diff --git a/info.toml b/info.toml index a0d63e7..8cc2acc 100644 --- a/info.toml +++ b/info.toml @@ -6,4 +6,5 @@ essential = true [script] dependencies = [ "Controls" ] +exports = [ "src/Export.as" ] timeout = 0 diff --git a/src/Export.as b/src/Export.as new file mode 100644 index 0000000..37a5b27 --- /dev/null +++ b/src/Export.as @@ -0,0 +1,8 @@ +namespace PluginManager +{ + /* + Queues a plugin for deletion. Note that this will invalidate the plugin object + passed in on the next frame! Do not use the Plugin handle after calling this! + */ + import void PluginUninstall(Meta::Plugin@ plugin) from "PluginManager"; +} diff --git a/src/ExportImpl.as b/src/ExportImpl.as new file mode 100644 index 0000000..d7230b0 --- /dev/null +++ b/src/ExportImpl.as @@ -0,0 +1,32 @@ +namespace PluginManager +{ + void PluginUninstall(Meta::Plugin@ plugin) + { + startnew(PluginUninstallAsync, plugin); + } + + void PluginUninstallAsync(ref@ metaPlugin) + { + auto plugin = cast(metaPlugin); + if (plugin is null) { + error("tried to uninstall a plugin but it was null!"); + return; + } + + // Grab ID now since handle will be invalid after uninstalling + const string id = plugin.ID; + + ::PluginUninstallAsync(metaPlugin); + @metaPlugin = null; + @plugin = null; + + // Make sure plugin tab (if open) updates correctly + for (int i = g_window.m_tabs.Length - 1; i >= 0; i--) { + auto tab = cast(g_window.m_tabs[i]); + if (tab !is null && tab.m_plugin !is null && tab.m_plugin.m_id == id) { + tab.m_plugin.CheckIfInstalled(); + break; + } + } + } +}