2026-06-03 02:42:00 +03:00
|
|
|
import { hasDesktopInvoke, invokeDesktop, isDesktopShell } from '@/lib/desktop';
|
2026-04-20 15:41:15 +03:00
|
|
|
|
|
|
|
|
type InvokeArgs = Record<string, unknown>;
|
|
|
|
|
|
|
|
|
|
export const invokeDesktopCommand = async <TValue = unknown>(
|
|
|
|
|
command: string,
|
|
|
|
|
args?: InvokeArgs,
|
|
|
|
|
): Promise<TValue> => {
|
2026-06-03 02:42:00 +03:00
|
|
|
if (!hasDesktopInvoke()) {
|
2026-04-20 15:41:15 +03:00
|
|
|
throw new Error('Desktop runtime is not available');
|
|
|
|
|
}
|
2026-06-03 02:42:00 +03:00
|
|
|
return invokeDesktop<TValue>(command, args) as Promise<TValue>;
|
2026-04-20 15:41:15 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const startDesktopWindowDrag = async (): Promise<void> => {
|
|
|
|
|
if (!isDesktopShell()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
2026-06-03 02:42:00 +03:00
|
|
|
await invokeDesktopCommand('desktop_start_window_drag');
|
2026-04-20 15:41:15 +03:00
|
|
|
} catch {
|
|
|
|
|
// ignore
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const setDesktopWindowTitle = async (title: string): Promise<void> => {
|
|
|
|
|
if (!isDesktopShell()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
await invokeDesktopCommand('desktop_set_window_title', { title });
|
|
|
|
|
} catch {
|
|
|
|
|
// ignore
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const setDesktopWindowTheme = async (
|
|
|
|
|
themeMode?: string,
|
|
|
|
|
themeVariant?: string,
|
|
|
|
|
): Promise<void> => {
|
|
|
|
|
if (!isDesktopShell()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
await invokeDesktopCommand('desktop_set_window_theme', { themeMode, themeVariant });
|
|
|
|
|
} catch {
|
|
|
|
|
// ignore
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const getDesktopAppVersion = async (): Promise<string | null> => {
|
|
|
|
|
if (!isDesktopShell()) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const version = await invokeDesktopCommand('desktop_get_app_version');
|
|
|
|
|
return typeof version === 'string' && version.trim().length > 0 ? version : null;
|
|
|
|
|
} catch {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
};
|