You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
GlosSI/SteamTweaks/src/common/tweakApi.ts

30 lines
835 B
TypeScript

export const initTweak = <T>(name: string, tweakMain: (() => T)|{
install: () => T;
uninstall: () => void;
}, force = false): T => {
if (!force && window.GlosSITweaks[name]) {
throw new Error(`Tweak ${name} is already installed!`);
}
if (typeof tweakMain === 'object') {
window.GlosSITweaks[name] = { install: tweakMain.install, uninstall: () => {
try {
tweakMain.uninstall();
} catch (e) {
GlosSIApi.SteamTarget.log('error', e);
}
delete window.GlosSITweaks[name];
} };
} else {
window.GlosSITweaks[name] = { install: tweakMain };
}
try {
return window.GlosSITweaks[name].install() as T;
} catch (e) {
GlosSIApi.SteamTarget.log('error', e);
throw e;
}
};