fix: improve error handling and logging in various components

This commit is contained in:
2026-05-24 16:17:16 +02:00
parent 730a27b397
commit 9d80811e83
5 changed files with 139 additions and 168 deletions
+6 -1
View File
@@ -44,7 +44,8 @@ export class Config {
this.encrypt && this.crypto ? this.crypto.decrypt(fileStream) : fileStream
) as Record<string, unknown>;
this.config = decryptedJSON;
} catch {
} catch (err) {
console.log(err);
this.config = {};
await this.save();
}
@@ -63,6 +64,10 @@ export class Config {
});
}
values () {
return this.config;
}
value(key: string) {
return {
set: <T>(val: T) => {
+65 -115
View File
@@ -283,51 +283,19 @@ export const downloadTheme = async (
await path.normalize(`${themeFolder}/assets/${themeInfoObj.preview}`)
);
const downloadableThemes = await getDownloadableThemes();
custom_themes.update((themes) => {
const reloadedThemes = [...themes];
for (const theme of downloadableThemes) {
if (theme.name === 'Default') continue; // never overwrite Default from remote
if (!reloadedThemes.find((t) => t.name === theme.name)) {
reloadedThemes.push(theme);
}
const installedTheme = reloadedThemes.find((t) => t.name === theme.name);
if (installedTheme) {
const installedThemeVersion = new SemVer(installedTheme.version);
const downloadableThemeVersion = new SemVer(theme.version);
if (downloadableThemeVersion.compare(installedThemeVersion) > 0) {
installedTheme.updateAvailable = true;
const index = reloadedThemes.findIndex((t) => t.name === theme.name);
reloadedThemes[index] = installedTheme;
}
}
const matchedTheme = themes.find((t) => t.name === theme.name);
if (matchedTheme) {
matchedTheme.scriptUrl = themeScriptUrl;
matchedTheme.assets = themeAssets;
matchedTheme.preview = themePreview;
matchedTheme.status = 'installed';
matchedTheme.progress = 1;
}
for (const installedTheme of reloadedThemes) {
if (installedTheme.name === 'Default') continue; // never touch Default
if (installedTheme.name === theme.name) {
installedTheme.name = themeInfoObj.name;
installedTheme.author = themeInfoObj.author;
installedTheme.version = themeInfoObj.version;
installedTheme.scriptUrl = themeScriptUrl;
installedTheme.assets = themeAssets;
installedTheme.preview = themePreview;
installedTheme.status = 'installed';
}
}
return reloadedThemes.sort((a, b) => {
if (a.name === 'Default') return -1;
if (b.name === 'Default') return 1;
if (a.status === 'installed' && b.status !== 'installed') return -1;
if (a.status !== 'installed' && b.status === 'installed') return 1;
return a.name.localeCompare(b.name);
});
return themes;
});
await reloadThemes();
return {
success: true,
};
@@ -357,38 +325,20 @@ export const deleteTheme = async (themeToUninstall: Theme) => {
return themes;
});
await fs.remove(themeFolder, { recursive: true });
const downloadableThemes = await getDownloadableThemes();
custom_themes.update((themes) => {
const reloadedThemes = [...themes];
for (const theme of downloadableThemes) {
if (theme.name === themeToUninstall.name) {
const themeIndex = reloadedThemes.findIndex((t) => t.name === theme.name);
if (themeIndex) {
reloadedThemes.splice(themeIndex, 1);
reloadedThemes.push(theme);
}
}
const installedTheme = reloadedThemes.find((t) => t.name === theme.name);
if (installedTheme) {
const installedThemeVersion = new SemVer(installedTheme.version);
const downloadableThemeVersion = new SemVer(theme.version);
if (downloadableThemeVersion.compare(installedThemeVersion) > 0) {
installedTheme.updateAvailable = true;
const index = reloadedThemes.findIndex((t) => t.name === theme.name);
reloadedThemes[index] = installedTheme;
}
}
const matchedTheme = themes.find((t) => t.name === themeToUninstall.name);
if (matchedTheme) {
matchedTheme.scriptUrl = '';
matchedTheme.assets = '';
matchedTheme.preview = `https://git.ez-pp.farm/EZPPFarm/EZPPLauncher-Themes/raw/branch/main/previews/${toSafeName(themeToUninstall.name)}.png`;
matchedTheme.status = 'not-installed';
matchedTheme.updateAvailable = false;
}
return reloadedThemes.sort((a, b) => {
if (a.name === 'Default') return -1;
if (b.name === 'Default') return 1;
if (a.status === 'installed' && b.status !== 'installed') return -1;
if (a.status !== 'installed' && b.status === 'installed') return 1;
return a.name.localeCompare(b.name);
});
return themes;
});
await reloadThemes();
return true;
};
@@ -424,7 +374,8 @@ export const checkThemeFromFile = async (filePath: string) => {
style: string;
preview: string;
};
} catch {
} catch (err) {
console.log(err);
return {
success: false,
error: 'Could not read theme file',
@@ -464,54 +415,56 @@ export const importThemeFromFile = async (themeName: string, filePath: string) =
}
}
}
const themeInfo = await fs.readTextFile(await path.join(themeFolder, 'theme.json'));
const themeInfoObj = JSON.parse(themeInfo) as ThemeInfo;
const themeScriptUrl = convertFileSrc(
await path.normalize(`${themeFolder}/${themeInfoObj.entry}`)
);
const themeAssets = convertFileSrc(await path.normalize(`${themeFolder}/assets`));
const themePreview = convertFileSrc(
await path.normalize(`${themeFolder}/assets/${themeInfoObj.preview}`)
);
const downloadableThemes = await getDownloadableThemes();
custom_themes.update((themes) => {
const reloadedThemes = [...themes];
await reloadThemes();
return {
success: true,
};
};
for (const theme of downloadableThemes) {
if (theme.name === 'Default') continue; // never overwrite Default from remote
export const reloadThemes = async () => {
const [downloadableThemes, installedThemes] = await Promise.all([
getDownloadableThemes(),
getThemes(),
]);
if (!reloadedThemes.find((t) => t.name === theme.name)) {
reloadedThemes.push(theme);
const installedMap = new Map(installedThemes.map((t) => [t.name, t]));
const combinedMap = new Map(installedThemes.map((t) => [t.name, { ...t }]));
for (const downloadable of downloadableThemes) {
const installed = installedMap.get(downloadable.name);
if (installed) {
if (new SemVer(downloadable.version).compare(new SemVer(installed.version)) > 0) {
combinedMap.get(downloadable.name)!.updateAvailable = true;
}
} else {
combinedMap.set(downloadable.name, downloadable);
}
}
const installedTheme = reloadedThemes.find((t) => t.name === theme.name);
if (installedTheme) {
const installedThemeVersion = new SemVer(installedTheme.version);
const downloadableThemeVersion = new SemVer(theme.version);
if (downloadableThemeVersion.compare(installedThemeVersion) > 0) {
installedTheme.updateAvailable = true;
const index = reloadedThemes.findIndex((t) => t.name === theme.name);
reloadedThemes[index] = installedTheme;
}
}
const combinedThemes = [...combinedMap.values()];
custom_themes.update((storeThemes) => {
const storeMap = new Map(storeThemes.map((t) => [t.name, t]));
const ACTIVE_STATUSES = new Set(['downloading', 'extracting', 'deleting']);
for (const theme of combinedThemes) {
const storeTheme = storeMap.get(theme.name);
if (!storeTheme || ACTIVE_STATUSES.has(storeTheme.status)) continue;
storeTheme.scriptUrl = theme.scriptUrl;
storeTheme.assets = theme.assets;
storeTheme.preview = theme.preview;
storeTheme.version = theme.version;
storeTheme.author = theme.author;
storeTheme.updateAvailable = theme.updateAvailable;
}
for (const installedTheme of reloadedThemes) {
if (installedTheme.name === 'Default') continue; // never touch Default
const newThemes = combinedThemes.filter((t) => !storeMap.has(t.name));
const merged = [...storeThemes, ...newThemes];
if (installedTheme.name === themeName) {
installedTheme.name = themeInfoObj.name;
installedTheme.author = themeInfoObj.author;
installedTheme.version = themeInfoObj.version;
installedTheme.scriptUrl = themeScriptUrl;
installedTheme.assets = themeAssets;
installedTheme.preview = themePreview;
installedTheme.status = 'installed';
}
}
return reloadedThemes.sort((a, b) => {
return merged.sort((a, b) => {
if (a.name === 'Default') return -1;
if (b.name === 'Default') return 1;
if (a.status === 'installed' && b.status !== 'installed') return -1;
@@ -519,9 +472,6 @@ export const importThemeFromFile = async (themeName: string, filePath: string) =
return a.name.localeCompare(b.name);
});
});
return {
success: true,
};
};
export const toSafeName = (name: string) => {
+56 -46
View File
@@ -99,55 +99,13 @@
disableReload();
setupValues();
launcherVersion.set(await getLauncherVersion());
platform.set(await getPlatform());
if ($platform !== 'windows' && $platform !== 'linux') unsupported_platform = true;
const isFirstStartup = await $userSettings.init();
firstStartup.set(isFirstStartup);
$userAuth.init();
try {
const themeVolume = $userSettings.value('volume').get(0.15);
custom_theme_volume.set(themeVolume);
currentLoadingInfo.set('Loading themes...');
const downloadableThemes = await getDownloadableThemes();
const themes = await getThemes();
const combinedThemes = [...themes];
for (const theme of downloadableThemes) {
if (!combinedThemes.find((t) => t.name === theme.name)) combinedThemes.push(theme);
const installedTheme = themes.find((t) => t.name === theme.name);
if (installedTheme) {
const installedThemeVersion = new SemVer(installedTheme.version);
const downloadableThemeVersion = new SemVer(theme.version);
if (downloadableThemeVersion.compare(installedThemeVersion) > 0) {
installedTheme.updateAvailable = true;
const index = combinedThemes.findIndex((t) => t.name === theme.name);
combinedThemes[index] = installedTheme;
}
}
}
custom_themes.set(combinedThemes);
const activeTheme = $userSettings.value('theme').get('Default');
const theme = themes.find((theme) => theme.name === activeTheme);
if (!theme) {
$userSettings.value('theme').set('Default');
await $userSettings.save();
loadTheme(themes[0], $custom_theme_container!, themeVolume);
} else {
loadTheme(theme, $custom_theme_container!, themeVolume);
}
} catch {
sileo.error({
title: 'An error occured!',
description: 'Failed to load theme',
fill: '#181825',
styles: {
description: 'text-center!',
},
});
}
currentLoadingInfo.set('Loading config...');
const config_theme = $userSettings.value('theme');
const config_theme_volume = $userSettings.value('volume');
const config_patching = $userSettings.value('patching');
const config_custom_cursor = $userSettings.value('custom_cursor');
const config_cursor_smoothening = $userSettings.value('cursor_smoothening');
@@ -156,6 +114,17 @@
const config_discord_presence = $userSettings.value('discord_presence');
const config_tracking_enabled = $userSettings.value('tracking_consent');
const localThemes = await getThemes();
const last_theme = localThemes.find((t) => t.name === config_theme.get('Default'));
if (!last_theme) {
$userSettings.value('theme').set('Default');
await $userSettings.save();
loadTheme(localThemes[0], $custom_theme_container!, config_theme_volume.get(0.15));
} else {
loadTheme(last_theme, $custom_theme_container!, config_theme_volume.get(0.15));
}
custom_theme_volume.set(config_theme_volume.get(0.15));
patch.set(config_patching.get(true));
customCursor.set(config_custom_cursor.get(true));
cursorSmoothening.set(config_cursor_smoothening.get(true));
@@ -170,6 +139,7 @@
customCursor.subscribe((val) => config_custom_cursor.set(val));
cursorSmoothening.subscribe((val) => config_cursor_smoothening.set(val));
reduceAnimations.subscribe((val) => config_reduce_animations.set(val));
discordPresence.subscribe(async (val) => {
config_discord_presence.set(val);
try {
@@ -180,7 +150,10 @@
await presence.disconnect();
}
presenceLoading.set(false);
} catch {}
} catch (err) {
console.log(err);
presenceLoading.set(false);
}
});
try {
@@ -190,7 +163,44 @@
await presence.connect();
presenceLoading.set(false);
}
} catch {}
} catch (err) {
console.log(err);
presenceLoading.set(false);
}
try {
currentLoadingInfo.set('Loading themes...');
const downloadableThemes = await getDownloadableThemes();
const combinedThemes = [...localThemes];
for (const theme of downloadableThemes) {
if (!combinedThemes.find((t) => t.name === theme.name)) combinedThemes.push(theme);
const installedTheme = localThemes.find((t) => t.name === theme.name);
if (installedTheme) {
const installedThemeVersion = new SemVer(installedTheme.version);
const downloadableThemeVersion = new SemVer(theme.version);
if (downloadableThemeVersion.compare(installedThemeVersion) > 0) {
installedTheme.updateAvailable = true;
const index = combinedThemes.findIndex((t) => t.name === theme.name);
combinedThemes[index] = installedTheme;
}
}
}
custom_themes.set(combinedThemes);
} catch (err) {
console.log(err);
sileo.error({
title: 'An error occured!',
description: 'Failed to load themes',
fill: '#181825',
styles: {
description: 'text-center!',
},
});
}
platform.set(await getPlatform());
if ($platform !== 'windows' && $platform !== 'linux') unsupported_platform = true;
});
</script>
+8 -4
View File
@@ -225,7 +225,7 @@
}
osuInstallationPath.set(selectedPath);
$userSettings.value('osu_installation_path').set(selectedPath);
$userSettings.save();
await $userSettings.save();
sileo.success({
title: 'Yay!',
description: 'osu! installation path set successfully.',
@@ -642,7 +642,9 @@
largeImageKey: 'ezppfarm',
}),
]);
} catch {}
} catch (err) {
console.log(err);
}
}
await new Promise((res) => setTimeout(res, 1000));
await replaceUIFiles(osuPath, true);
@@ -740,7 +742,8 @@
});
loginIsLoading = false;
}
} catch {
} catch (err) {
console.log(err);
sileo.error({
title: 'Login failed!',
description: 'There was an issue connecting to the server. Please try again later.',
@@ -1105,7 +1108,8 @@
description: 'text-center!',
},
});
} catch {
} catch (err) {
console.log(err);
sileo.error({
title: 'Hmmm...',
description: 'An unknown error occurred while importing your theme.',
+4 -2
View File
@@ -106,7 +106,8 @@
message: 'Please check your username and password.',
};
}
} catch {
} catch (err) {
console.log(err);
userLoginResult = {
message: 'There was an issue connecting to the server. Please try again later.',
};
@@ -122,7 +123,8 @@
preferredMode.set(userInfo.player.info.preferred_mode);
preferredType.set(userInfo.player.info.preferred_type);
}
} catch {
} catch (err) {
console.log(err);
userLoginResult = {
message: 'There was an issue connecting to the server. Please try again later.',
};