feat: add exit event

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
MiaoWoo 2022-04-03 02:41:17 +08:00
parent b55e662f81
commit b8440b83de
3 changed files with 20 additions and 3 deletions

View File

@ -0,0 +1,4 @@
function exit() {
console.debug('exit finish!')
}
exit()

View File

@ -32,6 +32,7 @@ class MiaoScriptCore {
} }
loadPlugins() { loadPlugins() {
process.emit('core.before.load.plugins')
let loadPluginStartTime = new Date().getTime() let loadPluginStartTime = new Date().getTime()
console.i18n("ms.core.plugin.initialize") console.i18n("ms.core.plugin.initialize")
this.pluginManager.scan(this.pluginFolder) this.pluginManager.scan(this.pluginFolder)
@ -39,19 +40,32 @@ class MiaoScriptCore {
this.pluginManager.load(this.pluginManager.getPlugins()) this.pluginManager.load(this.pluginManager.getPlugins())
this.pluginManager.enable(this.pluginManager.getPlugins()) this.pluginManager.enable(this.pluginManager.getPlugins())
console.i18n("ms.core.plugin.completed", { time: (new Date().getTime() - loadPluginStartTime) / 1000 }) console.i18n("ms.core.plugin.completed", { time: (new Date().getTime() - loadPluginStartTime) / 1000 })
process.emit('core.after.load.plugins')
} }
disable() { disable() {
process.emit('core.before.disable')
let disableStartTime = Date.now() let disableStartTime = Date.now()
console.i18n("ms.core.engine.disable") console.i18n("ms.core.engine.disable")
this.pluginManager.disable(this.pluginManager.getPlugins()) this.pluginManager.disable(this.pluginManager.getPlugins())
this.taskManager.disable() 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) process.exit(0)
console.i18n("ms.core.engine.disable.finish", { console.i18n("ms.core.engine.disable.finish", {
loader: base.version, loader: base.version,
version: 'v' + global.ScriptEngineVersion, version: 'v' + global.ScriptEngineVersion,
time: (new Date().getTime() - disableStartTime) / 1000 time: (new Date().getTime() - disableStartTime) / 1000
}) })
process.emit('core.after.exit')
} }
} }

View File

@ -5,8 +5,7 @@ function updateJar() {
var updateFolder = fs.concat(pluginFolder, 'update') var updateFolder = fs.concat(pluginFolder, 'update')
} }
} }
function upgradeModules() { function upgradeModules(core) {
var core = http.get('https://registry.npmmirror.com/@ccms/core')
if (base.version && global.ScriptEngineVersion != core['dist-tags']['latest']) { if (base.version && global.ScriptEngineVersion != core['dist-tags']['latest']) {
var Paths = Java.type('java.nio.file.Paths') var Paths = Java.type('java.nio.file.Paths')
base.save(Paths.get(root, "upgrade"), core['dist-tags']['latest']) base.save(Paths.get(root, "upgrade"), core['dist-tags']['latest'])
@ -46,7 +45,7 @@ function initialize() {
updateJar() updateJar()
} catch (ignore) { } catch (ignore) {
} }
upgradeModules() upgradeModules(http.get('https://registry.npmmirror.com/@ccms/core'))
console.debug('initialize finish!') console.debug('initialize finish!')
} }
initialize() initialize()