feat: create SystemPath class to prevent Hydra not opening when some user folders are not correctly set on windows

This commit is contained in:
Zamitto
2025-04-30 12:10:26 -03:00
parent 6068d70aeb
commit f52f0ca614
11 changed files with 79 additions and 23 deletions

View File

@@ -0,0 +1,45 @@
import { app, dialog } from "electron";
import { logger } from "./logger";
export class SystemPath {
static readonly paths = {
userData: "userData",
downloads: "downloads",
documents: "documents",
desktop: "desktop",
home: "home",
appData: "appData",
temp: "temp",
};
static checkIfPathsAreAvailable() {
const paths = Object.keys(SystemPath.paths) as Array<
keyof typeof SystemPath.paths
>;
paths.forEach((pathName) => {
try {
app.getPath(pathName);
} catch (error) {
logger.error(`Error getting path ${pathName}`);
if (error instanceof Error) {
logger.error(error.message, error.stack);
}
dialog.showErrorBox(
`Hydra was not able to find path for '${pathName}' system folder`,
`Some functionalities may not work as expected.\nPlease check your system settings.`
);
}
});
}
static getPath(pathName: keyof typeof SystemPath.paths): string {
try {
return app.getPath(pathName);
} catch (error) {
logger.error(`Error getting path: ${error}`);
return "";
}
}
}