GooseMod v5.5.0: Handle module import errors better

pull/14/head
Oj18 3 years ago
parent 70c7adb27b
commit bec15387ea

@ -1,5 +1,11 @@
# GooseMod Changelog
## v5.5.0 [2020-12-06]
- ### Features
- Display error when a module fails to import instead of causing an error and halting GooseMod loading
## v5.4.0 [2020-12-04]
- ### Features

4
dist/index.js vendored

File diff suppressed because one or more lines are too long

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

@ -99,7 +99,7 @@ const init = async function () {
this.disabledModules = {};
this.lastVersion = localStorage.getItem('goosemodLastVersion');
this.version = '5.4.0';
this.version = '5.5.0';
this.versionHash = '<hash>'; // Hash of built final js file is inserted here via build script
fetch('https://goosemod-api.netlify.app/injectVersion.json').then((x) => x.json().then((latestInjectVersionInfo) => {
@ -196,7 +196,7 @@ const init = async function () {
for (let m of toInstallModules) {
this.updateLoadingScreen(`${this.moduleStoreAPI.modules.find((x) => x.filename === m).name} - ${toInstallModules.indexOf(m) + 1}/${toInstallModules.length}`);
await this.moduleStoreAPI.importModule(m);
}
}

@ -22,36 +22,41 @@ export default {
},
importModule: async (moduleName) => {
const moduleInfo = goosemodScope.moduleStoreAPI.modules.find((x) => x.filename === moduleName);
try {
const moduleInfo = goosemodScope.moduleStoreAPI.modules.find((x) => x.filename === moduleName);
const jsCode = await goosemodScope.moduleStoreAPI.jsCache.getJSForModule(moduleName);
const jsCode = await goosemodScope.moduleStoreAPI.jsCache.getJSForModule(moduleName);
const calculatedHash = await sha512(jsCode);
if (calculatedHash !== moduleInfo.hash) {
goosemodScope.showToast(`Cancelled importing of ${moduleName} due to hash mismatch`, {timeout: 2000});
const calculatedHash = await sha512(jsCode);
if (calculatedHash !== moduleInfo.hash) {
goosemodScope.showToast(`Cancelled importing of ${moduleName} due to hash mismatch`, {timeout: 2000, type: 'danger'});
console.warn('Hash mismatch', calculatedHash, moduleInfo.hash);
return;
}
console.warn('Hash mismatch', calculatedHash, moduleInfo.hash);
return;
}
await goosemodScope.importModule({
filename: `${moduleInfo.filename}.js`,
data: jsCode
});
await goosemodScope.importModule({
filename: `${moduleInfo.filename}.js`,
data: jsCode
});
if (goosemodScope.modules[moduleName].onLoadingFinished !== undefined) {
await goosemodScope.modules[moduleName].onLoadingFinished();
}
if (goosemodScope.modules[moduleName].onLoadingFinished !== undefined) {
await goosemodScope.modules[moduleName].onLoadingFinished();
}
let settingItem = goosemodScope.settings.items.find((x) => x[1] === 'Module Store');
let settingItem = goosemodScope.settings.items.find((x) => x[1] === 'Module Store');
let item = settingItem[2].find((x) => x.subtext === moduleInfo.description);
let item = settingItem[2].find((x) => x.subtext === moduleInfo.description);
item.buttonType = 'danger';
item.buttonText = 'Remove';
item.showToggle = true;
item.buttonType = 'danger';
item.buttonText = 'Remove';
item.showToggle = true;
// if (goosemodScope.settings.isSettingsOpen() && !goosemodScope.initialImport) goosemodScope.settings.createFromItems();
// if (goosemodScope.settings.isSettingsOpen() && !goosemodScope.initialImport) goosemodScope.settings.createFromItems();
} catch (e) {
goosemodScope.showToast(`Failed to import module ${moduleName}`, { timeout: 2000, type: 'error' });
console.error(e);
}
},
moduleRemoved: async (m) => {

Loading…
Cancel
Save