Skip to content

Commit

Permalink
Support hardware acceleration
Browse files Browse the repository at this point in the history
  • Loading branch information
oza6ut0ne committed May 1, 2024
1 parent f80b150 commit e35d31c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
10 changes: 10 additions & 0 deletions src/main/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ interface ConfigSchema {
readonly imgEnabled: boolean;
readonly videoEnabled: boolean;
readonly roundIconEnabled: boolean;
readonly hardwareAccelerationEnabled: boolean;
readonly globalRestoreAccelerator: string;
}

Expand Down Expand Up @@ -78,6 +79,7 @@ class Config {
imgEnabled: true,
videoEnabled: true,
roundIconEnabled: false,
hardwareAccelerationEnabled: false,
globalRestoreAccelerator: 'CmdOrCtrl+Shift+Space'
};

Expand Down Expand Up @@ -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));
}
Expand Down
6 changes: 4 additions & 2 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
17 changes: 7 additions & 10 deletions src/main/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) => {
Expand All @@ -93,17 +89,18 @@ 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();
}},
]}
]);

if (process.env.NODE_ENV === 'development') {
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;
Expand Down
8 changes: 8 additions & 0 deletions src/main/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
}
}

0 comments on commit e35d31c

Please sign in to comment.