2024-12-09 00:56:55 -06:00
|
|
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
|
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
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');
|
|
|
|
|
2025-01-06 20:35:57 -06:00
|
|
|
electronAPI.ipcRenderer.on("device-info", (_event, value: any) => {
|
2025-01-07 22:47:46 -06:00
|
|
|
preloadData.deviceInfo = value;
|
2024-12-09 00:56:55 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
electronAPI.contextBridge.exposeInMainWorld('targetAPI', {
|
2025-04-25 14:04:59 -05:00
|
|
|
onDeviceInfo: (callback: any) => electronAPI.ipcRenderer.on('device-info', callback),
|
2025-01-07 22:47:46 -06:00
|
|
|
getDeviceInfo: () => preloadData.deviceInfo,
|
2025-04-29 13:03:10 -05:00
|
|
|
getSessions: () => electronAPI.ipcRenderer.invoke('get-sessions'),
|
2025-04-25 14:04:59 -05:00
|
|
|
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
|
2025-02-13 11:21:49 -06:00
|
|
|
} 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'); },
|
2025-05-01 13:28:56 -05:00
|
|
|
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'); },
|
2025-02-13 11:21:49 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
window.targetAPI = {
|
|
|
|
onDeviceInfo: (callback: () => void) => preloadData.onDeviceInfoCb = callback,
|
2025-05-01 13:28:56 -05:00
|
|
|
getDeviceInfo: () => preloadData.deviceInfo,
|
2025-05-09 10:44:26 -05:00
|
|
|
getSessions: (callback?: () => Promise<[any]>) => {
|
|
|
|
if (callback) {
|
|
|
|
preloadData.getSessionsCb = callback;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return preloadData.getSessionsCb();
|
|
|
|
}
|
|
|
|
},
|
2025-02-13 11:21:49 -06:00
|
|
|
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,
|
2025-02-13 11:21:49 -06:00
|
|
|
};
|
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
|
|
|
|
};
|