Split Linux screensharing audio tracks, Rework screensharing functionality and layout This will need some refactoring soon
66 lines
1.8 KiB
TypeScript
66 lines
1.8 KiB
TypeScript
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');
|
|
}
|