Fix plugin loading for packed plugins

This commit is contained in:
Jiiks 2018-08-28 18:08:56 +03:00
parent 2093c472b5
commit 76d54f0a95
2 changed files with 17 additions and 25 deletions

View File

@ -190,25 +190,22 @@ export default class {
static async preloadPackedContent(pkg, reload = false, index) { static async preloadPackedContent(pkg, reload = false, index) {
try { try {
const packagePath = path.join(this.contentPath, pkg); const packagePath = path.join(this.contentPath, pkg);
const packageName = pkg.replace('.bd', '');
await FileUtils.fileExists(packagePath); await FileUtils.fileExists(packagePath);
const config = JSON.parse(asar.extractFile(packagePath, 'config.json').toString()); const config = JSON.parse(asar.extractFile(packagePath, 'config.json').toString());
const unpackedPath = path.join(Globals.getPath('tmp'), config.info.name); const unpackedPath = path.join(Globals.getPath('tmp'), packageName);
asar.extractAll(packagePath, unpackedPath); asar.extractAll(packagePath, unpackedPath);
const content = await this.preloadContent({ return this.preloadContent({
config, config,
contentPath: unpackedPath, contentPath: unpackedPath,
packagePath: packagePath, packagePath: packagePath,
pkg, pkg,
packageName,
packed: true packed: true
}, reload, index); }, reload, index);
rimraf(unpackedPath, err => {
if (err) throw err;
});
return content;
} catch (err) { } catch (err) {
throw err; throw err;
} }
@ -295,13 +292,19 @@ export default class {
const content = await this.loadContent(paths, configs, readConfig.info, readConfig.main, readConfig.dependencies, readConfig.permissions, readConfig.mainExport, packed ? dirName : false); const content = await this.loadContent(paths, configs, readConfig.info, readConfig.main, readConfig.dependencies, readConfig.permissions, readConfig.mainExport, packed ? dirName : false);
if (!content) return undefined; if (!content) return undefined;
if (!reload && this.getContentById(content.id)) if (!reload && this.getContentById(content.id))
throw {message: `A ${this.contentType} with the ID ${content.id} already exists.`}; throw { message: `A ${this.contentType} with the ID ${content.id} already exists.` };
if (reload) this.localContent.splice(index, 1, content); if (reload) this.localContent.splice(index, 1, content);
else this.localContent.push(content); else this.localContent.push(content);
return content; return content;
} catch (err) { } catch (err) {
throw err; throw err;
} finally {
if (typeof dirName === 'object' && dirName.packed) {
rimraf(dirName.contentPath, err => {
if (err) Logger.err(err);
});
}
} }
} }
@ -358,20 +361,7 @@ export default class {
if (this.unloadContentHook) this.unloadContentHook(content); if (this.unloadContentHook) this.unloadContentHook(content);
if (reload) { if (reload) return content.packed ? this.preloadPackedContent(content.packed.pkg, true, index) : this.preloadContent(content.dirName, true, index);
let newcontent;
if (content.packed) {
newcontent = await this.preloadPackedContent(content.packed.pkg, true, index);
} else {
newcontent = await this.preloadContent(content.dirName, true, index);
}
if (newcontent.enabled) {
newcontent.userConfig.enabled = false;
newcontent.start(false);
}
return newcontent;
}
this.localContent.splice(index, 1); this.localContent.splice(index, 1);
} catch (err) { } catch (err) {

View File

@ -112,15 +112,17 @@ export default class extends ContentManager {
configs, info, main, configs, info, main,
paths: { paths: {
contentPath: paths.contentPath, contentPath: paths.contentPath,
dirName: paths.dirName, dirName: packed ? packed.packageName : paths.dirName,
mainPath: paths.mainPath mainPath: paths.mainPath
} }
}); });
if (packed) instance.packed = { if (packed) instance.packed = {
pkg: packed.pkg,
packageName: packed.packageName,
packagePath: packed.packagePath, packagePath: packed.packagePath,
pkg: packed.pkg packed: true
}; }; else instance.packed = false;
if (instance.enabled && this.loaded) { if (instance.enabled && this.loaded) {
instance.userConfig.enabled = false; instance.userConfig.enabled = false;