1
0
Fork 0
mirror of https://gitlab.com/futo-org/fcast.git synced 2025-06-24 21:25:23 +00:00
fcast/receivers/common/web/main/Preload.ts

71 lines
3 KiB
TypeScript
Raw Normal View History

2024-12-09 00:56:55 -06:00
/* eslint-disable @typescript-eslint/ban-ts-comment */
/* eslint-disable @typescript-eslint/no-explicit-any */
import { Opcode } from 'common/Packets';
2025-05-01 10:37:21 -05:00
import { Logger, LoggerType } from 'common/Logger';
const logger = new Logger('MainWindow', LoggerType.FRONTEND);
// Cannot directly pass the object to the renderer for some reason...
const loggerInterface = {
trace: (message?: any, ...optionalParams: any[]) => { logger.trace(message, ...optionalParams); },
debug: (message?: any, ...optionalParams: any[]) => { logger.debug(message, ...optionalParams); },
info: (message?: any, ...optionalParams: any[]) => { logger.info(message, ...optionalParams); },
warn: (message?: any, ...optionalParams: any[]) => { logger.warn(message, ...optionalParams); },
error: (message?: any, ...optionalParams: any[]) => { logger.error(message, ...optionalParams); },
fatal: (message?: any, ...optionalParams: any[]) => { logger.fatal(message, ...optionalParams); },
};
2024-12-09 00:56:55 -06:00
declare global {
interface Window {
electronAPI: any;
webOS: any;
webOSDev: any;
targetAPI: any;
}
}
2024-12-18 20:43:47 -06:00
let preloadData: Record<string, any> = {};
2024-12-09 00:56:55 -06:00
// @ts-ignore
if (TARGET === 'electron') {
// @ts-ignore
const electronAPI = __non_webpack_require__('electron');
electronAPI.ipcRenderer.on("device-info", (_event, value: any) => {
preloadData.deviceInfo = value;
2024-12-09 00:56:55 -06:00
})
electronAPI.contextBridge.exposeInMainWorld('targetAPI', {
onDeviceInfo: (callback: any) => electronAPI.ipcRenderer.on('device-info', callback),
getDeviceInfo: () => preloadData.deviceInfo,
getSessions: () => electronAPI.ipcRenderer.invoke('get-sessions'),
onConnect: (callback: any) => electronAPI.ipcRenderer.on('connect', callback),
onDisconnect: (callback: any) => electronAPI.ipcRenderer.on('disconnect', callback),
2025-05-01 10:37:21 -05:00
logger: loggerInterface,
2024-12-09 00:56:55 -06:00
});
// @ts-ignore
} else if (TARGET === 'webOS' || TARGET === 'tizenOS') {
preloadData = {
2025-05-01 10:37:21 -05:00
onDeviceInfoCb: () => { logger.error('Main: Callback not set while fetching device info'); },
getSessionsCb: () => { logger.error('Main: Callback not set while calling getSessions'); },
2025-05-01 10:37:21 -05:00
onConnectCb: (_, value: any) => { logger.error('Main: Callback not set while calling onConnect'); },
onDisconnectCb: (_, value: any) => { logger.error('Main: Callback not set while calling onDisconnect'); },
};
window.targetAPI = {
onDeviceInfo: (callback: () => void) => preloadData.onDeviceInfoCb = callback,
getDeviceInfo: () => preloadData.deviceInfo,
getSessions: (callback: () => any) => preloadData.getSessionsCb = callback,
onConnect: (callback: (_, value: any) => void) => preloadData.onConnectCb = callback,
onDisconnect: (callback: (_, value: any) => void) => preloadData.onDisconnectCb = callback,
2025-05-01 10:37:21 -05:00
logger: loggerInterface,
};
2024-12-09 00:56:55 -06:00
} else {
// @ts-ignore
2025-05-01 10:37:21 -05:00
logger.warn(`Attempting to run FCast player on unsupported target: ${TARGET}`);
2024-12-09 00:56:55 -06:00
}
2024-12-18 20:43:47 -06:00
export {
preloadData
};