Skip to content

Commit

Permalink
feat: add sender message to console log in front to help debug
Browse files Browse the repository at this point in the history
  • Loading branch information
hrenaud committed Jun 22, 2024
1 parent 32ea70d commit ba85341
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion electron-app/ecoindex-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions electron-app/ecoindex-app/src/interface.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface IVersionsAPI {

export interface IElectronAPI {
sendLogToFront: (callback) => string
sendHostInfoToFront: (callback) => object
handleSetFolderOuput: () => Promise<string>
handleSelectFolder: () => Promise<string>
getWorkDir: (newDir: string) => Promise<string>
Expand Down
13 changes: 10 additions & 3 deletions electron-app/ecoindex-app/src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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',
Expand All @@ -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
}

Expand Down
4 changes: 4 additions & 0 deletions electron-app/ecoindex-app/src/main/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 4 additions & 0 deletions electron-app/ecoindex-app/src/renderer/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/',
Expand Down
1 change: 1 addition & 0 deletions electron-app/ecoindex-app/src/shared/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
}

0 comments on commit ba85341

Please sign in to comment.