mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-24 11:21:02 +00:00
feat: create SystemPath class to prevent Hydra not opening when some user folders are not correctly set on windows
This commit is contained in:
45
src/main/services/system-path.ts
Normal file
45
src/main/services/system-path.ts
Normal 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 "";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user