Small changes to the plugin loading system

This commit is contained in:
DJj123dj
2024-11-18 20:19:25 +01:00
parent 5a4b45aa3f
commit a31588f025
4 changed files with 26 additions and 10 deletions
+1
View File
@@ -7,6 +7,7 @@ otdebug.txt
*/.DS_Store */.DS_Store
*/*/.DS_Store */*/.DS_Store
*/*/*/.DS_Store */*/*/.DS_Store
**/.DS_Store
TEMP/ TEMP/
.vscode/ .vscode/
plugins/* plugins/*
+16 -1
View File
@@ -80,7 +80,7 @@ export class ODPlugin extends ODManagerData {
this.crashed = false 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(){ getStartFile(){
const newFile = this.data.startFile.replace(/\.ts$/,".js") const newFile = this.data.startFile.replace(/\.ts$/,".js")
return nodepath.join(this.dir,newFile) return nodepath.join(this.dir,newFile)
@@ -113,6 +113,7 @@ export class ODPlugin extends ODManagerData {
}else return true }else return true
} }
/**Check if a npm dependency exists. */
#checkDependency(id:string){ #checkDependency(id:string){
try{ try{
require.resolve(id) 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(){ dependenciesInstalled(){
const missing: string[] = [] const missing: string[] = []
this.data.npmDependencies.forEach((d) => { this.data.npmDependencies.forEach((d) => {
@@ -132,6 +134,7 @@ export class ODPlugin extends ODManagerData {
return missing return missing
} }
/**Get a list of all missing plugins that are required for this plugin. */
pluginsInstalled(manager:ODPluginManager){ pluginsInstalled(manager:ODPluginManager){
const missing: string[] = [] const missing: string[] = []
this.data.requiredPlugins.forEach((p) => { this.data.requiredPlugins.forEach((p) => {
@@ -143,6 +146,18 @@ export class ODPlugin extends ODManagerData {
return missing 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<ODManagerData> { export class ODPluginClassManager extends ODManager<ODManagerData> {
+7 -9
View File
@@ -91,22 +91,20 @@ export const loadAllPlugins = async () => {
const missingDependencies: {id:string,missing:string}[] = [] const missingDependencies: {id:string,missing:string}[] = []
const missingPlugins: {id:string,missing:string}[] = [] const missingPlugins: {id:string,missing:string}[] = []
//go trough all plugins for errors //go through all plugins for errors
sortedPlugins.forEach((plugin) => { sortedPlugins.filter((plugin) => plugin.enabled).forEach((plugin) => {
const from = plugin.id.value 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.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})) plugin.pluginsInstalled(openticket.plugins).forEach((missing) => missingPlugins.push({id:from,missing}))
}) })
//handle all incompatibilities //handle all incompatibilities
const alreadyLoggedCompatPlugins: string[] = []
incompatibilities.forEach((match) => { 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) const fromPlugin = openticket.plugins.get(match.from)
if (fromPlugin && !fromPlugin.crashed){ if (fromPlugin && !fromPlugin.crashed){
fromPlugin.crashed = true fromPlugin.crashed = true
+2
View File
@@ -737,8 +737,10 @@ const main = async () => {
if (openticket.defaults.getDefault("startScreenRendering")){ if (openticket.defaults.getDefault("startScreenRendering")){
await openticket.startscreen.renderAllComponents() await openticket.startscreen.renderAllComponents()
if (openticket.languages.getLanguageMetadata(false)?.automated){ 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("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") openticket.log("Please help us improve the translation by contributing to our project!","warning")
console.log("===================")
} }
await openticket.events.get("afterStartScreensRendered").emit([openticket.startscreen]) await openticket.events.get("afterStartScreensRendered").emit([openticket.startscreen])