mirror of https://github.com/GooseMod/GooseMod
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
2.5 KiB
87 lines
2.5 KiB
let goosemodScope = {};
|
|
|
|
export const setThisScope = (scope) => {
|
|
goosemodScope = scope;
|
|
};
|
|
|
|
|
|
export const disableModule = (name) => {
|
|
let settings = JSON.parse(goosemod.storage.get('goosemodDisabled')) || {};
|
|
|
|
settings[name] = true;
|
|
|
|
goosemod.storage.set('goosemodDisabled', JSON.stringify(settings));
|
|
};
|
|
|
|
export const enableModule = (name) => {
|
|
let settings = JSON.parse(goosemod.storage.get('goosemodDisabled')) || {};
|
|
|
|
delete settings[name];
|
|
|
|
goosemod.storage.set('goosemodDisabled', JSON.stringify(settings));
|
|
};
|
|
|
|
export const checkDisabled = (name) => {
|
|
return Object.keys(JSON.parse(goosemod.storage.get('goosemodDisabled')) || {}).includes(name);
|
|
};
|
|
|
|
|
|
export const saveModuleSettings = async () => {
|
|
//goosemodScope.logger.debug('settings', 'Saving module settings...');
|
|
|
|
let settings = JSON.parse(goosemod.storage.get('goosemodModules')) || {};
|
|
|
|
for (let p in goosemodScope.modules) {
|
|
if (goosemodScope.modules.hasOwnProperty(p)) {
|
|
try {
|
|
settings[p] = await (goosemodScope.modules[p].goosemodHandlers.getSettings || (async () => []))();
|
|
} catch (e) {
|
|
console.error('Failed to load settings to save module', p, e);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (JSON.stringify(JSON.parse(goosemod.storage.get('goosemodModules'))) !== JSON.stringify(settings)) {
|
|
goosemod.storage.set('goosemodModules', JSON.stringify(settings));
|
|
|
|
// goosemodScope.showToast('Settings saved');
|
|
}
|
|
};
|
|
|
|
export const clearModuleSetting = (moduleName) => {
|
|
let settings = JSON.parse(goosemod.storage.get('goosemodModules'));
|
|
|
|
if (!settings || !settings[moduleName]) return;
|
|
|
|
delete settings[moduleName];
|
|
|
|
goosemod.storage.set('goosemodModules', JSON.stringify(settings));
|
|
};
|
|
|
|
export const clearSettings = () => {
|
|
goosemod.storage.remove('goosemodModules');
|
|
};
|
|
|
|
export const loadSavedModuleSetting = async (moduleName) => {
|
|
let settings = JSON.parse(goosemod.storage.get('goosemodModules'));
|
|
|
|
if (!settings || !settings[moduleName]) return;
|
|
|
|
await (goosemodScope.modules[moduleName].goosemodHandlers.loadSettings || (async () => []))(settings[moduleName]);
|
|
};
|
|
|
|
/* export const loadSavedModuleSettings = async () => {
|
|
//goosemodScope.logger.debug('settings', 'Loading module settings...');
|
|
|
|
let settings = JSON.parse(goosemod.storage.get('goosemodModules'));
|
|
|
|
if (!settings) return;
|
|
|
|
for (let p in goosemodScope.modules) {
|
|
if (goosemodScope.modules.hasOwnProperty(p) && settings.hasOwnProperty(p)) {
|
|
await (goosemodScope.modules[p].goosemodHandlers.loadSettings || (async () => []))(settings[p]);
|
|
}
|
|
}
|
|
|
|
return settings;
|
|
}; */ |