Fixes some watcher issues
Also fixes BdApi~monkeyPatch not returning the cancel patch.
This commit is contained in:
parent
4405f0df23
commit
1ca7269b34
|
@ -199,10 +199,13 @@ export default class AddonManager {
|
||||||
if (typeof(filename) === "undefined") return;
|
if (typeof(filename) === "undefined") return;
|
||||||
try {__non_webpack_require__(path.resolve(this.addonFolder, filename));}
|
try {__non_webpack_require__(path.resolve(this.addonFolder, filename));}
|
||||||
catch (error) {return new AddonError(filename, filename, Strings.Addons.compileError, {message: error.message, stack: error.stack});}
|
catch (error) {return new AddonError(filename, filename, Strings.Addons.compileError, {message: error.message, stack: error.stack});}
|
||||||
|
|
||||||
const addon = __non_webpack_require__(path.resolve(this.addonFolder, filename));
|
const addon = __non_webpack_require__(path.resolve(this.addonFolder, filename));
|
||||||
if (this.addonList.find(c => c.id == addon.id)) return new AddonError(addon.name, filename, Strings.Addons.alreadyExists.format({type: this.prefix, name: addon.name}));
|
if (this.addonList.find(c => c.id == addon.id)) return new AddonError(addon.name, filename, Strings.Addons.alreadyExists.format({type: this.prefix, name: addon.name}));
|
||||||
|
|
||||||
const error = this.initializeAddon(addon);
|
const error = this.initializeAddon(addon);
|
||||||
if (error) return error;
|
if (error) return error;
|
||||||
|
|
||||||
this.addonList.push(addon);
|
this.addonList.push(addon);
|
||||||
if (shouldToast) Toasts.success(`${addon.name} v${addon.version} was loaded.`);
|
if (shouldToast) Toasts.success(`${addon.name} v${addon.version} was loaded.`);
|
||||||
this.emit("loaded", addon.id);
|
this.emit("loaded", addon.id);
|
||||||
|
@ -225,8 +228,8 @@ export default class AddonManager {
|
||||||
reloadAddon(idOrFileOrAddon, shouldToast = true) {
|
reloadAddon(idOrFileOrAddon, shouldToast = true) {
|
||||||
const addon = typeof(idOrFileOrAddon) == "string" ? this.addonList.find(c => c.id == idOrFileOrAddon || c.filename == idOrFileOrAddon) : idOrFileOrAddon;
|
const addon = typeof(idOrFileOrAddon) == "string" ? this.addonList.find(c => c.id == idOrFileOrAddon || c.filename == idOrFileOrAddon) : idOrFileOrAddon;
|
||||||
const didUnload = this.unloadAddon(addon, shouldToast, true);
|
const didUnload = this.unloadAddon(addon, shouldToast, true);
|
||||||
if (!didUnload) return didUnload;
|
if (addon && !didUnload) return didUnload;
|
||||||
return this.loadAddon(addon.filename, shouldToast);
|
return this.loadAddon(addon ? addon.filename : idOrFileOrAddon, shouldToast);
|
||||||
}
|
}
|
||||||
|
|
||||||
isLoaded(idOrFile) {
|
isLoaded(idOrFile) {
|
||||||
|
@ -288,7 +291,10 @@ export default class AddonManager {
|
||||||
|
|
||||||
for (const filename of files) {
|
for (const filename of files) {
|
||||||
const absolutePath = path.resolve(this.addonFolder, filename);
|
const absolutePath = path.resolve(this.addonFolder, filename);
|
||||||
if (!fs.statSync(absolutePath).isFile()) continue;
|
const stats = fs.statSync(absolutePath);
|
||||||
|
if (!stats || !stats.isFile()) continue;
|
||||||
|
this.timeCache[filename] = stats.mtime.getTime();
|
||||||
|
|
||||||
if (!filename.endsWith(this.extension)) {
|
if (!filename.endsWith(this.extension)) {
|
||||||
// Lets check to see if this filename has the duplicated file pattern `something(1).ext`
|
// Lets check to see if this filename has the duplicated file pattern `something(1).ext`
|
||||||
const match = filename.match(this.duplicatePattern);
|
const match = filename.match(this.duplicatePattern);
|
||||||
|
@ -311,7 +317,7 @@ export default class AddonManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.saveState();
|
this.saveState();
|
||||||
// if (Settings.get(this.collection, this.category, this.id)) this.watchAddons();
|
if (Settings.get(this.collection, this.category, this.id)) this.watchAddons();
|
||||||
return errors;
|
return errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -194,7 +194,7 @@ BdApi.deleteData = function(pluginName, key) {
|
||||||
// return cancel;
|
// return cancel;
|
||||||
// };
|
// };
|
||||||
BdApi.monkeyPatch = function(what, methodName, options) {
|
BdApi.monkeyPatch = function(what, methodName, options) {
|
||||||
const {before, after, instead, once = false} = options;
|
const {before, after, instead, once = false, callerId = "BdApi"} = options;
|
||||||
const patchType = before ? "before" : after ? "after" : instead ? "instead" : "";
|
const patchType = before ? "before" : after ? "after" : instead ? "instead" : "";
|
||||||
if (!patchType) return Logger.err("BdApi", "Must provide one of: after, before, instead");
|
if (!patchType) return Logger.err("BdApi", "Must provide one of: after, before, instead");
|
||||||
const originalMethod = what[methodName];
|
const originalMethod = what[methodName];
|
||||||
|
@ -202,7 +202,7 @@ BdApi.monkeyPatch = function(what, methodName, options) {
|
||||||
originalMethod: originalMethod,
|
originalMethod: originalMethod,
|
||||||
callOriginalMethod: () => data.originalMethod.apply(data.thisObject, data.methodArguments)
|
callOriginalMethod: () => data.originalMethod.apply(data.thisObject, data.methodArguments)
|
||||||
};
|
};
|
||||||
data.cancelPatch = Patcher[patchType]("BdApi", what, methodName, (thisObject, args, returnValue) => {
|
data.cancelPatch = Patcher[patchType](callerId, what, methodName, (thisObject, args, returnValue) => {
|
||||||
data.thisObject = thisObject;
|
data.thisObject = thisObject;
|
||||||
data.methodArguments = args;
|
data.methodArguments = args;
|
||||||
data.returnValue = returnValue;
|
data.returnValue = returnValue;
|
||||||
|
@ -211,9 +211,10 @@ BdApi.monkeyPatch = function(what, methodName, options) {
|
||||||
if (once) data.cancelPatch();
|
if (once) data.cancelPatch();
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
// Logger.err("monkeyPatch", `Error in the ${patchType} of ${methodName}`);
|
Logger.err(`${callerId}:monkeyPatch`, `Error in the ${patchType} of ${methodName}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
return data.cancelPatch;
|
||||||
};
|
};
|
||||||
// Event when element is removed
|
// Event when element is removed
|
||||||
BdApi.onRemoved = function(node, callback) {
|
BdApi.onRemoved = function(node, callback) {
|
||||||
|
|
|
@ -56,10 +56,11 @@ export default new class PluginManager extends AddonManager {
|
||||||
togglePlugin(id) {return this.toggleAddon(id);}
|
togglePlugin(id) {return this.toggleAddon(id);}
|
||||||
|
|
||||||
unloadPlugin(idOrFileOrAddon) {return this.unloadAddon(idOrFileOrAddon);}
|
unloadPlugin(idOrFileOrAddon) {return this.unloadAddon(idOrFileOrAddon);}
|
||||||
|
loadPlugin(filename) {return this.loadAddon(filename);}
|
||||||
|
|
||||||
loadPlugin(filename) {
|
loadAddon(filename) {
|
||||||
const error = this.loadAddon(filename);
|
const error = super.loadAddon(filename);
|
||||||
if (error) Modals.showAddonErrors({themes: [error]});
|
if (error) Modals.showAddonErrors({plugins: [error]});
|
||||||
}
|
}
|
||||||
|
|
||||||
reloadPlugin(idOrFileOrAddon) {
|
reloadPlugin(idOrFileOrAddon) {
|
||||||
|
|
|
@ -43,14 +43,11 @@ export default new class ThemeManager extends AddonManager {
|
||||||
toggleTheme(id) {return this.toggleAddon(id);}
|
toggleTheme(id) {return this.toggleAddon(id);}
|
||||||
|
|
||||||
unloadTheme(idOrFileOrAddon) {return this.unloadAddon(idOrFileOrAddon);}
|
unloadTheme(idOrFileOrAddon) {return this.unloadAddon(idOrFileOrAddon);}
|
||||||
|
loadTheme(filename) {return this.loadAddon(filename);}
|
||||||
|
reloadTheme(idOrFileOrAddon) {return this.reloadAddon(idOrFileOrAddon);}
|
||||||
|
|
||||||
loadTheme(filename) {
|
loadAddon(filename) {
|
||||||
const error = this.loadAddon(filename);
|
const error = super.loadAddon(filename);
|
||||||
if (error) Modals.showAddonErrors({themes: [error]});
|
|
||||||
}
|
|
||||||
|
|
||||||
reloadTheme(idOrFileOrAddon) {
|
|
||||||
const error = this.reloadAddon(idOrFileOrAddon);
|
|
||||||
if (error) Modals.showAddonErrors({themes: [error]});
|
if (error) Modals.showAddonErrors({themes: [error]});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue