Skip to content

Commit

Permalink
use settings store instead
Browse files Browse the repository at this point in the history
  • Loading branch information
imolorhe committed Nov 16, 2024
1 parent 78eb35d commit 8c58ccf
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 21 deletions.
1 change: 1 addition & 0 deletions packages/altair-electron-interop/src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface SettingStore {
proxy_host?: string;
proxy_port?: string;
};
disable_hardware_acceleration: boolean;
}

export const settingsStoreFileName = 'desktop_settings';
Expand Down
11 changes: 7 additions & 4 deletions packages/altair-electron/src/app/menu.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { app, Menu, MenuItemConstructorOptions, shell } from 'electron';
import { ActionManager } from './actions';
import { getStartupOption, setStartupOption } from '../utils/startup';
import {
getDisableHardwareAcceleration,
setDisableHardwareAcceleration,
} from '../utils/startup';
import { restartApp } from '../utils';

export class MenuManager {
Expand Down Expand Up @@ -106,18 +109,18 @@ export class MenuManager {
submenu: [
{ role: 'minimize' },
{ role: 'close' },
getStartupOption('DISABLE_HARDWARE_ACCELERATION')
getDisableHardwareAcceleration()
? {
label: 'Enable hardware acceleration (beta)',
click: () => {
setStartupOption('DISABLE_HARDWARE_ACCELERATION', false);
setDisableHardwareAcceleration(false);
restartApp(app);
},
}
: {
label: 'Disable hardware acceleration (beta)',
click: () => {
setStartupOption('DISABLE_HARDWARE_ACCELERATION', true);
setDisableHardwareAcceleration(true);
restartApp(app);
},
},
Expand Down
6 changes: 6 additions & 0 deletions packages/altair-electron/src/settings/main/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ import { SettingsState } from 'altair-static';

export const store = new ElectronStore<SettingStore>({
name: settingsStoreFileName,
defaults: {
settings: {
proxy_setting: 'none',
},
disable_hardware_acceleration: false,
},
});

export const altairSettingsStore = new ElectronStore<SettingsState>({
Expand Down
23 changes: 6 additions & 17 deletions packages/altair-electron/src/utils/startup.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,21 @@
import { App } from 'electron';
import { PersistentStore } from '../store';
import { store } from '../settings/main/store';

interface StartupOptionsStore {
DISABLE_HARDWARE_ACCELERATION: boolean;
}
const startupOptionsStore = new PersistentStore<StartupOptionsStore>({
defaults: {
DISABLE_HARDWARE_ACCELERATION: false,
},
});
function disableHardwareAcceleration(app: App) {
app.commandLine.appendSwitch('ignore-gpu-blacklist');
app.commandLine.appendSwitch('disable-gpu');
app.commandLine.appendSwitch('disable-gpu-compositing');
app.disableHardwareAcceleration();
}
export function getStartupOption<T extends keyof StartupOptionsStore>(option: T) {
return startupOptionsStore.get(option);
export function getDisableHardwareAcceleration() {
return store.get('disable_hardware_acceleration');
}
export function setStartupOption<T extends keyof StartupOptionsStore>(
option: T,
value: StartupOptionsStore[T]
) {
startupOptionsStore.set(option, value);
export function setDisableHardwareAcceleration(value: boolean) {
store.set('disable_hardware_acceleration', value);
}

export function configureAppOnStartup(app: App) {
if (startupOptionsStore.get('DISABLE_HARDWARE_ACCELERATION')) {
if (store.get('disable_hardware_acceleration')) {
disableHardwareAcceleration(app);
}
}

0 comments on commit 8c58ccf

Please sign in to comment.