Files
feishin/src/preload/utils.ts
T
Martín González Gómez 668de93829 Open settings with shortcut (#1655)
* Open settings with shortcut. Also add settings to menubar.
2026-02-07 15:19:05 -08:00

85 lines
2.0 KiB
TypeScript

import { ipcRenderer, IpcRendererEvent, webFrame } from 'electron';
import { disableAutoUpdates, isLinux, isMacOS, isWindows } from '../main/utils';
const openItem = async (path: string) => {
return ipcRenderer.invoke('open-item', path);
};
const openApplicationDirectory = async () => {
return ipcRenderer.invoke('open-application-directory');
};
const playerErrorListener = (cb: (event: IpcRendererEvent, data: { code: number }) => void) => {
ipcRenderer.on('player-error-listener', cb);
};
const mainMessageListener = (
cb: (
event: IpcRendererEvent,
data: { message: string; type: 'error' | 'info' | 'success' | 'warning' },
) => void,
) => {
ipcRenderer.on('toast-from-main', cb);
};
const logger = (
cb: (
event: IpcRendererEvent,
data: {
message: string;
type: 'debug' | 'error' | 'info' | 'verbose' | 'warning';
},
) => void,
) => {
ipcRenderer.send('logger', cb);
};
const download = (url: string) => {
ipcRenderer.send('download-url', url);
};
const checkForUpdates = (): Promise<{ updateAvailable: boolean; version?: string }> => {
return ipcRenderer.invoke('app-check-for-updates');
};
const forceGarbageCollection = (): boolean => {
try {
if (typeof global.gc === 'function') {
global.gc();
webFrame.clearCache();
return true;
}
if (typeof window.gc === 'function') {
window.gc();
webFrame.clearCache();
return true;
}
return false;
} catch {
return false;
}
};
const rendererOpenSettings = (cb: (event: IpcRendererEvent) => void) => {
ipcRenderer.on('renderer-open-settings', cb);
};
export const utils = {
checkForUpdates,
disableAutoUpdates,
download,
forceGarbageCollection,
isLinux,
isMacOS,
isWindows,
logger,
mainMessageListener,
openApplicationDirectory,
openItem,
playerErrorListener,
rendererOpenSettings,
};
export type Utils = typeof utils;