peter пре 6 година
родитељ
комит
9efbf54908
1 измењених фајлова са 27 додато и 22 уклоњено
  1. 27
    22
      src/backend/PluginLoader.ts

+ 27
- 22
src/backend/PluginLoader.ts Прегледај датотеку

@@ -4,28 +4,13 @@ import { FolderStatus } from "upgiter/js/src/Types";
4 4
 import { Plugin } from "./Plugin";
5 5
 import { FrontworkAdmin } from "./Admin";
6 6
 
7
-export type PluginLoaderIfc = {
8
-    PluginLoader: {
9
-        installPlugin: (name:string, force:boolean) => Promise<FolderStatus>
10
-        startPlugin: (name:string) => Promise<boolean>
11
-        updatePlugin: (name:string) => Promise<boolean>
12
-        setPluginVersion: (name:string, tag:string) => Promise<FolderStatus>
13
-        getLoadedPluginNames: () => Promise<String[]>
14
-        selfUpdate: (force:boolean) => Promise<FolderStatus>
15
-        destroy: () => Promise<void> 
16
-    }
17
-}
18
-
19
-class PluginLoader
20
-implements RPCExporter<PluginLoaderIfc, "PluginLoader">{
21
-    
22
-    name = "PluginLoader" as "PluginLoader";
7
+class PluginLoader {
23 8
     private runningPlugins: Plugin[]
24 9
     private pluginUpdaters:{[name in string]:Git.Updater} = {}
25 10
 
26 11
     constructor(private admin:FrontworkAdmin){}
27 12
 
28
-    private async selfUpdate(force:boolean = false){
13
+    async selfUpdate(force:boolean = false){
29 14
         const updater = new Git.Updater({
30 15
             schema: 'https',
31 16
             localPath: './dist',
@@ -39,7 +24,7 @@ implements RPCExporter<PluginLoaderIfc, "PluginLoader">{
39 24
             //logger.warn("Cloning fb-dist/admin into ./dist ..."+(force?" USING FORCE!":""))
40 25
             status = await updater.cloneRepo(force)
41 26
 
42
-            //this.destroy()
27
+            this.destroy()
43 28
             const installer = eval("require")("./Installer").installAdmin
44 29
             installer(this.getPlugins())
45 30
         }
@@ -55,7 +40,6 @@ implements RPCExporter<PluginLoaderIfc, "PluginLoader">{
55 40
             remotePath: 'frontwork-distribution',
56 41
             repoName: name
57 42
         })
58
-        //new GitUpdater("./plugins/"+name)
59 43
         const status = await this.pluginUpdaters[name].cloneRepo(force)
60 44
         return status
61 45
     }
@@ -79,8 +63,8 @@ implements RPCExporter<PluginLoaderIfc, "PluginLoader">{
79 63
         }
80 64
 */
81 65
 
82
-        let str = "../plugins/"+name+"/Plugin"
83
-        const pluginClass = await eval('require')(str)
66
+        let evalstr = "../plugins/"+name+"/Plugin"
67
+        const pluginClass = await eval('require')(evalstr)
84 68
         const pluginObj = new pluginClass.default(this)
85 69
         try{
86 70
             if(pluginObj.start)
@@ -142,10 +126,31 @@ implements RPCExporter<PluginLoaderIfc, "PluginLoader">{
142 126
         return [...this.runningPlugins]
143 127
     }
144 128
 
145
-    private async destroy(){
129
+    async destroy(){
146 130
         return
147 131
     }
148 132
 
133
+}
134
+
135
+
136
+export type PluginLoaderIfc = {
137
+    PluginLoader: {
138
+        installPlugin: (name:string, force:boolean) => Promise<FolderStatus>
139
+        startPlugin: (name:string) => Promise<boolean>
140
+        updatePlugin: (name:string) => Promise<boolean>
141
+        setPluginVersion: (name:string, tag:string) => Promise<FolderStatus>
142
+        getLoadedPluginNames: () => Promise<String[]>
143
+        selfUpdate: (force:boolean) => Promise<FolderStatus>
144
+        destroy: () => Promise<void> 
145
+    }
146
+}
147
+
148
+class RPCPluginLoader 
149
+extends PluginLoader
150
+implements RPCExporter<PluginLoaderIfc, "PluginLoader">{
151
+
152
+    name = "PluginLoader" as "PluginLoader";
153
+
149 154
     exportRPCs(){
150 155
         return [{
151 156
             name: "installPlugin" as "installPlugin",

Loading…
Откажи
Сачувај