mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-07 12:30:12 +02:00
668de93829
* Open settings with shortcut. Also add settings to menubar.
85 lines
2.0 KiB
TypeScript
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;
|