mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-02-03 08:43:48 +03:00
Merge branch 'main' of https://github.com/fhilipecrash/hydra
This commit is contained in:
commit
53f85503e2
@ -88,6 +88,9 @@
|
||||
"delete": "Remove all files"
|
||||
},
|
||||
"settings": {
|
||||
"error_title_modal": "Error",
|
||||
"error_modal_download": "Your selected folder does not have write permissions or does not exist, please check the folder in your \"Settings\" tab",
|
||||
"error_description_modal": "The selected directory does not have write permissions or does not exist, please choose another folder",
|
||||
"downloads_path": "Downloads path",
|
||||
"change": "Update",
|
||||
"notifications": "Notifications",
|
||||
|
@ -88,6 +88,9 @@
|
||||
"delete": "Apagar arquivos"
|
||||
},
|
||||
"settings": {
|
||||
"error_title_modal": "Erro",
|
||||
"error_modal_download": "Você selecionou uma pasta que não tem permissão de escrita ou não existe, por favor verifique na área \"Configurações\"",
|
||||
"error_description_modal": "O diretório selecionado não possui permissão de escrita ou não existe, favor selecione outra pasta",
|
||||
"downloads_path": "Diretório dos downloads",
|
||||
"change": "Mudar",
|
||||
"notifications": "Notificações",
|
||||
|
10
src/main/events/helpers/validate-path.ts
Normal file
10
src/main/events/helpers/validate-path.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import fs from "fs";
|
||||
|
||||
export default function validatePath(path: string): Error | undefined {
|
||||
try {
|
||||
fs.accessSync(path, fs.constants.W_OK);
|
||||
return;
|
||||
} catch (error) {
|
||||
return error as Error;
|
||||
}
|
||||
}
|
@ -8,6 +8,9 @@ import type { GameShop } from "@types";
|
||||
import { getDownloadsPath } from "../helpers/get-downloads-path";
|
||||
import { getImageBase64 } from "@main/helpers";
|
||||
import { In } from "typeorm";
|
||||
import validatePath from "./helpers/validate-path";
|
||||
import { dialog } from "electron";
|
||||
import { t } from "i18next";
|
||||
|
||||
const startGameDownload = async (
|
||||
_event: Electron.IpcMainInvokeEvent,
|
||||
@ -38,6 +41,20 @@ const startGameDownload = async (
|
||||
writePipe.write({ action: "pause" });
|
||||
|
||||
const downloadsPath = game?.downloadPath ?? (await getDownloadsPath());
|
||||
const error = validatePath(downloadsPath);
|
||||
if (error) {
|
||||
dialog.showErrorBox(
|
||||
t("error_title_modal", {
|
||||
ns: "settings",
|
||||
lng: "en",
|
||||
}),
|
||||
`${t("error_modal_download", {
|
||||
ns: "settings",
|
||||
lng: "en",
|
||||
})}${error instanceof Error ? "\n" + error.message : ""}`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
await gameRepository.update(
|
||||
{
|
||||
|
@ -1,12 +1,15 @@
|
||||
import { userPreferencesRepository } from "@main/repository";
|
||||
import { registerEvent } from "../register-event";
|
||||
|
||||
import { registerEvent } from "./register-event";
|
||||
import { dialog } from "electron";
|
||||
import { t } from "i18next";
|
||||
import type { UserPreferences } from "@types";
|
||||
import validatePath from "./helpers/validate-path";
|
||||
|
||||
const updateUserPreferences = async (
|
||||
_event: Electron.IpcMainInvokeEvent,
|
||||
preferences: Partial<UserPreferences>
|
||||
) => {
|
||||
const payload = async () =>
|
||||
await userPreferencesRepository.upsert(
|
||||
{
|
||||
id: 1,
|
||||
@ -14,6 +17,28 @@ const updateUserPreferences = async (
|
||||
},
|
||||
["id"]
|
||||
);
|
||||
|
||||
if (preferences.downloadsPath) {
|
||||
const error = validatePath(preferences.downloadsPath);
|
||||
|
||||
if (!error) {
|
||||
payload();
|
||||
return true;
|
||||
}
|
||||
dialog.showErrorBox(
|
||||
t("error_title_modal", {
|
||||
ns: "settings",
|
||||
lng: "en",
|
||||
}),
|
||||
`${t("error_description_modal", {
|
||||
ns: "settings",
|
||||
lng: "en",
|
||||
})}${error instanceof Error ? "\n" + error.message : ""}`
|
||||
);
|
||||
return false;
|
||||
}
|
||||
payload();
|
||||
return true;
|
||||
};
|
||||
|
||||
registerEvent(updateUserPreferences, {
|
||||
|
2
src/renderer/declaration.d.ts
vendored
2
src/renderer/declaration.d.ts
vendored
@ -52,7 +52,7 @@ declare global {
|
||||
getUserPreferences: () => Promise<UserPreferences | null>;
|
||||
updateUserPreferences: (
|
||||
preferences: Partial<UserPreferences>
|
||||
) => Promise<void>;
|
||||
) => Promise<boolean>;
|
||||
|
||||
/* Hardware */
|
||||
getDiskFreeSpace: () => Promise<DiskSpace>;
|
||||
|
@ -29,15 +29,14 @@ export function Settings() {
|
||||
});
|
||||
}, []);
|
||||
|
||||
const updateUserPreferences = <T extends keyof UserPreferences>(
|
||||
const updateUserPreferences = async <T extends keyof UserPreferences>(
|
||||
field: T,
|
||||
value: UserPreferences[T]
|
||||
) => {
|
||||
setForm((prev) => ({ ...prev, [field]: value }));
|
||||
|
||||
window.electron.updateUserPreferences({
|
||||
const payload = await window.electron.updateUserPreferences({
|
||||
[field]: value,
|
||||
});
|
||||
setForm((prev) => (payload ? { ...prev, [field]: value } : prev));
|
||||
};
|
||||
|
||||
const handleChooseDownloadsPath = async () => {
|
||||
|
Loading…
Reference in New Issue
Block a user