Skip to content

Commit

Permalink
auto updater system yay
Browse files Browse the repository at this point in the history
  • Loading branch information
toddtarsi committed Jan 28, 2024
1 parent f6ff296 commit 0acf2b3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/selenium-ide/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "selenium-ide",
"version": "4.0.1-alpha.86",
"version": "4.0.1-alpha.87",
"private": false,
"description": "Selenium IDE electron app",
"author": "Todd <[email protected]>",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { WindowConfig } from 'browser/types'
import Electron from 'electron'

const WIDTH = 400
const HEIGHT = 150
const WIDTH = 300
const HEIGHT = 120

export const window: WindowConfig['window'] = () => {
const display = Electron.screen.getPrimaryDisplay()
Expand All @@ -15,12 +15,11 @@ export const window: WindowConfig['window'] = () => {
minimizable: false,
fullscreenable: false,
autoHideMenuBar: true,
frame: false,
maximizable: false,
show: false,
skipTaskbar: true,
useContentSize: false,
modal: true,
title: 'Update checker',
title: 'Checking for updates',
webPreferences: {
contextIsolation: true,
nodeIntegration: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@ import AppWrapper from 'browser/components/AppWrapper'
import renderWhenReady from 'browser/helpers/renderWhenReady'
import React from 'react'

const completeStatus = 'Update has been installed and will be applied on restart.'
const completeStatus =
'Update has been installed and will be applied on restart.'

let lastStatus = ''
// @ts-expect-error just whatever
window.setStatus = (status: string) => {
lastStatus = status
}

const UpdateNotifier = () => {
const [status, setStatus] = React.useState('Checking for updates...')
const [status, setStatus] = React.useState(lastStatus)
React.useEffect(() => {
// @ts-expect-error just whatever
window.setStatus = setStatus
setStatus(lastStatus)
}, [])
// @ts-expect-error this exists
const completeUpdateNotifier = () => window.completeUpdateNotifier()
Expand All @@ -23,9 +31,8 @@ const UpdateNotifier = () => {
<Grid item xs={12}>
<Typography variant="subtitle1">{status}</Typography>
</Grid>
</Grid>
{status === completeStatus && (
<Grid className="centered" container spacing={1}>
<>
<Grid item xs={6}>
<Button onClick={closeUpdateNotifier} variant="outlined">
OK
Expand All @@ -36,17 +43,16 @@ const UpdateNotifier = () => {
Restart Now
</Button>
</Grid>
</Grid>
</>
)}
{status.startsWith('Error') && (
<Grid className="centered" container spacing={1}>
<Grid item xs={6}>
<Grid item xs={12}>
<Button onClick={closeUpdateNotifier} variant="outlined">
OK
</Button>
</Grid>
</Grid>
)}
</Grid>
</AppWrapper>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export default class SystemController extends BaseController {
if (this.isDown) {
// If automated, assume we already have a chromedriver process running
if (!isAutomated) {
this.checkForUpdates()
const startupError = await this.session.driver.startProcess(
this.session.store.get('browserInfo')
)
Expand Down Expand Up @@ -76,7 +77,6 @@ export default class SystemController extends BaseController {
await this.session.api.system.onLog.addListener(this.writeToLog)
this.isDown = false
firstTime = false
this.checkForUpdates()
}
}

Expand Down Expand Up @@ -118,7 +118,13 @@ export default class SystemController extends BaseController {
ipcMain.once('do-restart', () => {
autoUpdater.quitAndInstall()
})
autoUpdater.checkForUpdatesAndNotify()
const promise = await autoUpdater.checkForUpdatesAndNotify()
if (promise === null) {
window.webContents.executeJavaScript(
'window.setStatus("No Update Available")'
)
setTimeout(() => window.close(), 5000)
}
}

async shutdown() {
Expand Down

0 comments on commit 0acf2b3

Please sign in to comment.