/ src / auto-update-manager.js
auto-update-manager.js
 1  const { Emitter, CompositeDisposable } = require('event-kit');
 2  
 3  module.exports = class AutoUpdateManager {
 4    constructor({ applicationDelegate }) {
 5      this.applicationDelegate = applicationDelegate;
 6      this.subscriptions = new CompositeDisposable();
 7      this.emitter = new Emitter();
 8    }
 9  
10    initialize() {
11      this.subscriptions.add(
12        this.applicationDelegate.onDidBeginCheckingForUpdate(() => {
13          this.emitter.emit('did-begin-checking-for-update');
14        }),
15        this.applicationDelegate.onDidBeginDownloadingUpdate(() => {
16          this.emitter.emit('did-begin-downloading-update');
17        }),
18        this.applicationDelegate.onDidCompleteDownloadingUpdate(details => {
19          this.emitter.emit('did-complete-downloading-update', details);
20        }),
21        this.applicationDelegate.onUpdateNotAvailable(() => {
22          this.emitter.emit('update-not-available');
23        }),
24        this.applicationDelegate.onUpdateError(() => {
25          this.emitter.emit('update-error');
26        })
27      );
28    }
29  
30    destroy() {
31      this.subscriptions.dispose();
32      this.emitter.dispose();
33    }
34  
35    checkForUpdate() {
36      this.applicationDelegate.checkForUpdate();
37    }
38  
39    restartAndInstallUpdate() {
40      this.applicationDelegate.restartAndInstallUpdate();
41    }
42  
43    getState() {
44      return this.applicationDelegate.getAutoUpdateManagerState();
45    }
46  
47    getErrorMessage() {
48      return this.applicationDelegate.getAutoUpdateManagerErrorMessage();
49    }
50  
51    platformSupportsUpdates() {
52      return (
53        atom.getReleaseChannel() !== 'dev' && this.getState() !== 'unsupported'
54      );
55    }
56  
57    onDidBeginCheckingForUpdate(callback) {
58      return this.emitter.on('did-begin-checking-for-update', callback);
59    }
60  
61    onDidBeginDownloadingUpdate(callback) {
62      return this.emitter.on('did-begin-downloading-update', callback);
63    }
64  
65    onDidCompleteDownloadingUpdate(callback) {
66      return this.emitter.on('did-complete-downloading-update', callback);
67    }
68  
69    // TODO: When https://github.com/atom/electron/issues/4587 is closed, we can
70    // add an update-available event.
71    // onUpdateAvailable (callback) {
72    //   return this.emitter.on('update-available', callback)
73    // }
74  
75    onUpdateNotAvailable(callback) {
76      return this.emitter.on('update-not-available', callback);
77    }
78  
79    onUpdateError(callback) {
80      return this.emitter.on('update-error', callback);
81    }
82  
83    getPlatform() {
84      return process.platform;
85    }
86  };