Merge pull request #207 from Hachi-R/auto-launch

added option to start hydra on system startup
This commit is contained in:
Hydra 2024-05-06 16:27:28 +01:00 committed by GitHub
commit e041d27988
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 630 additions and 400 deletions

View file

@ -37,6 +37,7 @@
"@sentry/vite-plugin": "^2.16.1", "@sentry/vite-plugin": "^2.16.1",
"@vanilla-extract/css": "^1.14.2", "@vanilla-extract/css": "^1.14.2",
"@vanilla-extract/recipes": "^0.5.2", "@vanilla-extract/recipes": "^0.5.2",
"auto-launch": "^5.0.6",
"axios": "^1.6.8", "axios": "^1.6.8",
"better-sqlite3": "^9.5.0", "better-sqlite3": "^9.5.0",
"check-disk-space": "^3.4.0", "check-disk-space": "^3.4.0",
@ -66,6 +67,7 @@
"@electron-toolkit/eslint-config-ts": "^1.0.1", "@electron-toolkit/eslint-config-ts": "^1.0.1",
"@electron-toolkit/tsconfig": "^1.0.1", "@electron-toolkit/tsconfig": "^1.0.1",
"@swc/core": "^1.4.16", "@swc/core": "^1.4.16",
"@types/auto-launch": "^5.0.5",
"@types/jsdom": "^21.1.6", "@types/jsdom": "^21.1.6",
"@types/lodash-es": "^4.17.12", "@types/lodash-es": "^4.17.12",
"@types/node": "^20.12.7", "@types/node": "^20.12.7",

View file

@ -138,7 +138,8 @@
"telemetry": "Telemetry", "telemetry": "Telemetry",
"telemetry_description": "Enable anonymous usage statistics", "telemetry_description": "Enable anonymous usage statistics",
"behavior": "Behavior", "behavior": "Behavior",
"quit_app_instead_hiding": "Close app instead of minimizing to tray" "quit_app_instead_hiding": "Close app instead of minimizing to tray",
"launch_with_system": "Launch app on system start-up"
}, },
"notifications": { "notifications": {
"download_complete": "Download complete", "download_complete": "Download complete",

View file

@ -134,7 +134,8 @@
"telemetry": "Telemetria", "telemetry": "Telemetria",
"telemetry_description": "Habilitar estatísticas de uso anônimas", "telemetry_description": "Habilitar estatísticas de uso anônimas",
"behavior": "Comportamento", "behavior": "Comportamento",
"quit_app_instead_hiding": "Fechar o aplicativo em vez de minimizá-lo" "quit_app_instead_hiding": "Fechar o aplicativo em vez de minimizá-lo",
"launch_with_system": "Iniciar aplicativo na inicialização do sistema"
}, },
"notifications": { "notifications": {
"download_complete": "Download concluído", "download_complete": "Download concluído",

View file

@ -29,6 +29,9 @@ export class UserPreferences {
@Column("boolean", { default: false }) @Column("boolean", { default: false })
preferQuitInsteadOfHiding: boolean; preferQuitInsteadOfHiding: boolean;
@Column("boolean", { default: false })
runAtStartup: boolean;
@CreateDateColumn() @CreateDateColumn()
createdAt: Date; createdAt: Date;

View file

@ -26,6 +26,7 @@ import "./torrenting/resume-game-download";
import "./torrenting/start-game-download"; import "./torrenting/start-game-download";
import "./user-preferences/get-user-preferences"; import "./user-preferences/get-user-preferences";
import "./user-preferences/update-user-preferences"; import "./user-preferences/update-user-preferences";
import "./user-preferences/auto-launch";
ipcMain.handle("ping", () => "pong"); ipcMain.handle("ping", () => "pong");
ipcMain.handle("getVersion", () => app.getVersion()); ipcMain.handle("getVersion", () => app.getVersion());

View file

@ -0,0 +1,21 @@
import { registerEvent } from "../register-event";
import AutoLaunch from "auto-launch";
import { app } from "electron";
const autoLaunch = async (
_event: Electron.IpcMainInvokeEvent,
enabled: boolean
) => {
const appLauncher = new AutoLaunch({
name: app.getName(),
});
if (enabled) {
appLauncher.enable().catch();
} else {
appLauncher.disable().catch();
}
};
registerEvent(autoLaunch, {
name: "autoLaunch",
});

View file

@ -26,7 +26,7 @@ export class WindowManager {
} }
} }
public static async createMainWindow() { public static createMainWindow() {
// Create the browser window. // Create the browser window.
this.mainWindow = new BrowserWindow({ this.mainWindow = new BrowserWindow({
width: 1200, width: 1200,

View file

@ -48,6 +48,7 @@ contextBridge.exposeInMainWorld("electron", {
getUserPreferences: () => ipcRenderer.invoke("getUserPreferences"), getUserPreferences: () => ipcRenderer.invoke("getUserPreferences"),
updateUserPreferences: (preferences: UserPreferences) => updateUserPreferences: (preferences: UserPreferences) =>
ipcRenderer.invoke("updateUserPreferences", preferences), ipcRenderer.invoke("updateUserPreferences", preferences),
autoLaunch: (enabled: boolean) => ipcRenderer.invoke("autoLaunch", enabled),
/* Library */ /* Library */
addGameToLibrary: ( addGameToLibrary: (

View file

@ -57,6 +57,7 @@ contextBridge.exposeInMainWorld("electron", {
getUserPreferences: () => ipcRenderer.invoke("getUserPreferences"), getUserPreferences: () => ipcRenderer.invoke("getUserPreferences"),
updateUserPreferences: (preferences: UserPreferences) => updateUserPreferences: (preferences: UserPreferences) =>
ipcRenderer.invoke("updateUserPreferences", preferences), ipcRenderer.invoke("updateUserPreferences", preferences),
autoLaunch: (enabled: boolean) => ipcRenderer.invoke("autoLaunch", enabled),
/* Library */ /* Library */
addGameToLibrary: ( addGameToLibrary: (

View file

@ -74,6 +74,7 @@ declare global {
updateUserPreferences: ( updateUserPreferences: (
preferences: Partial<UserPreferences> preferences: Partial<UserPreferences>
) => Promise<void>; ) => Promise<void>;
autoLaunch: (enabled: boolean) => Promise<void>;
/* Hardware */ /* Hardware */
getDiskFreeSpace: (path: string) => Promise<DiskSpace>; getDiskFreeSpace: (path: string) => Promise<DiskSpace>;

View file

@ -12,6 +12,7 @@ export function Settings() {
repackUpdatesNotificationsEnabled: false, repackUpdatesNotificationsEnabled: false,
telemetryEnabled: false, telemetryEnabled: false,
preferQuitInsteadOfHiding: false, preferQuitInsteadOfHiding: false,
runAtStartup: false,
}); });
const { t } = useTranslation("settings"); const { t } = useTranslation("settings");
@ -30,6 +31,7 @@ export function Settings() {
telemetryEnabled: userPreferences?.telemetryEnabled ?? false, telemetryEnabled: userPreferences?.telemetryEnabled ?? false,
preferQuitInsteadOfHiding: preferQuitInsteadOfHiding:
userPreferences?.preferQuitInsteadOfHiding ?? false, userPreferences?.preferQuitInsteadOfHiding ?? false,
runAtStartup: userPreferences?.runAtStartup ?? false,
}); });
}); });
}, []); }, []);
@ -123,6 +125,15 @@ export function Settings() {
) )
} }
/> />
<CheckboxField
label={t("launch_with_system")}
onChange={() => {
updateUserPreferences("runAtStartup", !form.runAtStartup);
window.electron.autoLaunch(!form.runAtStartup);
}}
checked={form.runAtStartup}
/>
</div> </div>
</section> </section>
); );

View file

@ -106,6 +106,7 @@ export interface UserPreferences {
repackUpdatesNotificationsEnabled: boolean; repackUpdatesNotificationsEnabled: boolean;
telemetryEnabled: boolean; telemetryEnabled: boolean;
preferQuitInsteadOfHiding: boolean; preferQuitInsteadOfHiding: boolean;
runAtStartup: boolean;
} }
export interface HowLongToBeatCategory { export interface HowLongToBeatCategory {

980
yarn.lock

File diff suppressed because it is too large Load diff