A simple source reloader for sketchup extensions in dev

This a simple extension in dev source reloader, I used in my extension dev env.
It can automatic reload the extension source files after you change and saved.

I use UI.start_timer(2, true) to start a loop backend worker, and ::File.stat(file) to find all files in $LOADED_FEATURES、$LOAD_PATH whoes mtime changed.

I opened the source in https://github.com/subar-cn/source_reloader

Hope it can help you,

1 Like

(1) Extensions should not use global variables ($reloader_timer_id.)
Use a class or module variable instead. (Like: @@reloader_timer_id)

(2) It is rather heavy-handed to be checking every file in $LOADED_FEATURES every 2 seconds for a new mod time. I would suggest finding a way to only check the extension files under development.

2 Likes

Yes, it’s my mistake, I will change it to module variable later.

And,

It’s difficult to determine a extension is still under development or not.

In my development env, I place the extensions codes in my work directory such as ‘~/work/su_dev/**’ and
use thomthom 's Extension Sources to load them to SU.

And someone may directly place the extension files(under development) in the plugins directory.
And someone may create a ruby file(eg. 0.dev.rb) in the SU plugins directory, add extension entry file to $LOAD_PATH, such as

entry_path = **absolute_path_of_extension_entry_file_in_dev**
$LOAD_PATH << entry_path unless $LOAD_PATH.include?(entry_path)

They are all effective.

So, I find it difficult to determine which extension is still under development. I will continue to seek a better way to handle it, although the current mechanism can still operate normally.

Topic moved to [Developers] [Ruby API ] category…

Very impressed!
I have also created a tool similar to yours to aid me in my plugin development work. My approach is slightly different, as I have added a feature that allows me to add specific files or directories to the watch list. This makes it easier for me to manage and monitor only the necessary files or directories.

2 Likes

Yes, I wrote this feature in the TODO LIST in README, the second one.

The idea is to refer to thomthom 's Extension Sources to introduce a plugin list, which can enable/disable automatic reloading for a single plugin.

It is agains the guidline mentioned here:
https://ruby.sketchup.com/file.extension_requirements.html:

Don’t modify the ‘$LOAD_PATH’. Doing so may cause other extensions to load the wrong files. Instead include your extension support folder in the path whenever you load a file.

1 Like