-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
main.ts
146 lines (118 loc) · 4.52 KB
/
main.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import { CancellationToken, PackageFileInfo, ProgressInfo, UpdateFileInfo, UpdateInfo } from "builder-util-runtime"
import { EventEmitter } from "events"
import { existsSync, readFileSync } from "fs-extra"
import * as path from "path"
import { URL } from "url"
import { AppUpdater } from "./AppUpdater"
import { LoginCallback } from "./electronHttpExecutor"
export { BaseUpdater } from "./BaseUpdater"
export { AppUpdater, NoOpLogger } from "./AppUpdater"
export { CancellationToken, PackageFileInfo, ProgressInfo, UpdateFileInfo, UpdateInfo }
export { Provider } from "./providers/Provider"
export { AppImageUpdater } from "./AppImageUpdater"
export { DebUpdater } from "./DebUpdater"
export { RpmUpdater } from "./RpmUpdater"
export { MacUpdater } from "./MacUpdater"
export { NsisUpdater } from "./NsisUpdater"
// autoUpdater to mimic electron bundled autoUpdater
let _autoUpdater: any
// required for jsdoc
export declare const autoUpdater: AppUpdater
function doLoadAutoUpdater(): AppUpdater {
// tslint:disable:prefer-conditional-expression
if (process.platform === "win32") {
_autoUpdater = new (require("./NsisUpdater").NsisUpdater)()
} else if (process.platform === "darwin") {
_autoUpdater = new (require("./MacUpdater").MacUpdater)()
} else {
_autoUpdater = new (require("./AppImageUpdater").AppImageUpdater)()
try {
const identity = path.join(process.resourcesPath, "package-type")
if (!existsSync(identity)) {
return _autoUpdater
}
console.info("Checking for beta autoupdate feature for deb/rpm distributions")
const fileType = readFileSync(identity).toString().trim()
console.info("Found package-type:", fileType)
switch (fileType) {
case "deb":
_autoUpdater = new (require("./DebUpdater").DebUpdater)()
break
case "rpm":
_autoUpdater = new (require("./RpmUpdater").RpmUpdater)()
break
default:
break
}
} catch (error: any) {
console.warn(
"Unable to detect 'package-type' for autoUpdater (beta rpm/deb support). If you'd like to expand support, please consider contributing to electron-builder",
error.message
)
}
}
return _autoUpdater
}
Object.defineProperty(exports, "autoUpdater", {
enumerable: true,
get: () => {
return _autoUpdater || doLoadAutoUpdater()
},
})
export interface ResolvedUpdateFileInfo {
readonly url: URL
readonly info: UpdateFileInfo
packageInfo?: PackageFileInfo
}
export interface UpdateCheckResult {
readonly updateInfo: UpdateInfo
readonly downloadPromise?: Promise<Array<string>> | null
readonly cancellationToken?: CancellationToken
/** @deprecated */
readonly versionInfo: UpdateInfo
}
export type UpdaterEvents = "login" | "checking-for-update" | "update-available" | "update-not-available" | "update-cancelled" | "download-progress" | "update-downloaded" | "error"
export const DOWNLOAD_PROGRESS = "download-progress"
export const UPDATE_DOWNLOADED = "update-downloaded"
export type LoginHandler = (authInfo: any, callback: LoginCallback) => void
export class UpdaterSignal {
constructor(private emitter: EventEmitter) {}
/**
* Emitted when an authenticating proxy is [asking for user credentials](https://github.com/electron/electron/blob/master/docs/api/client-request.md#event-login).
*/
login(handler: LoginHandler): void {
addHandler(this.emitter, "login", handler)
}
progress(handler: (info: ProgressInfo) => void): void {
addHandler(this.emitter, DOWNLOAD_PROGRESS, handler)
}
updateDownloaded(handler: (info: UpdateDownloadedEvent) => void): void {
addHandler(this.emitter, UPDATE_DOWNLOADED, handler)
}
updateCancelled(handler: (info: UpdateInfo) => void): void {
addHandler(this.emitter, "update-cancelled", handler)
}
}
export interface UpdateDownloadedEvent extends UpdateInfo {
downloadedFile: string
}
const isLogEvent = false
function addHandler(emitter: EventEmitter, event: UpdaterEvents, handler: (...args: Array<any>) => void): void {
if (isLogEvent) {
emitter.on(event, (...args: Array<any>) => {
console.log("%s %s", event, args)
handler(...args)
})
} else {
emitter.on(event, handler)
}
}
export interface Logger {
info(message?: any): void
warn(message?: any): void
error(message?: any): void
debug?(message: string): void
}
// return null if verify signature succeed
// return error message if verify signature failed
export type verifyUpdateCodeSignature = (publisherName: string[], path: string) => Promise<string | null>