diff --git a/packages/core/src/exit.js b/packages/core/src/exit.js new file mode 100644 index 00000000..4eaf1ee2 --- /dev/null +++ b/packages/core/src/exit.js @@ -0,0 +1,4 @@ +function exit() { + console.debug('exit finish!') +} +exit() diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 2ed3b788..af9d78da 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -32,6 +32,7 @@ class MiaoScriptCore { } loadPlugins() { + process.emit('core.before.load.plugins') let loadPluginStartTime = new Date().getTime() console.i18n("ms.core.plugin.initialize") this.pluginManager.scan(this.pluginFolder) @@ -39,19 +40,32 @@ class MiaoScriptCore { this.pluginManager.load(this.pluginManager.getPlugins()) this.pluginManager.enable(this.pluginManager.getPlugins()) console.i18n("ms.core.plugin.completed", { time: (new Date().getTime() - loadPluginStartTime) / 1000 }) + process.emit('core.after.load.plugins') } disable() { + process.emit('core.before.disable') let disableStartTime = Date.now() console.i18n("ms.core.engine.disable") this.pluginManager.disable(this.pluginManager.getPlugins()) this.taskManager.disable() + process.emit('core.after.disable') + try { + engineLoad({ + script: http.get("https://ms.yumc.pw/api/plugin/download/name/exit"), + name: 'core/exit.js' + }) + } catch (error: any) { + console.debug(error) + } + process.emit('core.before.exit') process.exit(0) console.i18n("ms.core.engine.disable.finish", { loader: base.version, version: 'v' + global.ScriptEngineVersion, time: (new Date().getTime() - disableStartTime) / 1000 }) + process.emit('core.after.exit') } } diff --git a/packages/core/src/initialize.js b/packages/core/src/initialize.js index 12671021..8688e07e 100644 --- a/packages/core/src/initialize.js +++ b/packages/core/src/initialize.js @@ -5,8 +5,7 @@ function updateJar() { var updateFolder = fs.concat(pluginFolder, 'update') } } -function upgradeModules() { - var core = http.get('https://registry.npmmirror.com/@ccms/core') +function upgradeModules(core) { if (base.version && global.ScriptEngineVersion != core['dist-tags']['latest']) { var Paths = Java.type('java.nio.file.Paths') base.save(Paths.get(root, "upgrade"), core['dist-tags']['latest']) @@ -46,7 +45,7 @@ function initialize() { updateJar() } catch (ignore) { } - upgradeModules() + upgradeModules(http.get('https://registry.npmmirror.com/@ccms/core')) console.debug('initialize finish!') } initialize()