-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy pathmain.ts
167 lines (133 loc) · 4.46 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import { CancellationToken, PackageFileInfo, ProgressInfo, UpdateInfo, VersionInfo } from "builder-util-runtime"
import { EventEmitter } from "events"
import { OutgoingHttpHeaders } from "http"
import { URL } from "url"
import { AppUpdater } from "./AppUpdater"
import { LoginCallback } from "./electronHttpExecutor"
export { NET_SESSION_NAME } from "./electronHttpExecutor"
export { AppUpdater, NoOpLogger } from "./AppUpdater"
export { UpdateInfo, VersionInfo }
export { CancellationToken } from "builder-util-runtime"
export { Provider } from "./Provider"
// autoUpdater to mimic electron bundled autoUpdater
let _autoUpdater: any
// required for jsdoc
export declare const autoUpdater: AppUpdater
function _load_autoUpdater(): 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)()
}
return _autoUpdater
}
Object.defineProperty(exports, "autoUpdater", {
enumerable: true,
get: () => {
return _autoUpdater || _load_autoUpdater()
}
})
export interface FileInfo {
readonly name: string
readonly url: string
packageInfo?: PackageFileInfo
readonly sha2?: string
readonly sha512?: string
readonly headers?: OutgoingHttpHeaders
}
// due to historical reasons for windows we use channel name without platform specifier
export function getDefaultChannelName() {
return `latest${getChannelFilePrefix()}`
}
function getChannelFilePrefix() {
const currentPlatform = getCurrentPlatform()
if (currentPlatform === "linux") {
return "-linux"
}
else {
return currentPlatform === "darwin" ? "-mac" : ""
}
}
export function getCustomChannelName(channel: string) {
return `${channel}${getChannelFilePrefix()}`
}
export function getCurrentPlatform() {
return process.env.TEST_UPDATER_PLATFORM || process.platform
}
export function isUseOldMacProvider() {
// getCurrentPlatform() === "darwin"
return false
}
export function getChannelFilename(channel: string) {
return `${channel}.yml`
}
export interface UpdateCheckResult {
readonly versionInfo: VersionInfo
readonly fileInfo?: FileInfo
readonly downloadPromise?: Promise<Array<string>> | null
readonly cancellationToken?: CancellationToken
}
export type UpdaterEvents = "login" | "checking-for-update" | "update-available" | "update-cancelled" | "download-progress" | "update-downloaded" | "error"
export const DOWNLOAD_PROGRESS: UpdaterEvents = "download-progress"
export const UPDATE_DOWNLOADED: UpdaterEvents = "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) {
addHandler(this.emitter, "login", handler)
}
progress(handler: (info: ProgressInfo) => void) {
addHandler(this.emitter, DOWNLOAD_PROGRESS, handler)
}
updateDownloaded(handler: (info: UpdateInfo) => void) {
addHandler(this.emitter, UPDATE_DOWNLOADED, handler)
}
updateCancelled(handler: (info: UpdateInfo) => void) {
addHandler(this.emitter, "update-cancelled", handler)
}
}
const isLogEvent = false
function addHandler(emitter: EventEmitter, event: UpdaterEvents, handler: (...args: Array<any>) => void) {
if (isLogEvent) {
emitter.on(event, (...args: Array<any>) => {
console.log("%s %s", event, args)
handler.apply(null, 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
}
// if baseUrl path doesn't ends with /, this path will be not prepended to passed pathname for new URL(input, base)
/** @internal */
export function newBaseUrl(url: string) {
const result = new URL(url)
if (!result.pathname.endsWith("/")) {
result.pathname += "/"
}
return result
}
/** @internal */
export function newUrlFromBase(pathname: string, baseUrl: URL): URL {
const result = new URL(pathname, baseUrl)
// search is not propagated
if (!result.search && baseUrl.search) {
result.search = baseUrl.search
}
return result
}