Skip to content

Commit

Permalink
feat: add auto update (to try)
Browse files Browse the repository at this point in the history
  • Loading branch information
hrenaud committed Jul 22, 2024
1 parent 5f66c45 commit e06d0d9
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 1 deletion.
54 changes: 54 additions & 0 deletions electron-app/ecoindex-app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion electron-app/ecoindex-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"productName": "EcoindexLighthouse",
"private": true,
"version": "1.0.1-rc.1",
"description": "An application to mesure the ecoindex of a website with LightHouse & Ecoindex.",
"description": "An application to mesure the ecological impact of a website with LightHouse & Ecoindex.",
"homepage": "https://github.com/cnumr/lighthouse-plugin-ecoindex#readme",
"bugs": "https://github.com/cnumr/lighthouse-plugin-ecoindex/issues",
"publisher": "Association Green IT",
Expand Down Expand Up @@ -67,6 +67,7 @@
"copy-webpack-plugin": "^12.0.2",
"css-loader": "^6.11.0",
"electron": "31.0.1",
"electron-updater": "^6.2.1",
"env-cmd": "^10.1.0",
"eslint": "^8.57.0",
"eslint-plugin-import": "^2.29.1",
Expand Down
35 changes: 35 additions & 0 deletions electron-app/ecoindex-app/src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
setWorkDir,
} from '../shared/memory'

import { autoUpdater } from 'electron-updater'
import fixPath from 'fix-path'
import fs from 'fs'
import os from 'os'
Expand Down Expand Up @@ -87,6 +88,7 @@ const createWindow = (): void => {
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', () => {
autoUpdater.checkForUpdatesAndNotify()
// simple handlers
ipcMain.handle(channels.SIMPLE_MESURES, handleSimpleCollect)
// json handlers
Expand Down Expand Up @@ -138,6 +140,39 @@ app.on('activate', () => {
}
})

autoUpdater.on('checking-for-update', () => {
sendStatusToWindow('Checking for update...')
})
autoUpdater.on('update-available', (info) => {
sendStatusToWindow('Update available.')
})
autoUpdater.on('update-not-available', (info) => {
sendStatusToWindow('Update not available.')
})
autoUpdater.on('error', (err) => {
sendStatusToWindow('Error in auto-updater. ' + err)
})
autoUpdater.on('download-progress', (progressObj) => {
let log_message = 'Download speed: ' + progressObj.bytesPerSecond
log_message = log_message + ' - Downloaded ' + progressObj.percent + '%'
log_message =
log_message +
' (' +
progressObj.transferred +
'/' +
progressObj.total +
')'
sendStatusToWindow(log_message)
})
autoUpdater.on('update-downloaded', (info) => {
sendStatusToWindow('Update downloaded')
})

function sendStatusToWindow(text: string) {
// log.info(text)
getMainWindow().webContents.send('message', text)
}

// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and import them here.

Expand Down

0 comments on commit e06d0d9

Please sign in to comment.