From a31588f025426e7bc5f3420d9039e11223a4d7f4 Mon Sep 17 00:00:00 2001 From: DJj123dj <80536295+DJj123dj@users.noreply.github.com> Date: Mon, 18 Nov 2024 20:19:25 +0100 Subject: [PATCH] Small changes to the plugin loading system --- .gitignore | 1 + src/core/api/modules/plugin.ts | 17 ++++++++++++++++- src/core/startup/pluginLauncher.ts | 16 +++++++--------- src/index.ts | 2 ++ 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index aca1716..f210749 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ otdebug.txt */.DS_Store */*/.DS_Store */*/*/.DS_Store +**/.DS_Store TEMP/ .vscode/ plugins/* diff --git a/src/core/api/modules/plugin.ts b/src/core/api/modules/plugin.ts index 99b568d..31fd16b 100644 --- a/src/core/api/modules/plugin.ts +++ b/src/core/api/modules/plugin.ts @@ -80,7 +80,7 @@ export class ODPlugin extends ODManagerData { this.crashed = false } - //Get the startfile location relative to the ./plugins/ directory + /**Get the startfile location relative to the `./plugins/` directory. (`./dist/plugins/`) when compiled) */ getStartFile(){ const newFile = this.data.startFile.replace(/\.ts$/,".js") return nodepath.join(this.dir,newFile) @@ -113,6 +113,7 @@ export class ODPlugin extends ODManagerData { }else return true } + /**Check if a npm dependency exists. */ #checkDependency(id:string){ try{ require.resolve(id) @@ -122,6 +123,7 @@ export class ODPlugin extends ODManagerData { } } + /**Get a list of all missing npm dependencies that are required for this plugin. */ dependenciesInstalled(){ const missing: string[] = [] this.data.npmDependencies.forEach((d) => { @@ -132,6 +134,7 @@ export class ODPlugin extends ODManagerData { return missing } + /**Get a list of all missing plugins that are required for this plugin. */ pluginsInstalled(manager:ODPluginManager){ const missing: string[] = [] this.data.requiredPlugins.forEach((p) => { @@ -143,6 +146,18 @@ export class ODPlugin extends ODManagerData { return missing } + /**Get a list of all enabled incompatible plugins that interfere with this plugin. */ + pluginsIncompatible(manager:ODPluginManager){ + const incompatible: string[] = [] + this.data.incompatiblePlugins.forEach((p) => { + const plugin = manager.get(p) + if (plugin && plugin.enabled){ + incompatible.push(p) + } + }) + + return incompatible + } } export class ODPluginClassManager extends ODManager { diff --git a/src/core/startup/pluginLauncher.ts b/src/core/startup/pluginLauncher.ts index c14bfb9..4790aaf 100644 --- a/src/core/startup/pluginLauncher.ts +++ b/src/core/startup/pluginLauncher.ts @@ -91,22 +91,20 @@ export const loadAllPlugins = async () => { const missingDependencies: {id:string,missing:string}[] = [] const missingPlugins: {id:string,missing:string}[] = [] - //go trough all plugins for errors - sortedPlugins.forEach((plugin) => { + //go through all plugins for errors + sortedPlugins.filter((plugin) => plugin.enabled).forEach((plugin) => { const from = plugin.id.value - plugin.data.incompatiblePlugins.forEach((to) => { - //deny incompatibility if it already exists - if (incompatibilities.find((p) => (p.from == from && p.to == to) || (p.to == from && p.from == to))) return - - //check for existence of both plugins => add to list - if (openticket.plugins.exists(to)) incompatibilities.push({from,to}) - }) plugin.dependenciesInstalled().forEach((missing) => missingDependencies.push({id:from,missing})) + plugin.pluginsIncompatible(openticket.plugins).forEach((incompatible) => incompatibilities.push({from,to:incompatible})) plugin.pluginsInstalled(openticket.plugins).forEach((missing) => missingPlugins.push({id:from,missing})) }) //handle all incompatibilities + const alreadyLoggedCompatPlugins: string[] = [] incompatibilities.forEach((match) => { + if (alreadyLoggedCompatPlugins.includes(match.from) || alreadyLoggedCompatPlugins.includes(match.to)) return + else alreadyLoggedCompatPlugins.push(match.from,match.to) + const fromPlugin = openticket.plugins.get(match.from) if (fromPlugin && !fromPlugin.crashed){ fromPlugin.crashed = true diff --git a/src/index.ts b/src/index.ts index b4f30e5..209f7e3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -737,8 +737,10 @@ const main = async () => { if (openticket.defaults.getDefault("startScreenRendering")){ await openticket.startscreen.renderAllComponents() if (openticket.languages.getLanguageMetadata(false)?.automated){ + console.log("===================") openticket.log("You are currently using a language which has been translated by Google Translate!","warning") openticket.log("Please help us improve the translation by contributing to our project!","warning") + console.log("===================") } await openticket.events.get("afterStartScreensRendered").emit([openticket.startscreen])