From ba8534199eba569ad509abbbbc867eeedda2870f Mon Sep 17 00:00:00 2001 From: Renaud Heluin Date: Sun, 23 Jun 2024 01:03:07 +0200 Subject: [PATCH] feat: add sender message to console log in front to help debug --- electron-app/ecoindex-app/package.json | 2 +- electron-app/ecoindex-app/src/interface.d.ts | 1 + electron-app/ecoindex-app/src/main/main.ts | 13 ++++++++++--- electron-app/ecoindex-app/src/main/preload.ts | 4 ++++ electron-app/ecoindex-app/src/renderer/renderer.ts | 4 ++++ electron-app/ecoindex-app/src/shared/constants.js | 1 + 6 files changed, 21 insertions(+), 4 deletions(-) diff --git a/electron-app/ecoindex-app/package.json b/electron-app/ecoindex-app/package.json index f5cb8903..977a59f3 100644 --- a/electron-app/ecoindex-app/package.json +++ b/electron-app/ecoindex-app/package.json @@ -2,7 +2,7 @@ "name": "ecoindex-app", "productName": "Ecoindex mesures launcher", "version": "1.0.0", - "description": "An application to measure the ecoindex of a website with LightHouse & Ecoindex.", + "description": "An application to mesure the ecoindex of a website with LightHouse & Ecoindex.", "main": ".webpack/main", "scripts": { "start": "electron-forge start", diff --git a/electron-app/ecoindex-app/src/interface.d.ts b/electron-app/ecoindex-app/src/interface.d.ts index 14042162..84cdad27 100644 --- a/electron-app/ecoindex-app/src/interface.d.ts +++ b/electron-app/ecoindex-app/src/interface.d.ts @@ -7,6 +7,7 @@ export interface IVersionsAPI { export interface IElectronAPI { sendLogToFront: (callback) => string + sendHostInfoToFront: (callback) => object handleSetFolderOuput: () => Promise handleSelectFolder: () => Promise getWorkDir: (newDir: string) => Promise diff --git a/electron-app/ecoindex-app/src/main/main.ts b/electron-app/ecoindex-app/src/main/main.ts index 22871559..85548930 100644 --- a/electron-app/ecoindex-app/src/main/main.ts +++ b/electron-app/ecoindex-app/src/main/main.ts @@ -46,7 +46,7 @@ const createWindow = (): void => { mainWindow.loadURL(MAIN_WINDOW_WEBPACK_ENTRY) // Open the DevTools. - // mainWindow.webContents.openDevTools(); + mainWindow.webContents.openDevTools({ mode: 'detach' }) } // This method will be called when Electron has finished @@ -106,9 +106,11 @@ async function _echoReadable(event: IpcMainEvent, readable: any) { win.webContents.send(channels.ASYNCHRONOUS_LOG, chomp(line)) } } + +let mainWindow: BrowserWindow = null const _createWindow = (): void => { // Create the browser window. - const mainWindow = new BrowserWindow({ + mainWindow = new BrowserWindow({ width: 1000, height: 800, icon: '/assets/app-ico.png', @@ -121,12 +123,17 @@ const _createWindow = (): void => { mainWindow.loadURL(MAIN_WINDOW_WEBPACK_ENTRY) // Open the DevTools. - // mainWindow.webContents.openDevTools(); + // mainWindow.webContents.openDevTools({ mode: 'detach' }) +} + +const _sendMessageToFrontLog = (message: any) => { + mainWindow.webContents.send(channels.HOST_INFORMATIONS, message) } const _getHomeDir = async () => { fixPath() const _shellEnv = await shellEnv() + _sendMessageToFrontLog(_shellEnv) return _shellEnv.HOME } diff --git a/electron-app/ecoindex-app/src/main/preload.ts b/electron-app/ecoindex-app/src/main/preload.ts index be308652..9aaa279d 100644 --- a/electron-app/ecoindex-app/src/main/preload.ts +++ b/electron-app/ecoindex-app/src/main/preload.ts @@ -23,6 +23,10 @@ contextBridge.exposeInMainWorld('electronAPI', { ipcRenderer.on(channels.ASYNCHRONOUS_LOG, (_event, value) => callback(value), ), + sendHostInfoToFront: (callback: any) => + ipcRenderer.on(channels.HOST_INFORMATIONS, (_event, value) => + callback(value), + ), isLighthouseEcoindexPluginInstalled: () => ipcRenderer.invoke(channels.IS_LIGHTHOUSE_ECOINDEX_INSTALLED), isNodeInstalled: () => ipcRenderer.invoke(channels.IS_NODE_INSTALLED), diff --git a/electron-app/ecoindex-app/src/renderer/renderer.ts b/electron-app/ecoindex-app/src/renderer/renderer.ts index ed5a4761..e75a04f3 100644 --- a/electron-app/ecoindex-app/src/renderer/renderer.ts +++ b/electron-app/ecoindex-app/src/renderer/renderer.ts @@ -36,6 +36,10 @@ window.electronAPI.sendLogToFront((message: string) => { textArea.scrollTop = textArea.scrollHeight }) +window.electronAPI.sendHostInfoToFront((obj: object) => { + console.log(`Host informations:`, obj) +}) + console.log('👋 Welcome to Ecoindex mesures launcher!') console.log( '💡 More informations : https://cnumr.github.io/lighthouse-plugin-ecoindex/ and https://www.ecoindex.fr/', diff --git a/electron-app/ecoindex-app/src/shared/constants.js b/electron-app/ecoindex-app/src/shared/constants.js index 06c8fdb4..ada7a393 100644 --- a/electron-app/ecoindex-app/src/shared/constants.js +++ b/electron-app/ecoindex-app/src/shared/constants.js @@ -7,5 +7,6 @@ module.exports = { SELECT_FOLDER: 'dialog:select-folder', IS_LIGHTHOUSE_ECOINDEX_INSTALLED: 'is-lighthouse-ecoindex-installed', IS_NODE_INSTALLED: 'is-node-installed', + HOST_INFORMATIONS: 'host-informations', }, }