feat(desktop): add keep-awake setting

This commit is contained in:
Bohdan Triapitsyn
2026-07-01 19:07:20 +03:00
parent 4b1e05160f
commit bc4a7d358a
16 changed files with 236 additions and 2 deletions
+41 -1
View File
@@ -51,6 +51,7 @@ export type DesktopSettings = {
// Optional absolute path to `opencode` binary.
opencodeBinary?: string;
desktopLanAccessEnabled?: boolean;
desktopKeepAwakeEnabled?: boolean;
desktopUiPassword?: string;
projects?: ProjectEntry[];
activeProjectId?: string;
@@ -235,6 +236,12 @@ type LaunchAtLoginStatus = {
enabled: boolean;
};
type KeepAwakeStatus = {
supported: boolean;
enabled: boolean;
active: boolean;
};
export const getDesktopLaunchAtLogin = async (): Promise<LaunchAtLoginStatus | null> => {
if (!canUseElectronDesktopIPC() || !isDesktopLocalOriginActive()) {
return null;
@@ -269,6 +276,40 @@ export const setDesktopLaunchAtLogin = async (enabled: boolean): Promise<LaunchA
}
};
export const getDesktopKeepAwake = async (): Promise<KeepAwakeStatus | null> => {
if (!canUseElectronDesktopIPC() || !isDesktopLocalOriginActive()) {
return null;
}
try {
const result = await invokeDesktop<KeepAwakeStatus>('desktop_get_keep_awake');
if (!result || typeof result.supported !== 'boolean' || typeof result.enabled !== 'boolean' || typeof result.active !== 'boolean') {
return null;
}
return result;
} catch (error) {
console.warn('Failed to get keep awake status', error);
return null;
}
};
export const setDesktopKeepAwake = async (enabled: boolean): Promise<KeepAwakeStatus | null> => {
if (!canUseElectronDesktopIPC() || !isDesktopLocalOriginActive()) {
return null;
}
try {
const result = await invokeDesktop<KeepAwakeStatus>('desktop_set_keep_awake', { enabled });
if (!result || typeof result.supported !== 'boolean' || typeof result.enabled !== 'boolean' || typeof result.active !== 'boolean') {
return null;
}
return result;
} catch (error) {
console.warn('Failed to set keep awake status', error);
return null;
}
};
const normalizeOrigin = (raw: string): string | null => {
const trimmed = raw.trim();
if (!trimmed) return null;
@@ -819,4 +860,3 @@ export const fetchDesktopInstalledApps = async (
return { apps: [], success: false, hasCache: false, isCacheStale: false };
}
};