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 */
|
2025-01-06 20:35:57 -06:00
|
|
|
import { toast, ToastIcon } from '../components/Toast';
|
2024-12-09 00:56:55 -06:00
|
|
|
|
|
|
|
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');
|
|
|
|
|
2025-01-06 20:35:57 -06:00
|
|
|
// Since event is sent async during window startup, could fire off before or after renderer.js is loaded
|
|
|
|
electronAPI.ipcRenderer.on('startup-storage-clear', () => {
|
|
|
|
localStorage.clear();
|
|
|
|
});
|
|
|
|
|
|
|
|
electronAPI.ipcRenderer.on("device-info", (_event, value: any) => {
|
2024-12-09 00:56:55 -06:00
|
|
|
deviceInfo = value;
|
|
|
|
})
|
|
|
|
|
|
|
|
electronAPI.contextBridge.exposeInMainWorld('targetAPI', {
|
2025-01-06 20:35:57 -06:00
|
|
|
onStartupStorageClear: (callback: any) => electronAPI.ipcRenderer.on('startup-storage-clear', callback),
|
2024-12-09 00:56:55 -06:00
|
|
|
onDeviceInfo: (callback: any) => electronAPI.ipcRenderer.on("device-info", callback),
|
2025-01-06 20:35:57 -06:00
|
|
|
onConnect: (callback: any) => electronAPI.ipcRenderer.on("connect", callback),
|
|
|
|
onDisconnect: (callback: any) => electronAPI.ipcRenderer.on("disconnect", callback),
|
2024-12-09 00:56:55 -06:00
|
|
|
getDeviceInfo: () => deviceInfo,
|
|
|
|
});
|
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
} else if (TARGET === 'webOS') {
|
2025-01-06 20:35:57 -06:00
|
|
|
try {
|
|
|
|
require('lib/webOSTVjs-1.2.10/webOSTV.js');
|
|
|
|
require('lib/webOSTVjs-1.2.10/webOSTV-dev.js');
|
|
|
|
const serviceId = 'com.futo.fcast.receiver.service';
|
|
|
|
let onStartupStorageClearCb = () => { localStorage.clear(); };
|
|
|
|
let onDeviceInfoCb = () => { console.log('Main: Callback not set while fetching device info'); };
|
|
|
|
let onConnectCb = (_, value: any) => { console.log('Main: Callback not set while calling onConnect'); };
|
|
|
|
let onDisconnectCb = (_, value: any) => { console.log('Main: Callback not set while calling onDisconnect'); };
|
2024-12-17 22:59:41 -06:00
|
|
|
|
2025-01-06 20:35:57 -06:00
|
|
|
const getDeviceInfoService = window.webOS.service.request(`luna://${serviceId}/`, {
|
|
|
|
method:"getDeviceInfo",
|
|
|
|
parameters: {},
|
|
|
|
onSuccess: (message: any) => {
|
|
|
|
console.log(`Main: getDeviceInfo ${JSON.stringify(message)}`);
|
2024-12-09 00:56:55 -06:00
|
|
|
|
2025-01-06 20:35:57 -06:00
|
|
|
deviceInfo = message.value;
|
|
|
|
onDeviceInfoCb();
|
|
|
|
},
|
|
|
|
onFailure: (message: any) => {
|
|
|
|
console.error(`Main: getDeviceInfo ${JSON.stringify(message)}`);
|
|
|
|
toast(`Main: getDeviceInfo ${JSON.stringify(message)}`, ToastIcon.ERROR);
|
|
|
|
},
|
|
|
|
// onComplete: (message) => {},
|
|
|
|
});
|
2024-12-09 00:56:55 -06:00
|
|
|
|
2025-01-06 20:35:57 -06:00
|
|
|
window.targetAPI = {
|
|
|
|
onStartupStorageClear: (callback: () => void) => onStartupStorageClearCb = callback,
|
|
|
|
onDeviceInfo: (callback: () => void) => onDeviceInfoCb = callback,
|
|
|
|
onConnect: (callback: () => void) => onConnectCb = callback,
|
|
|
|
onDisconnect: (callback: () => void) => onDisconnectCb = callback,
|
|
|
|
getDeviceInfo: () => deviceInfo,
|
|
|
|
};
|
2024-12-09 00:56:55 -06:00
|
|
|
|
2025-01-06 20:35:57 -06:00
|
|
|
preloadData = {
|
|
|
|
getDeviceInfoService: getDeviceInfoService,
|
|
|
|
onStartupStorageClearCb: onStartupStorageClearCb,
|
|
|
|
onConnectCb: onConnectCb,
|
|
|
|
onDisconnectCb: onDisconnectCb,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
console.error(`Main: preload ${JSON.stringify(err)}`);
|
|
|
|
toast(`Main: preload ${JSON.stringify(err)}`, ToastIcon.ERROR);
|
|
|
|
}
|
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
|
|
|
|
};
|