From 39572702a060ad327f9424319c4337939d3f51b4 Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Sun, 5 Jan 2025 12:28:33 -0300 Subject: [PATCH] feat: remove unnecessary userPreferences findOne --- src/main/index.ts | 5 +++-- src/main/main.ts | 10 +--------- .../game-details/modals/download-settings-modal.tsx | 4 +--- src/types/index.ts | 1 + 4 files changed, 6 insertions(+), 14 deletions(-) diff --git a/src/main/index.ts b/src/main/index.ts index ca49a9fb..a1c45402 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -13,6 +13,7 @@ import { knexClient, migrationConfig } from "./knex-client"; import { databaseDirectory } from "./constants"; import { PythonRPC } from "./services/python-rpc"; import { Aria2 } from "./services/aria2"; +import { loadState } from "./main"; const { autoUpdater } = updater; @@ -86,12 +87,12 @@ app.whenReady().then(async () => { await dataSource.initialize(); - await import("./main"); - const userPreferences = await userPreferencesRepository.findOne({ where: { id: 1 }, }); + await loadState(userPreferences); + if (userPreferences?.language) { i18n.changeLanguage(userPreferences.language); } diff --git a/src/main/main.ts b/src/main/main.ts index 477d887f..82f682c7 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -12,7 +12,7 @@ import { Aria2 } from "./services/aria2"; import { Downloader } from "@shared"; import { IsNull, Not } from "typeorm"; -const loadState = async (userPreferences: UserPreferences | null) => { +export const loadState = async (userPreferences: UserPreferences | null) => { await import("./events"); Aria2.spawn(); @@ -49,11 +49,3 @@ const loadState = async (userPreferences: UserPreferences | null) => { startMainLoop(); }; - -userPreferencesRepository - .findOne({ - where: { id: 1 }, - }) - .then((userPreferences) => { - loadState(userPreferences); - }); diff --git a/src/renderer/src/pages/game-details/modals/download-settings-modal.tsx b/src/renderer/src/pages/game-details/modals/download-settings-modal.tsx index 541bd01c..acb4c169 100644 --- a/src/renderer/src/pages/game-details/modals/download-settings-modal.tsx +++ b/src/renderer/src/pages/game-details/modals/download-settings-modal.tsx @@ -98,9 +98,7 @@ export function DownloadSettingsModal({ ? Downloader.RealDebrid : filteredDownloaders[0]; - setSelectedDownloader( - selectedDownloader === undefined ? null : selectedDownloader - ); + setSelectedDownloader(selectedDownloader ?? null); }, [ userPreferences?.downloadsPath, downloaders, diff --git a/src/types/index.ts b/src/types/index.ts index 345893a5..cd1094cc 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -299,6 +299,7 @@ export interface UpdateProfileRequest { profileImageUrl?: string | null; backgroundImageUrl?: string | null; bio?: string; + language?: string; } export interface DownloadSourceDownload {