From e35d31c0393cfbec25a03b76ba71ec324f0aa4de Mon Sep 17 00:00:00 2001 From: oza6ut0ne <33759728+oza6ut0ne@users.noreply.github.com> Date: Wed, 1 May 2024 19:54:27 +0900 Subject: [PATCH] Support hardware acceleration --- src/main/config.ts | 10 ++++++++++ src/main/main.ts | 6 ++++-- src/main/menu.ts | 17 +++++++---------- src/main/util.ts | 8 ++++++++ 4 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/main/config.ts b/src/main/config.ts index 0ef0c97..5439164 100644 --- a/src/main/config.ts +++ b/src/main/config.ts @@ -23,6 +23,7 @@ interface ConfigSchema { readonly imgEnabled: boolean; readonly videoEnabled: boolean; readonly roundIconEnabled: boolean; + readonly hardwareAccelerationEnabled: boolean; readonly globalRestoreAccelerator: string; } @@ -78,6 +79,7 @@ class Config { imgEnabled: true, videoEnabled: true, roundIconEnabled: false, + hardwareAccelerationEnabled: false, globalRestoreAccelerator: 'CmdOrCtrl+Shift+Space' }; @@ -213,6 +215,14 @@ class Config { this.store.set(getVarName(() => this.defaultValues.roundIconEnabled), value); } + get hardwareAccelerationEnabled(): boolean { + return this.store.get(getVarName(() => this.defaultValues.hardwareAccelerationEnabled)); + } + + set hardwareAccelerationEnabled(value: boolean) { + this.store.set(getVarName(() => this.defaultValues.hardwareAccelerationEnabled), value); + } + get globalRestoreAccelerator(): string { return this.store.get(getVarName(() => this.defaultValues.globalRestoreAccelerator)); } diff --git a/src/main/main.ts b/src/main/main.ts index c15db3f..9bf395a 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -29,8 +29,10 @@ if (args.c) { app.quit(); } -app.disableHardwareAcceleration(); -app.commandLine.appendSwitch('disable-gpu'); +if (!config.hardwareAccelerationEnabled) { + app.disableHardwareAcceleration(); + app.commandLine.appendSwitch('disable-gpu'); +} app.commandLine.appendSwitch('disable-frame-rate-limit'); app.whenReady().then(() => setTimeout(onAppReady, 2000)); app.on('window-all-closed', app.quit); diff --git a/src/main/menu.ts b/src/main/menu.ts index eccf809..5c5ca89 100644 --- a/src/main/menu.ts +++ b/src/main/menu.ts @@ -4,9 +4,8 @@ import { addDuration, resetDuration, togglePause, updateIconEnabled, updateImgEnabled, updateInlineImgEnabled, updateNewlineEnabled, updateRoundIconEnabled, updateVideoEnabled } from './ipc'; -import { isExe, isMac, isWindows, isAppImage, restoreWindow, aliveOrNull } from './util'; +import { isMac, isWindows, isAppImage, restoreWindow, aliveOrNull, tryRelaunch } from './util'; -const relaunchExecPath = isExe ? process.env.PORTABLE_EXECUTABLE_FILE : undefined; export let tray: Tray | null = null; let trayMenu: Menu | null = null; @@ -77,10 +76,7 @@ function createTrayMenu(windows: BrowserWindow[]): Menu { return { label: v, checked: config.useMultiWindow === v, type: 'radio', click: () => { config.useMultiWindow = v; - if (!isAppImage) { - app.relaunch({ execPath: relaunchExecPath }); - app.quit(); - } + tryRelaunch(); }} })}, { label: 'Visible on all Workspaces', type: 'checkbox', checked: config.visibleOnAllWorkspaces, click: (item) => { @@ -93,6 +89,10 @@ function createTrayMenu(windows: BrowserWindow[]): Menu { { label: 'Show Image', type: 'checkbox', checked: config.imgEnabled, click: (item) => updateImgEnabled(item.checked) }, { label: 'Show Video', type: 'checkbox', checked: config.videoEnabled, click: (item) => updateVideoEnabled(item.checked) }, { label: 'Round Icon', type: 'checkbox', checked: config.roundIconEnabled, click: (item) => updateRoundIconEnabled(item.checked) }, + { label: 'Hardware Acceleration', type: 'checkbox', checked: config.hardwareAccelerationEnabled, click: (item) => { + config.hardwareAccelerationEnabled = item.checked; + tryRelaunch(); + }}, ]} ]); @@ -100,10 +100,7 @@ function createTrayMenu(windows: BrowserWindow[]): Menu { addDebugMenu(contextMenu, windows); } - contextMenu.append(new MenuItem({ label: 'Restart', visible: !isAppImage, click: () => { - app.relaunch({ execPath: relaunchExecPath }); - app.quit(); - }})); + contextMenu.append(new MenuItem({ label: 'Restart', visible: !isAppImage, click: () => tryRelaunch()})); contextMenu.append(new MenuItem({ role: 'quit' })); return contextMenu; diff --git a/src/main/util.ts b/src/main/util.ts index b88c3e0..65009c5 100644 --- a/src/main/util.ts +++ b/src/main/util.ts @@ -5,6 +5,7 @@ export const isWindows = process.platform === 'win32'; export const isMac = process.platform === 'darwin'; export const isAppImage = isLinux && app.isPackaged && app.getPath('exe').startsWith('/tmp/.mount_'); export const isExe = isWindows && app.isPackaged; +export const execPath = isExe ? process.env.PORTABLE_EXECUTABLE_FILE : undefined; export function restoreWindow(window: BrowserWindow | null) { @@ -22,3 +23,10 @@ export function restoreWindow(window: BrowserWindow | null) { export function aliveOrNull(window: BrowserWindow): BrowserWindow | null { return window.isDestroyed() ? null : window; } + +export function tryRelaunch() { + if (!isAppImage) { + app.relaunch({ execPath: execPath }); + app.quit(); + } +}