From 1e5b887be9978b5cd1f4c1b90462751e1679fd3c Mon Sep 17 00:00:00 2001 From: ThaUnknown <6506529+ThaUnknown@users.noreply.github.com> Date: Fri, 10 Nov 2023 23:25:53 +0100 Subject: [PATCH] feat: allow specifying angle backend --- src/common/util.js | 3 ++- src/main/store.js | 30 ++++++++++++++++++++++++++++++ src/main/util.js | 10 +++++++++- src/renderer/views/Settings.svelte | 19 +++++++++++++++++++ 4 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 src/main/store.js diff --git a/src/common/util.js b/src/common/util.js index e8d2f292..1aeb3a34 100644 --- a/src/common/util.js +++ b/src/common/util.js @@ -24,7 +24,8 @@ export const defaults = { cards: 'small', expandingSidebar: true, torrentPath: undefined, - font: undefined + font: undefined, + angle: 'default' } export const subtitleExtensions = ['srt', 'vtt', 'ass', 'ssa', 'sub', 'txt'] diff --git a/src/main/store.js b/src/main/store.js new file mode 100644 index 00000000..306f0966 --- /dev/null +++ b/src/main/store.js @@ -0,0 +1,30 @@ +import { app } from 'electron' +import { join } from 'node:path' +import { writeFileSync, readFileSync } from 'node:fs' + +class Store { + constructor (configName, defaults) { + this.path = join(app.getPath('userData'), configName + '.json') + + this.data = parseDataFile(this.path, defaults) + } + + get (key) { + return this.data[key] + } + + set (key, val) { + this.data[key] = val + writeFileSync(this.path, JSON.stringify(this.data)) + } +} + +function parseDataFile (filePath, defaults) { + try { + return { ...defaults, ...JSON.parse(readFileSync(filePath).toString()) } + } catch (error) { + return defaults + } +} + +export default new Store('settings', { angle: 'default' }) diff --git a/src/main/util.js b/src/main/util.js index fb4bae9d..f5536365 100644 --- a/src/main/util.js +++ b/src/main/util.js @@ -1,4 +1,5 @@ import { app, ipcMain, shell, dialog } from 'electron' +import store from './store.js' export const development = process.env.NODE_ENV?.trim() === 'development' @@ -12,14 +13,17 @@ const flags = [ ['enable-hardware-overlays', 'single-fullscreen,single-on-top,underlay'], ['enable-features', 'PlatformEncryptedDolbyVision,EnableDrDc,CanvasOopRasterization,ThrottleDisplayNoneAndVisibilityHiddenCrossOriginIframes,UseSkiaRenderer,WebAssemblyLazyCompilation'], ['force_high_performance_gpu'], - ['disable-features', 'Vulkan'], + ['disable-features', 'Vulkan,CalculateNativeWinOcclusion'], ['disable-color-correct-rendering'], + ['autoplay-policy', 'no-user-gesture-required'], ['disable-notifications'], ['disable-logging'], ['disable-permissions-api'], ['no-sandbox'], ['no-zygote'], ['force-color-profile', 'srgb'] ] for (const [flag, value] of flags) { app.commandLine.appendSwitch(flag, value) } +app.commandLine.appendSwitch('use-angle', store.get('angle') || 'default') + if (!app.requestSingleInstanceLock()) app.quit() ipcMain.on('open', (event, url) => { @@ -33,6 +37,10 @@ ipcMain.on('doh', (event, dns) => { }) }) +ipcMain.on('angle', (e, data) => { + store.set('angle', data) +}) + ipcMain.on('close', () => { app.quit() }) diff --git a/src/renderer/views/Settings.svelte b/src/renderer/views/Settings.svelte index c18c9ff6..d056d138 100644 --- a/src/renderer/views/Settings.svelte +++ b/src/renderer/views/Settings.svelte @@ -43,6 +43,9 @@ let version = '1.0.0' window.IPC.on('version', data => (version = data)) window.IPC.emit('version') + function updateAngle () { + window.IPC.emit('angle', set.angle) + } let wasUpdated = false window.IPC.on('update-available', () => { @@ -534,6 +537,22 @@