From 6dd454a982943eda79f9d4bb76211952fbce659c Mon Sep 17 00:00:00 2001 From: Hachi-R Date: Wed, 30 Oct 2024 14:38:27 -0300 Subject: [PATCH 01/12] feat: add 'startMinimized' property to user preferences --- src/main/entity/user-preferences.entity.ts | 3 +++ src/main/knex-client.ts | 3 ++- .../20241030171454_quality_of_life.ts | 17 +++++++++++++++++ src/types/index.ts | 1 + 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/main/migrations/20241030171454_quality_of_life.ts diff --git a/src/main/entity/user-preferences.entity.ts b/src/main/entity/user-preferences.entity.ts index dc6d465d..b43d463e 100644 --- a/src/main/entity/user-preferences.entity.ts +++ b/src/main/entity/user-preferences.entity.ts @@ -35,6 +35,9 @@ export class UserPreferences { @Column("boolean", { default: false }) runAtStartup: boolean; + @Column("boolean", { default: false }) + startMinimized: boolean; + @CreateDateColumn() createdAt: Date; diff --git a/src/main/knex-client.ts b/src/main/knex-client.ts index 5f81ffbc..7db67250 100644 --- a/src/main/knex-client.ts +++ b/src/main/knex-client.ts @@ -11,7 +11,7 @@ import { AddAchievementNotificationPreference } from "./migrations/2024101301290 import { CreateUserSubscription } from "./migrations/20241015235142_create_user_subscription"; import { AddBackgroundImageUrl } from "./migrations/20241016100249_add_background_image_url"; import { AddWinePrefixToGame } from "./migrations/20241019081648_add_wine_prefix_to_game"; - +import { QualityOfLife } from "./migrations/20241030171454_quality_of_life"; export type HydraMigration = Knex.Migration & { name: string }; class MigrationSource implements Knex.MigrationSource { @@ -27,6 +27,7 @@ class MigrationSource implements Knex.MigrationSource { CreateUserSubscription, AddBackgroundImageUrl, AddWinePrefixToGame, + QualityOfLife, ]); } getMigrationName(migration: HydraMigration): string { diff --git a/src/main/migrations/20241030171454_quality_of_life.ts b/src/main/migrations/20241030171454_quality_of_life.ts new file mode 100644 index 00000000..5d2db874 --- /dev/null +++ b/src/main/migrations/20241030171454_quality_of_life.ts @@ -0,0 +1,17 @@ +import type { HydraMigration } from "@main/knex-client"; +import type { Knex } from "knex"; + +export const QualityOfLife: HydraMigration = { + name: "QualityOfLife", + up: (knex: Knex) => { + return knex.schema.alterTable("user_preferences", (table) => { + return table.boolean("startMinimized").notNullable().defaultTo(0); + }); + }, + + down: async (knex: Knex) => { + return knex.schema.alterTable("user_preferences", (table) => { + return table.dropColumn("startMinimized"); + }); + }, +}; diff --git a/src/types/index.ts b/src/types/index.ts index 7f970d63..9bb25e3f 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -160,6 +160,7 @@ export interface UserPreferences { realDebridApiToken: string | null; preferQuitInsteadOfHiding: boolean; runAtStartup: boolean; + startMinimized: boolean; } export interface Steam250Game { From 7af56cd7ccbeb995ccde35c0e5d23f255b126f13 Mon Sep 17 00:00:00 2001 From: Hachi-R Date: Wed, 30 Oct 2024 15:03:46 -0300 Subject: [PATCH 02/12] feat: add option to start minimized in user settings --- src/locales/en/translation.json | 3 ++- src/locales/pt-BR/translation.json | 3 ++- .../src/pages/settings/settings-behavior.tsx | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/locales/en/translation.json b/src/locales/en/translation.json index 01cfcdf8..a17875ad 100644 --- a/src/locales/en/translation.json +++ b/src/locales/en/translation.json @@ -253,7 +253,8 @@ "must_be_valid_url": "The source must be a valid URL", "blocked_users": "Blocked users", "user_unblocked": "User has been unblocked", - "enable_achievement_notifications": "When an achievement in unlocked" + "enable_achievement_notifications": "When an achievement in unlocked", + "launch_minimized": "Launch Hydra minimized" }, "notifications": { "download_complete": "Download complete", diff --git a/src/locales/pt-BR/translation.json b/src/locales/pt-BR/translation.json index 694a805d..e0f59e24 100644 --- a/src/locales/pt-BR/translation.json +++ b/src/locales/pt-BR/translation.json @@ -249,7 +249,8 @@ "must_be_valid_url": "A fonte deve ser uma URL válida", "blocked_users": "Usuários bloqueados", "user_unblocked": "Usuário desbloqueado", - "enable_achievement_notifications": "Quando uma conquista é desbloqueada" + "enable_achievement_notifications": "Quando uma conquista é desbloqueada", + "launch_minimized": "Iniciar o Hydra minimizado" }, "notifications": { "download_complete": "Download concluído", diff --git a/src/renderer/src/pages/settings/settings-behavior.tsx b/src/renderer/src/pages/settings/settings-behavior.tsx index f0b4b4c4..aabbe27d 100644 --- a/src/renderer/src/pages/settings/settings-behavior.tsx +++ b/src/renderer/src/pages/settings/settings-behavior.tsx @@ -17,6 +17,7 @@ export function SettingsBehavior() { const [form, setForm] = useState({ preferQuitInsteadOfHiding: false, runAtStartup: false, + startMinimized: false, }); const { t } = useTranslation("settings"); @@ -26,10 +27,13 @@ export function SettingsBehavior() { setForm({ preferQuitInsteadOfHiding: userPreferences.preferQuitInsteadOfHiding, runAtStartup: userPreferences.runAtStartup, + startMinimized: userPreferences.startMinimized, }); } }, [userPreferences]); + console.log(userPreferences?.startMinimized); + useEffect(() => { window.electron.isPortableVersion().then((isPortableVersion) => { setShowRunAtStartup(!isPortableVersion); @@ -63,6 +67,20 @@ export function SettingsBehavior() { checked={form.runAtStartup} /> )} + + {showRunAtStartup && ( +
+ { + handleChange({ startMinimized: !form.startMinimized }); + }} + /> +
+ )} ); } From 9e020652c9b177564099dce5bb5f6be155f5f8f7 Mon Sep 17 00:00:00 2001 From: Hachi-R Date: Wed, 30 Oct 2024 15:38:17 -0300 Subject: [PATCH 03/12] feat: implement launch minimized option --- src/main/events/user-preferences/auto-launch.ts | 5 +++-- src/preload/index.ts | 3 ++- src/renderer/src/declaration.d.ts | 4 +++- src/renderer/src/pages/settings/settings-behavior.tsx | 3 ++- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/events/user-preferences/auto-launch.ts b/src/main/events/user-preferences/auto-launch.ts index 1f4f9cc3..0b1bba21 100644 --- a/src/main/events/user-preferences/auto-launch.ts +++ b/src/main/events/user-preferences/auto-launch.ts @@ -16,15 +16,16 @@ const windowsStartupPath = path.join( const autoLaunch = async ( _event: Electron.IpcMainInvokeEvent, - enabled: boolean + autoLaunchProps: { enabled: boolean; minimized: boolean } ) => { if (!app.isPackaged) return; const appLauncher = new AutoLaunch({ name: app.getName(), + isHidden: autoLaunchProps.minimized, }); - if (enabled) { + if (autoLaunchProps.enabled) { appLauncher.enable().catch((err) => { logger.error(err); }); diff --git a/src/preload/index.ts b/src/preload/index.ts index 90c50763..9baa8325 100644 --- a/src/preload/index.ts +++ b/src/preload/index.ts @@ -101,7 +101,8 @@ contextBridge.exposeInMainWorld("electron", { getUserPreferences: () => ipcRenderer.invoke("getUserPreferences"), updateUserPreferences: (preferences: UserPreferences) => ipcRenderer.invoke("updateUserPreferences", preferences), - autoLaunch: (enabled: boolean) => ipcRenderer.invoke("autoLaunch", enabled), + autoLaunch: (autoLaunchProps: { enabled: boolean; minimized: boolean }) => + ipcRenderer.invoke("autoLaunch", autoLaunchProps), authenticateRealDebrid: (apiToken: string) => ipcRenderer.invoke("authenticateRealDebrid", apiToken), diff --git a/src/renderer/src/declaration.d.ts b/src/renderer/src/declaration.d.ts index 929b00e9..a639bd15 100644 --- a/src/renderer/src/declaration.d.ts +++ b/src/renderer/src/declaration.d.ts @@ -114,7 +114,9 @@ declare global { updateUserPreferences: ( preferences: Partial ) => Promise; - autoLaunch: (enabled: boolean) => Promise; + autoLaunch: ( + autoLaunchProps: { enabled?: boolean; minimized?: boolean } + ) => Promise; authenticateRealDebrid: (apiToken: string) => Promise; /* Download sources */ diff --git a/src/renderer/src/pages/settings/settings-behavior.tsx b/src/renderer/src/pages/settings/settings-behavior.tsx index aabbe27d..c0be02d6 100644 --- a/src/renderer/src/pages/settings/settings-behavior.tsx +++ b/src/renderer/src/pages/settings/settings-behavior.tsx @@ -62,7 +62,7 @@ export function SettingsBehavior() { label={t("launch_with_system")} onChange={() => { handleChange({ runAtStartup: !form.runAtStartup }); - window.electron.autoLaunch(!form.runAtStartup); + window.electron.autoLaunch({ enabled: !form.runAtStartup }); }} checked={form.runAtStartup} /> @@ -77,6 +77,7 @@ export function SettingsBehavior() { disabled={!form.runAtStartup} onChange={() => { handleChange({ startMinimized: !form.startMinimized }); + window.electron.autoLaunch({ minimized: !form.startMinimized }); }} /> From ad3b84b0ae67e2f3cc1c7d9e46a80117a21bd8c1 Mon Sep 17 00:00:00 2001 From: Hachi-R Date: Wed, 30 Oct 2024 15:38:36 -0300 Subject: [PATCH 04/12] lint --- src/renderer/src/declaration.d.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/renderer/src/declaration.d.ts b/src/renderer/src/declaration.d.ts index a639bd15..e9d57529 100644 --- a/src/renderer/src/declaration.d.ts +++ b/src/renderer/src/declaration.d.ts @@ -114,9 +114,10 @@ declare global { updateUserPreferences: ( preferences: Partial ) => Promise; - autoLaunch: ( - autoLaunchProps: { enabled?: boolean; minimized?: boolean } - ) => Promise; + autoLaunch: (autoLaunchProps: { + enabled?: boolean; + minimized?: boolean; + }) => Promise; authenticateRealDebrid: (apiToken: string) => Promise; /* Download sources */ From 36813d5f8695f34b3e853e443e3affa3fb2c197b Mon Sep 17 00:00:00 2001 From: Hachi-R Date: Wed, 30 Oct 2024 17:34:38 -0300 Subject: [PATCH 05/12] chore: remove unnecessary log --- src/renderer/src/pages/settings/settings-behavior.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/renderer/src/pages/settings/settings-behavior.tsx b/src/renderer/src/pages/settings/settings-behavior.tsx index c0be02d6..d2794c36 100644 --- a/src/renderer/src/pages/settings/settings-behavior.tsx +++ b/src/renderer/src/pages/settings/settings-behavior.tsx @@ -32,8 +32,6 @@ export function SettingsBehavior() { } }, [userPreferences]); - console.log(userPreferences?.startMinimized); - useEffect(() => { window.electron.isPortableVersion().then((isPortableVersion) => { setShowRunAtStartup(!isPortableVersion); From 0d68851cf4fb76d952d15fbf18abe8520133a204 Mon Sep 17 00:00:00 2001 From: Hachi-R Date: Wed, 30 Oct 2024 17:46:52 -0300 Subject: [PATCH 06/12] fix: ensure both values are passed to object to prevent false outcome --- src/renderer/src/declaration.d.ts | 4 ++-- src/renderer/src/pages/settings/settings-behavior.tsx | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/renderer/src/declaration.d.ts b/src/renderer/src/declaration.d.ts index e9d57529..a12862b3 100644 --- a/src/renderer/src/declaration.d.ts +++ b/src/renderer/src/declaration.d.ts @@ -115,8 +115,8 @@ declare global { preferences: Partial ) => Promise; autoLaunch: (autoLaunchProps: { - enabled?: boolean; - minimized?: boolean; + enabled: boolean; + minimized: boolean; }) => Promise; authenticateRealDebrid: (apiToken: string) => Promise; diff --git a/src/renderer/src/pages/settings/settings-behavior.tsx b/src/renderer/src/pages/settings/settings-behavior.tsx index d2794c36..4e3ef2f3 100644 --- a/src/renderer/src/pages/settings/settings-behavior.tsx +++ b/src/renderer/src/pages/settings/settings-behavior.tsx @@ -60,7 +60,10 @@ export function SettingsBehavior() { label={t("launch_with_system")} onChange={() => { handleChange({ runAtStartup: !form.runAtStartup }); - window.electron.autoLaunch({ enabled: !form.runAtStartup }); + window.electron.autoLaunch({ + enabled: !form.runAtStartup, + minimized: form.startMinimized, + }); }} checked={form.runAtStartup} /> @@ -75,7 +78,10 @@ export function SettingsBehavior() { disabled={!form.runAtStartup} onChange={() => { handleChange({ startMinimized: !form.startMinimized }); - window.electron.autoLaunch({ minimized: !form.startMinimized }); + window.electron.autoLaunch({ + minimized: !form.startMinimized, + enabled: form.runAtStartup, + }); }} /> From f585e343d980c32497b7cea497243817a1c31cee Mon Sep 17 00:00:00 2001 From: Hachi-R Date: Wed, 30 Oct 2024 19:59:37 -0300 Subject: [PATCH 07/12] feat: use argv to start app minimized on system launch --- src/main/services/window-manager.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/services/window-manager.ts b/src/main/services/window-manager.ts index e1dc4dfc..d9f996af 100644 --- a/src/main/services/window-manager.ts +++ b/src/main/services/window-manager.ts @@ -136,6 +136,10 @@ export class WindowManager { this.mainWindow.on("ready-to-show", () => { if (!app.isPackaged) WindowManager.mainWindow?.webContents.openDevTools(); WindowManager.mainWindow?.show(); + + if (process.argv.includes("--hide") || process.argv.includes("--hidden")) { + WindowManager.mainWindow?.hide(); + } }); this.mainWindow.on("close", async () => { From 0ecd27d4d500aa340a1baaeaa755909102940d90 Mon Sep 17 00:00:00 2001 From: Hachi-R Date: Wed, 30 Oct 2024 20:00:50 -0300 Subject: [PATCH 08/12] lint --- src/main/services/window-manager.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/services/window-manager.ts b/src/main/services/window-manager.ts index d9f996af..f537b375 100644 --- a/src/main/services/window-manager.ts +++ b/src/main/services/window-manager.ts @@ -137,7 +137,10 @@ export class WindowManager { if (!app.isPackaged) WindowManager.mainWindow?.webContents.openDevTools(); WindowManager.mainWindow?.show(); - if (process.argv.includes("--hide") || process.argv.includes("--hidden")) { + if ( + process.argv.includes("--hide") || + process.argv.includes("--hidden") + ) { WindowManager.mainWindow?.hide(); } }); From 619090961b7b162361916ec98b3a5488b710dc24 Mon Sep 17 00:00:00 2001 From: Hachi-R Date: Thu, 31 Oct 2024 01:09:10 -0300 Subject: [PATCH 09/12] chore: refactor hidden startup logic and tray click event --- src/main/services/window-manager.ts | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/main/services/window-manager.ts b/src/main/services/window-manager.ts index f537b375..efc8881c 100644 --- a/src/main/services/window-manager.ts +++ b/src/main/services/window-manager.ts @@ -135,13 +135,17 @@ export class WindowManager { this.mainWindow.on("ready-to-show", () => { if (!app.isPackaged) WindowManager.mainWindow?.webContents.openDevTools(); - WindowManager.mainWindow?.show(); if ( process.argv.includes("--hide") || process.argv.includes("--hidden") ) { WindowManager.mainWindow?.hide(); + process.argv = process.argv.filter( + (arg) => arg !== "--hide" && arg !== "--hidden" + ); + } else { + WindowManager.mainWindow?.show(); } }); @@ -317,14 +321,15 @@ export class WindowManager { if (process.platform !== "darwin") { tray.addListener("click", () => { if (this.mainWindow) { - if (WindowManager.mainWindow?.isMinimized()) - WindowManager.mainWindow.restore(); - - WindowManager.mainWindow?.focus(); - return; + if ( + WindowManager.mainWindow?.isMinimized() || + !WindowManager.mainWindow?.isVisible() + ) { + WindowManager.mainWindow?.show(); + } + } else { + this.createMainWindow(); } - - this.createMainWindow(); }); tray.addListener("right-click", showContextMenu); From 554889fe7d791866920c010f8fe798b39f74079e Mon Sep 17 00:00:00 2001 From: Hachi-R Date: Thu, 31 Oct 2024 09:26:55 -0300 Subject: [PATCH 10/12] refactor: remove launch app minimized logic --- src/main/services/window-manager.ts | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/main/services/window-manager.ts b/src/main/services/window-manager.ts index efc8881c..b61c991a 100644 --- a/src/main/services/window-manager.ts +++ b/src/main/services/window-manager.ts @@ -135,18 +135,7 @@ export class WindowManager { this.mainWindow.on("ready-to-show", () => { if (!app.isPackaged) WindowManager.mainWindow?.webContents.openDevTools(); - - if ( - process.argv.includes("--hide") || - process.argv.includes("--hidden") - ) { - WindowManager.mainWindow?.hide(); - process.argv = process.argv.filter( - (arg) => arg !== "--hide" && arg !== "--hidden" - ); - } else { - WindowManager.mainWindow?.show(); - } + WindowManager.mainWindow?.show(); }); this.mainWindow.on("close", async () => { From 43558f8c0e0be00bfabddfe3716cb7a46e4cb1fb Mon Sep 17 00:00:00 2001 From: Hachi-R Date: Thu, 31 Oct 2024 11:32:20 -0300 Subject: [PATCH 11/12] feat: prevent main window creation when --hidden arg is present --- src/main/index.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/index.ts b/src/main/index.ts index 1b1629ef..7f35c317 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -101,7 +101,10 @@ app.whenReady().then(async () => { i18n.changeLanguage(userPreferences.language); } - WindowManager.createMainWindow(); + if (!process.argv.includes("--hidden")) { + WindowManager.createMainWindow(); + } + WindowManager.createNotificationWindow(); WindowManager.createSystemTray(userPreferences?.language || "en"); }); From 5fb08b39fa356de4de3ddfbd6b236e06f77a135a Mon Sep 17 00:00:00 2001 From: Hachi-R Date: Thu, 31 Oct 2024 11:39:18 -0300 Subject: [PATCH 12/12] refactor: rename migration to be more descriptive --- src/main/knex-client.ts | 4 ++-- ...f_life.ts => 20241030171454_add_start_minimized_column.ts} | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) rename src/main/migrations/{20241030171454_quality_of_life.ts => 20241030171454_add_start_minimized_column.ts} (82%) diff --git a/src/main/knex-client.ts b/src/main/knex-client.ts index 7db67250..eec5b054 100644 --- a/src/main/knex-client.ts +++ b/src/main/knex-client.ts @@ -11,7 +11,7 @@ import { AddAchievementNotificationPreference } from "./migrations/2024101301290 import { CreateUserSubscription } from "./migrations/20241015235142_create_user_subscription"; import { AddBackgroundImageUrl } from "./migrations/20241016100249_add_background_image_url"; import { AddWinePrefixToGame } from "./migrations/20241019081648_add_wine_prefix_to_game"; -import { QualityOfLife } from "./migrations/20241030171454_quality_of_life"; +import { AddStartMinimizedColumn } from "./migrations/20241030171454_add_start_minimized_column"; export type HydraMigration = Knex.Migration & { name: string }; class MigrationSource implements Knex.MigrationSource { @@ -27,7 +27,7 @@ class MigrationSource implements Knex.MigrationSource { CreateUserSubscription, AddBackgroundImageUrl, AddWinePrefixToGame, - QualityOfLife, + AddStartMinimizedColumn, ]); } getMigrationName(migration: HydraMigration): string { diff --git a/src/main/migrations/20241030171454_quality_of_life.ts b/src/main/migrations/20241030171454_add_start_minimized_column.ts similarity index 82% rename from src/main/migrations/20241030171454_quality_of_life.ts rename to src/main/migrations/20241030171454_add_start_minimized_column.ts index 5d2db874..69ede189 100644 --- a/src/main/migrations/20241030171454_quality_of_life.ts +++ b/src/main/migrations/20241030171454_add_start_minimized_column.ts @@ -1,8 +1,8 @@ import type { HydraMigration } from "@main/knex-client"; import type { Knex } from "knex"; -export const QualityOfLife: HydraMigration = { - name: "QualityOfLife", +export const AddStartMinimizedColumn: HydraMigration = { + name: "AddStartMinimizedColumn", up: (knex: Knex) => { return knex.schema.alterTable("user_preferences", (table) => { return table.boolean("startMinimized").notNullable().defaultTo(0);