1
+ import { injectable } from "@theia/core/shared/inversify" ;
2
+ import { Emitter } from "@theia/core/shared/vscode-languageserver-protocol" ;
3
+ import { AllPublishOptions } from "builder-util-runtime" ;
4
+ import {
5
+ AppUpdater ,
6
+ AppImageUpdater ,
7
+ MacUpdater ,
8
+ NsisUpdater ,
9
+ UpdateInfo ,
10
+ ProgressInfo ,
11
+ CancellationToken
12
+ } from "electron-updater" ;
13
+
14
+ // IDEUpdater TODO docs
15
+ @injectable ( )
16
+ export class IDEUpdater {
17
+ private updater : AppUpdater ;
18
+
19
+ protected readonly checkingForUpdateEmitter = new Emitter < void > ( ) ;
20
+ protected readonly updateAvailableEmitter = new Emitter < UpdateInfo > ( ) ;
21
+ protected readonly updateNotAvailableEmitter = new Emitter < UpdateInfo > ( ) ;
22
+ protected readonly downloadProgressEmitter = new Emitter < ProgressInfo > ( ) ;
23
+ protected readonly downloadFinishedEmitter = new Emitter < UpdateInfo > ( ) ;
24
+ protected readonly errorEmitter = new Emitter < Error > ( ) ;
25
+
26
+ readonly onCheckingForUpdate = this . checkingForUpdateEmitter . event ;
27
+ readonly onUpdateAvailable = this . updateAvailableEmitter . event ;
28
+ readonly onUpdateNotAvailable = this . updateNotAvailableEmitter . event ;
29
+ readonly onDownloadProgressChanged = this . downloadProgressEmitter . event ;
30
+ readonly onDownloadFinished = this . downloadFinishedEmitter . event ;
31
+ readonly onError = this . errorEmitter . event ;
32
+
33
+ constructor ( ) {
34
+ const options : AllPublishOptions = {
35
+ provider : "s3" ,
36
+ bucket : "" ,
37
+ region : "" ,
38
+ acl : "public-read" ,
39
+ endpoint : "https://{service}.{region}.amazonaws.com" ,
40
+ channel : "" ,
41
+ }
42
+ // TODO: Search S3 bucket name for the two channels
43
+ // https://downloads.arduino.cc/arduino-ide/arduino-ide_2.0.0-rc2_Linux_64bit.zip
44
+ // https://downloads.arduino.cc/arduino-ide/nightly/arduino-ide_nightly-latest_Linux_64bit.zip
45
+
46
+ if ( process . platform === "win32" ) {
47
+ this . updater = new NsisUpdater ( options )
48
+ } else if ( process . platform === "darwin" ) {
49
+ this . updater = new MacUpdater ( options )
50
+ } else {
51
+ this . updater = new AppImageUpdater ( options )
52
+ }
53
+ this . updater . autoDownload = false ;
54
+
55
+ this . updater . on ( "checking-for-update" , this . checkingForUpdateEmitter . fire ) ;
56
+ this . updater . on ( "update-available" , this . updateAvailableEmitter . fire ) ;
57
+ this . updater . on ( "update-not-available" , this . updateNotAvailableEmitter . fire ) ;
58
+ this . updater . on ( "download-progress" , this . downloadFinishedEmitter . fire ) ;
59
+ this . updater . on ( "update-downloaded" , this . downloadFinishedEmitter . fire ) ;
60
+ this . updater . on ( "error" , this . errorEmitter . fire ) ;
61
+ }
62
+
63
+ checkForUpdates ( ) {
64
+ this . updater . checkForUpdates ( ) ;
65
+ }
66
+
67
+ downloadUpdate ( cancellationToken ?: CancellationToken ) {
68
+ this . updater . downloadUpdate ( cancellationToken ) ;
69
+ }
70
+
71
+ quitAndInstall ( ) {
72
+ this . updater . quitAndInstall ( ) ;
73
+ }
74
+ }
0 commit comments