Installing new version of an extension

When you install a new version of an extension which is already loaded, the files are replaced in the plugin folder but the code itself isn’t reloaded. This is very strange because at that moment you are running a mixed version of the extension. Old ruby code using the new html code from the dialog boxes because these are reloaded every time you open the dialog. The result is you get an incorrect working extension until you restart SketchUp (but the user don’t know this). How can we force the user to restart SketchUp? I thought about just give the user a message and quit SketchUp, but because the extension you are installing is already installed none of the new code seams to be evaluated again. It looks like I don’t have a method to warn the user of the need to restart SketchUp. Anybody an idea?

Not exactly force (because they can cancel the quit, same as if they initiated it from the File menu.)




Sketchup::quit, I know this method and this isn’t the problem. The problem is I need to get some signal that the user installed a new version of the extension to trigger this Sketchup::quit. I thought some code of the new extension will run / be evaluated on installation but it seams no code at all is evaluated / run when the same extension (older version) is already loaded.

Anyone who installs extensions in the middle of a session, with a valuable model loaded, is asking for trouble. Same for people who do not restart after installing extensions.

I always install with a blank new model, and restart afterward.

The EW functionality should warn users to save their model if it has been modified, and to restart after installing.

Does AppObserver#onUnloadExtension() fire ?

Nope, that was my first thought too. It fires only when the extension is manually unselected.

Also you can’t use any code which should be in the old version to detect because the old version is already installed. We can only put additional code in the new version to check.

Hmmm… In my Ruby 1.8.6 library extension for older SketchUp’s using Ruby 1.8, at my GitHub repos, … I subclassed SketchupExtension (within a module,) and overrode the load() method.

You could do something similar, just be sure to call super somewhere in the load() method.

Anyway, since your extension will only have one (singleton) instance of this custom subclass, you can check to see if one exists before the instantiation call. If true, then this is an update, if not it’s a normal load. So you will use the load() method to test and conditionally trigger your observer “time to restart” callback.

if ObjectSpace.each_object(Skalp::SkalpExtension){nil} > 0

or if inside the subclass, just:

if ObjectSpace.each_object(self.class){nil} > 0

Thanks to all for your replies. We solved this by making an installer extension with our main extension embedded inside.
The installer installs the main extension, removes itself and quit SketchUp to force the user to restart SketchUp. On restart only the main extension will be started.