feat: plugins v1.7

This commit is contained in:
2026-04-29 15:24:56 +02:00
parent eabbc08896
commit d261bac0ed
45 changed files with 5621 additions and 867 deletions

View File

@@ -4,11 +4,20 @@ import * as path from 'path';
export type AutoUpdateMode = 'auto' | 'off' | 'version';
export interface LocalApiSettings {
enabled: boolean;
port: number;
exposeOnLan: boolean;
scalarEnabled: boolean;
allowedSignalingServers: string[];
}
export interface DesktopSettings {
autoUpdateMode: AutoUpdateMode;
autoStart: boolean;
closeToTray: boolean;
hardwareAcceleration: boolean;
localApi: LocalApiSettings;
manifestUrls: string[];
preferredVersion: string | null;
vaapiVideoEncode: boolean;
@@ -19,11 +28,20 @@ export interface DesktopSettingsSnapshot extends DesktopSettings {
restartRequired: boolean;
}
const DEFAULT_LOCAL_API_SETTINGS: LocalApiSettings = {
enabled: false,
port: 17878,
exposeOnLan: false,
scalarEnabled: false,
allowedSignalingServers: []
};
const DEFAULT_DESKTOP_SETTINGS: DesktopSettings = {
autoUpdateMode: 'auto',
autoStart: true,
closeToTray: true,
hardwareAcceleration: true,
localApi: { ...DEFAULT_LOCAL_API_SETTINGS },
manifestUrls: [],
preferredVersion: null,
vaapiVideoEncode: false
@@ -61,6 +79,60 @@ function normalizeManifestUrls(value: unknown): string[] {
return manifestUrls;
}
function normalizePort(value: unknown, fallback: number): number {
if (typeof value !== 'number' || !Number.isFinite(value)) {
return fallback;
}
const port = Math.floor(value);
if (port < 1 || port > 65535) {
return fallback;
}
return port;
}
function normalizeAllowedSignalingServers(value: unknown): string[] {
if (!Array.isArray(value)) {
return [];
}
const urls: string[] = [];
for (const entry of value) {
if (typeof entry !== 'string') {
continue;
}
const trimmed = entry.trim().replace(/\/+$/u, '');
if (!trimmed || urls.includes(trimmed)) {
continue;
}
if (!/^https?:\/\//iu.test(trimmed)) {
continue;
}
urls.push(trimmed);
}
return urls;
}
function normalizeLocalApiSettings(value: unknown): LocalApiSettings {
const source = (value && typeof value === 'object') ? value as Partial<LocalApiSettings> : {};
return {
enabled: typeof source.enabled === 'boolean' ? source.enabled : DEFAULT_LOCAL_API_SETTINGS.enabled,
port: normalizePort(source.port, DEFAULT_LOCAL_API_SETTINGS.port),
exposeOnLan: typeof source.exposeOnLan === 'boolean' ? source.exposeOnLan : DEFAULT_LOCAL_API_SETTINGS.exposeOnLan,
scalarEnabled: typeof source.scalarEnabled === 'boolean' ? source.scalarEnabled : DEFAULT_LOCAL_API_SETTINGS.scalarEnabled,
allowedSignalingServers: normalizeAllowedSignalingServers(source.allowedSignalingServers)
};
}
export function getDesktopSettingsSnapshot(): DesktopSettingsSnapshot {
const storedSettings = readDesktopSettings();
const runtimeHardwareAcceleration = app.isHardwareAccelerationEnabled();
@@ -97,6 +169,7 @@ export function readDesktopSettings(): DesktopSettings {
hardwareAcceleration: typeof parsed.hardwareAcceleration === 'boolean'
? parsed.hardwareAcceleration
: DEFAULT_DESKTOP_SETTINGS.hardwareAcceleration,
localApi: normalizeLocalApiSettings(parsed.localApi),
manifestUrls: normalizeManifestUrls(parsed.manifestUrls),
preferredVersion: normalizePreferredVersion(parsed.preferredVersion)
};
@@ -106,9 +179,13 @@ export function readDesktopSettings(): DesktopSettings {
}
export function updateDesktopSettings(patch: Partial<DesktopSettings>): DesktopSettingsSnapshot {
const previousSettings = readDesktopSettings();
const mergedSettings = {
...readDesktopSettings(),
...patch
...previousSettings,
...patch,
localApi: patch.localApi
? { ...previousSettings.localApi, ...patch.localApi }
: previousSettings.localApi
};
const nextSettings: DesktopSettings = {
autoUpdateMode: normalizeAutoUpdateMode(mergedSettings.autoUpdateMode),
@@ -121,6 +198,7 @@ export function updateDesktopSettings(patch: Partial<DesktopSettings>): DesktopS
hardwareAcceleration: typeof mergedSettings.hardwareAcceleration === 'boolean'
? mergedSettings.hardwareAcceleration
: DEFAULT_DESKTOP_SETTINGS.hardwareAcceleration,
localApi: normalizeLocalApiSettings(mergedSettings.localApi),
manifestUrls: normalizeManifestUrls(mergedSettings.manifestUrls),
preferredVersion: normalizePreferredVersion(mergedSettings.preferredVersion),
vaapiVideoEncode: typeof mergedSettings.vaapiVideoEncode === 'boolean'