1
0
Fork 0
mirror of https://gitlab.com/futo-org/fcast.git synced 2025-08-04 08:17:01 +00:00

Receivers: Added unified logger module

This commit is contained in:
Michael Hollister 2025-05-01 10:37:21 -05:00
parent 7f9d7939bc
commit b24b3f0c55
17 changed files with 351 additions and 117 deletions

View file

@ -1,6 +1,18 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
/* eslint-disable @typescript-eslint/no-explicit-any */
import { Opcode } from 'common/Packets';
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); },
};
declare global {
interface Window {
@ -32,15 +44,16 @@ if (TARGET === 'electron') {
onDisconnect: (callback: any) => electronAPI.ipcRenderer.on('disconnect', callback),
onPing: (callback: any) => electronAPI.ipcRenderer.on('ping', callback),
onPong: (callback: any) => electronAPI.ipcRenderer.on('pong', callback),
logger: loggerInterface,
});
// @ts-ignore
} else if (TARGET === 'webOS' || TARGET === 'tizenOS') {
preloadData = {
onDeviceInfoCb: () => { console.log('Main: Callback not set while fetching device info'); },
onConnectCb: (_, value: any) => { console.log('Main: Callback not set while calling onConnect'); },
onDisconnectCb: (_, value: any) => { console.log('Main: Callback not set while calling onDisconnect'); },
onPingCb: (_, value: any) => { console.log('Main: Callback not set while calling onPing'); },
onDeviceInfoCb: () => { logger.error('Main: Callback not set while fetching device info'); },
onConnectCb: (_, value: any) => { logger.error('Main: Callback not set while calling onConnect'); },
onDisconnectCb: (_, value: any) => { logger.error('Main: Callback not set while calling onDisconnect'); },
onPingCb: (_, value: any) => { logger.error('Main: Callback not set while calling onPing'); },
};
window.targetAPI = {
@ -49,10 +62,11 @@ if (TARGET === 'electron') {
onDisconnect: (callback: (_, value: any) => void) => preloadData.onDisconnectCb = callback,
onPing: (callback: (_, value: any) => void) => preloadData.onPingCb = callback,
getDeviceInfo: () => preloadData.deviceInfo,
logger: loggerInterface,
};
} else {
// @ts-ignore
console.log(`Attempting to run FCast player on unsupported target: ${TARGET}`);
logger.warn(`Attempting to run FCast player on unsupported target: ${TARGET}`);
}
export {

View file

@ -12,6 +12,7 @@ let renderedAddresses = null;
let qrCodeUrl = null;
let qrWidth = null;
const logger = window.targetAPI.logger;
window.addEventListener('resize', (event) => calculateQRCodeWidth());
connectionMonitor.setUiUpdateCallbacks({
@ -37,13 +38,13 @@ connectionMonitor.setUiUpdateCallbacks({
window.targetAPI.onDeviceInfo(renderIPsAndQRCode);
if(window.targetAPI.getDeviceInfo()) {
console.log('device info already present');
logger.info('device info already present');
renderIPsAndQRCode();
}
function renderIPsAndQRCode() {
const value = window.targetAPI.getDeviceInfo();
console.log(`Network Interface Info: ${JSON.stringify(value)}`);
logger.info(`Network Interface Info: ${JSON.stringify(value)}`);
renderIPs(value.interfaces);
const addresses = [];
@ -91,7 +92,7 @@ function renderIPsAndQRCode() {
let base64 = btoa(json);
base64 = base64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
qrCodeUrl = `fcast://r/${base64}`;
console.log('QR Code:', {json, qrCodeUrl, base64});
logger.info('QR Code:', {json, qrCodeUrl, base64});
calculateQRCodeWidth();
if (!renderedConnectionInfo) {
@ -188,11 +189,11 @@ function renderQRCode(url: string) {
},
(err) => {
if (err) {
console.error(`Error rendering QR Code: ${err}`);
logger.error(`Error rendering QR Code: ${err}`);
toast(`Error rendering QR Code: ${err}`, ToastIcon.ERROR);
}
else {
console.log(`Rendered QR Code`);
logger.info(`Rendered QR Code`);
}
});