Merge pull request #953 from hydralauncher/fix/add-language-migration

feat: add language migration
This commit is contained in:
Chubby Granny Chaser 2024-09-14 00:19:38 +01:00 committed by GitHub
commit 7846ecbd4f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 20 additions and 3 deletions

View file

@ -2,12 +2,13 @@ import knex, { Knex } from "knex";
import { databasePath } from "./constants";
import { Hydra2_0_3 } from "./migrations/20240830143811_Hydra_2_0_3";
import { RepackUris } from "./migrations/20240830143906_RepackUris";
import { UpdateUserLanguage } from "./migrations/20240913213944_update_user_language";
export type HydraMigration = Knex.Migration & { name: string };
class MigrationSource implements Knex.MigrationSource<HydraMigration> {
getMigrations(): Promise<HydraMigration[]> {
return Promise.resolve([Hydra2_0_3, RepackUris]);
return Promise.resolve([Hydra2_0_3, RepackUris, UpdateUserLanguage]);
}
getMigrationName(migration: HydraMigration): string {
return migration.name;

View file

@ -0,0 +1,13 @@
import type { HydraMigration } from "@main/knex-client";
import type { Knex } from "knex";
export const UpdateUserLanguage: HydraMigration = {
name: "UpdateUserLanguage",
up: async (knex: Knex) => {
await knex("user_preferences")
.update("language", "pt-BR")
.where("language", "pt");
},
down: async (_knex: Knex) => {},
};

View file

@ -41,8 +41,11 @@ i18n
escapeValue: false,
},
})
.then(() => {
window.electron.updateUserPreferences({ language: i18n.language });
.then(async () => {
const userPreferences = await window.electron.getUserPreferences();
if (!userPreferences?.language) {
window.electron.updateUserPreferences({ language: i18n.language });
}
});
ReactDOM.createRoot(document.getElementById("root")!).render(