1
0
Fork 0
mirror of https://gitlab.com/futo-org/fcast.git synced 2025-08-07 09:42:50 +00:00
fcast/receivers/common/web/main/Preload.ts

69 lines
1.9 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-require-imports */
/* eslint-disable @typescript-eslint/no-explicit-any */
declare global {
interface Window {
electronAPI: any;
webOS: any;
webOSDev: any;
targetAPI: any;
}
}
let deviceInfo: 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) => {
deviceInfo = value;
})
electronAPI.contextBridge.exposeInMainWorld('targetAPI', {
onDeviceInfo: (callback: any) => electronAPI.ipcRenderer.on("device-info", callback),
getDeviceInfo: () => deviceInfo,
});
// @ts-ignore
} else if (TARGET === 'webOS') {
require('lib/webOSTVjs-1.2.10/webOSTV.js');
require('lib/webOSTVjs-1.2.10/webOSTV-dev.js');
const serviceId = 'com.futo.fcast.receiver.service';
2024-12-17 22:59:41 -06:00
let onDeviceInfoCb = () => { console.log('Main: Callback not set while fetching device info'); };
2024-12-09 00:56:55 -06:00
const getDeviceInfoService = window.webOS.service.request(`luna://${serviceId}/`, {
method:"getDeviceInfo",
parameters: {},
onSuccess: (message: any) => {
console.log(`Main: getDeviceInfo ${JSON.stringify(message)}`);
deviceInfo = message.value;
onDeviceInfoCb();
},
onFailure: (message: any) => {
console.error(`Main: getDeviceInfo ${JSON.stringify(message)}`);
},
// onComplete: (message) => {},
});
window.targetAPI = {
2024-12-17 22:59:41 -06:00
onDeviceInfo: (callback: () => void) => onDeviceInfoCb = callback,
2024-12-09 00:56:55 -06:00
getDeviceInfo: () => deviceInfo,
};
2024-12-18 20:43:47 -06:00
preloadData = {
getDeviceInfoService: getDeviceInfoService,
};
2024-12-09 00:56:55 -06:00
} else {
// @ts-ignore
console.log(`Attempting to run FCast player on unsupported target: ${TARGET}`);
}
2024-12-18 20:43:47 -06:00
export {
preloadData
};