From 8c58ccf5f2b5fd0105a236245e79c60236a650c8 Mon Sep 17 00:00:00 2001 From: Samuel Imolorhe Date: Sat, 16 Nov 2024 01:24:29 +0100 Subject: [PATCH] use settings store instead --- .../altair-electron-interop/src/settings.ts | 1 + packages/altair-electron/src/app/menu.ts | 11 +++++---- .../src/settings/main/store.ts | 6 +++++ packages/altair-electron/src/utils/startup.ts | 23 +++++-------------- 4 files changed, 20 insertions(+), 21 deletions(-) diff --git a/packages/altair-electron-interop/src/settings.ts b/packages/altair-electron-interop/src/settings.ts index f6590caa74..d2c74518cc 100644 --- a/packages/altair-electron-interop/src/settings.ts +++ b/packages/altair-electron-interop/src/settings.ts @@ -5,6 +5,7 @@ export interface SettingStore { proxy_host?: string; proxy_port?: string; }; + disable_hardware_acceleration: boolean; } export const settingsStoreFileName = 'desktop_settings'; diff --git a/packages/altair-electron/src/app/menu.ts b/packages/altair-electron/src/app/menu.ts index cf293cd7ba..278072237c 100644 --- a/packages/altair-electron/src/app/menu.ts +++ b/packages/altair-electron/src/app/menu.ts @@ -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 { @@ -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); }, }, diff --git a/packages/altair-electron/src/settings/main/store.ts b/packages/altair-electron/src/settings/main/store.ts index 6027e7b019..bec1f5c642 100644 --- a/packages/altair-electron/src/settings/main/store.ts +++ b/packages/altair-electron/src/settings/main/store.ts @@ -9,6 +9,12 @@ import { SettingsState } from 'altair-static'; export const store = new ElectronStore({ name: settingsStoreFileName, + defaults: { + settings: { + proxy_setting: 'none', + }, + disable_hardware_acceleration: false, + }, }); export const altairSettingsStore = new ElectronStore({ diff --git a/packages/altair-electron/src/utils/startup.ts b/packages/altair-electron/src/utils/startup.ts index 838b0b822c..d463491acd 100644 --- a/packages/altair-electron/src/utils/startup.ts +++ b/packages/altair-electron/src/utils/startup.ts @@ -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({ - 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(option: T) { - return startupOptionsStore.get(option); +export function getDisableHardwareAcceleration() { + return store.get('disable_hardware_acceleration'); } -export function setStartupOption( - 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); } }