-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathAppUpdater.ts
55 lines (47 loc) · 1.7 KB
/
AppUpdater.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import {app, BrowserWindow as BrowserWindowElectron} from "electron";
import * as os from "os";
import {isDev, log} from "./util";
import {autoUpdater} from "electron-auto-updater";
import BrowserWindow = GitHubElectron.BrowserWindow
import WebContents = GitHubElectron.WebContents
const UPDATE_SERVER_HOST = "onshape-download.develar.org"
export default class AppUpdater {
constructor(window: BrowserWindow) {
if (isDev()) {
return
}
const platform = os.platform()
if (platform === "linux") {
return
}
const version = app.getVersion()
autoUpdater.addListener("update-available", (event: any) => {
log("A new update is available")
})
autoUpdater.addListener("update-downloaded", (event: any, releaseNotes: string, releaseName: string, releaseDate: string, updateURL: string) => {
notify("A new update is ready to install", `Version ${releaseName} is downloaded and will be automatically installed on Quit`)
})
autoUpdater.addListener("error", (error: any) => {
log(error)
})
autoUpdater.addListener("checking-for-update", (event: any) => {
log("checking-for-update")
})
autoUpdater.addListener("update-not-available", () => {
log("update-not-available")
})
if (platform === "darwin") {
autoUpdater.setFeedURL(`https://${UPDATE_SERVER_HOST}/update/${platform}_${os.arch()}/${version}`)
}
window.webContents.once("did-frame-finish-load", (event: any) => {
autoUpdater.checkForUpdates()
})
}
}
function notify(title: string, message: string) {
let windows = BrowserWindowElectron.getAllWindows()
if (windows.length == 0) {
return
}
windows[0].webContents.send("notify", title, message)
}