Screensharing rework
Split Linux screensharing audio tracks, Rework screensharing functionality and layout This will need some refactoring soon
This commit is contained in:
65
electron/desktop-settings.ts
Normal file
65
electron/desktop-settings.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
import { app } from 'electron';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
export interface DesktopSettings {
|
||||
hardwareAcceleration: boolean;
|
||||
}
|
||||
|
||||
export interface DesktopSettingsSnapshot extends DesktopSettings {
|
||||
runtimeHardwareAcceleration: boolean;
|
||||
restartRequired: boolean;
|
||||
}
|
||||
|
||||
const DEFAULT_DESKTOP_SETTINGS: DesktopSettings = {
|
||||
hardwareAcceleration: true
|
||||
};
|
||||
|
||||
export function getDesktopSettingsSnapshot(): DesktopSettingsSnapshot {
|
||||
const storedSettings = readDesktopSettings();
|
||||
const runtimeHardwareAcceleration = app.isHardwareAccelerationEnabled();
|
||||
|
||||
return {
|
||||
...storedSettings,
|
||||
runtimeHardwareAcceleration,
|
||||
restartRequired: storedSettings.hardwareAcceleration !== runtimeHardwareAcceleration
|
||||
};
|
||||
}
|
||||
|
||||
export function readDesktopSettings(): DesktopSettings {
|
||||
const filePath = getDesktopSettingsPath();
|
||||
|
||||
try {
|
||||
if (!fs.existsSync(filePath)) {
|
||||
return { ...DEFAULT_DESKTOP_SETTINGS };
|
||||
}
|
||||
|
||||
const raw = fs.readFileSync(filePath, 'utf8');
|
||||
const parsed = JSON.parse(raw) as Partial<DesktopSettings>;
|
||||
|
||||
return {
|
||||
hardwareAcceleration: typeof parsed.hardwareAcceleration === 'boolean'
|
||||
? parsed.hardwareAcceleration
|
||||
: DEFAULT_DESKTOP_SETTINGS.hardwareAcceleration
|
||||
};
|
||||
} catch {
|
||||
return { ...DEFAULT_DESKTOP_SETTINGS };
|
||||
}
|
||||
}
|
||||
|
||||
export function updateDesktopSettings(patch: Partial<DesktopSettings>): DesktopSettingsSnapshot {
|
||||
const nextSettings: DesktopSettings = {
|
||||
...readDesktopSettings(),
|
||||
...patch
|
||||
};
|
||||
const filePath = getDesktopSettingsPath();
|
||||
|
||||
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
||||
fs.writeFileSync(filePath, JSON.stringify(nextSettings, null, 2), 'utf8');
|
||||
|
||||
return getDesktopSettingsSnapshot();
|
||||
}
|
||||
|
||||
function getDesktopSettingsPath(): string {
|
||||
return path.join(app.getPath('userData'), 'desktop-settings.json');
|
||||
}
|
||||
Reference in New Issue
Block a user