Skip to content

Commit

Permalink
[desktop] make window manager aware of quit-on-update, close #1617
Browse files Browse the repository at this point in the history
  • Loading branch information
ganthern committed Jan 28, 2020
1 parent ec9c390 commit 005a7f9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
6 changes: 4 additions & 2 deletions flow/electron.js
Expand Up @@ -202,8 +202,9 @@ declare module 'electron' {
}

declare export class App {
on(AppEvent, (Event, ...Array<any>) => void): App,
once(AppEvent, (Event, ...Array<any>) => void): App,
on(AppEvent, (Event, ...Array<any>) => any): App,
once(AppEvent, (Event, ...Array<any>) => any): App,
emit(AppEvent) : App,
requestSingleInstanceLock(): void,
quit(): void,
exit(code: Number): void,
Expand Down Expand Up @@ -598,6 +599,7 @@ export type AppEvent
| 'gpu-process-crashed'
| 'accessibility-support-changed'
| 'session-created'
| 'enable-force-quit'


// https://github.com/electron/electron/blob/master/docs/api/browser-window.md#instance-events
Expand Down
14 changes: 12 additions & 2 deletions test/client/desktop/ElectronUpdaterTest.js
Expand Up @@ -26,7 +26,8 @@ o.spec("ElectronUpdater Test", function (done, timeout) {
const electron = {
app: {
getPath: (path: string) => `/mock-${path}/`,
getVersion: (): string => "3.45.0"
getVersion: (): string => "3.45.0",
emit: ()=>{}
}
}

Expand Down Expand Up @@ -133,6 +134,7 @@ o.spec("ElectronUpdater Test", function (done, timeout) {
//mock node modules
const forgeMock = n.mock('node-forge', nodeForge).set()
const autoUpdaterMock = n.mock('electron-updater', {autoUpdater}).set().autoUpdater
const electronMock = n.mock('electron', electron).set()

//mock our modules
n.mock('./DesktopTray', desktopTray).set()
Expand Down Expand Up @@ -177,6 +179,8 @@ o.spec("ElectronUpdater Test", function (done, timeout) {
icon: 'this is an icon'
})

o(electronMock.app.emit.callCount).equals(1)
o(electronMock.app.emit.args[0]).equals('enable-force-quit')
o(autoUpdaterMock.quitAndInstall.callCount).equals(1)
o(autoUpdaterMock.quitAndInstall.args[0]).equals(false)
o(autoUpdaterMock.quitAndInstall.args[1]).equals(true)
Expand Down Expand Up @@ -292,11 +296,13 @@ o.spec("ElectronUpdater Test", function (done, timeout) {
icon: 'this is an icon'
})

o(electronMock.app.emit.callCount).equals(1)
o(electronMock.app.emit.args[0]).equals('enable-force-quit')
o(autoUpdaterMock.quitAndInstall.callCount).equals(1)
o(autoUpdaterMock.quitAndInstall.args[0]).equals(false)
o(autoUpdaterMock.quitAndInstall.args[1]).equals(true)
done()
}, 190)
}, 250)
})

o("retry after autoUpdater reports an error", done => {
Expand Down Expand Up @@ -420,6 +426,7 @@ o.spec("ElectronUpdater Test", function (done, timeout) {
publicKeyFromPem: (pem: string) => n.spyify(pem === "no" ? rightKey : wrongKey)
}).set()
const autoUpdaterMock = n.mock('electron-updater', {autoUpdater}).set().autoUpdater
const electronMock = n.mock('electron', electron).set()

//mock our modules
n.mock('./DesktopTray', desktopTray).set()
Expand Down Expand Up @@ -465,6 +472,9 @@ o.spec("ElectronUpdater Test", function (done, timeout) {
icon: 'this is an icon'
})


o(electronMock.app.emit.callCount).equals(1)
o(electronMock.app.emit.args[0]).equals('enable-force-quit')
o(autoUpdaterMock.quitAndInstall.callCount).equals(1)
o(autoUpdaterMock.quitAndInstall.args[0]).equals(false)
o(autoUpdaterMock.quitAndInstall.args[1]).equals(true)
Expand Down

0 comments on commit 005a7f9

Please sign in to comment.