1
0
Fork 0

Canvas: add unload logic

Clean up various global things, especially commands, when
unloading the Canvas. This means reloads of Canvas are
clean.
This commit is contained in:
James Turner 2023-01-06 10:57:00 +00:00
parent b359fc88cb
commit b93ecb962b
4 changed files with 52 additions and 2 deletions

View file

@ -170,4 +170,12 @@ var showErrorNotification = func(node)
addcommand("show-error-notification-popup", showErrorNotification);
# called from unload() in api.nas
var unloadErrorNotification = func
{
removecommand("show-error-notification-popup");
if (errorNotificationCanvas) {
errorNotificationCanvas.del();
errorNotificationCanvas = nil;
}
}

View file

@ -85,3 +85,11 @@ var getDesktop = func()
{
return Group.new(_getDesktopGhost());
};
var unload = func
{
unloadTooltips();
unloadErrorNotification();
logprint(LOG_INFO, "Unloaded canvas Nasal module");
};

View file

@ -430,7 +430,8 @@ var files_with = func(ext) {
return results;
}
setlistener("/nasal/canvas/loaded", func {
var loadMapModules = func
{
foreach(var ext; var extensions = ['.draw','.model','.layer'])
load_modules(files_with(ext));
@ -440,4 +441,25 @@ setlistener("/nasal/canvas/loaded", func {
# canvas.MFD = {EFIS:}; # where we'll be storing all MFDs
# TODO: should be inside a separate subfolder, i.e. canvas/map/mfd
load_modules( files_with('.mfd'), 'canvas' );
};
var loadedListener = nil;
var unloadMap = func
{
removelistener(loadedListener);
};
# listener is used to defer loading map modules until all of
# Canvas is loaded
loadedListener = setlistener("/nasal/canvas/loaded", func (n){
if (n.getBoolValue()) {
loadMapModules();
logprint(LOG_INFO, "loaded Canvas map");
} else {
logprint(LOG_INFO, "Unloading Canvas map");
unloadMap();
}
});

View file

@ -427,3 +427,15 @@ addcommand("clear-message", clearMessage);
# avoid sending commands before Nasal is inited, and hence
# producing errors
setprop("/sim/mouse/tooltip-commands-registered", 1);
# called by the module unload callback in api.nas
var unloadTooltips = func
{
removecommand("update-hover");
removecommand("set-tooltip");
removecommand("tooltip-timeout");
removecommand("show-message");
removecommand("clear-message");
setprop("/sim/mouse/tooltip-commands-registered", 0);
}