]> khamidou — GitHub mirrors - electron.git/commitdiff
Use ES6 style class
authorKevin Sawicki <kevinsawicki@gmail.com>
Fri, 15 Jan 2016 22:12:57 +0000 (14:12 -0800)
committerKevin Sawicki <kevinsawicki@gmail.com>
Fri, 15 Jan 2016 22:12:57 +0000 (14:12 -0800)
atom/browser/api/lib/auto-updater/auto-updater-win.js

index 097ac9d33294ddd8b81bba373c543277539b16cb..e7d6daca9273d98a39c0356646cfafe605f8b5f2 100644 (file)
@@ -1,63 +1,64 @@
+'use strict';
+
 const app = require('electron').app;
 const EventEmitter = require('events').EventEmitter;
 const url = require('url');
 const squirrelUpdate = require('./squirrel-update-win');
-const util = require('util');
-
-function AutoUpdater() {
-  AutoUpdater.super_.call(this);
-}
-
-util.inherits(AutoUpdater, EventEmitter);
 
-AutoUpdater.prototype.quitAndInstall = function() {
-  squirrelUpdate.processStart();
-  return app.quit();
-};
-
-AutoUpdater.prototype.setFeedURL = function(updateURL) {
-  return this.updateURL = updateURL;
-};
+class AutoUpdater extends EventEmitter {
+  constructor() {
+    super();
+  }
 
-AutoUpdater.prototype.checkForUpdates = function() {
-  if (!this.updateURL) {
-    return this.emitError('Update URL is not set');
+  quitAndInstall() {
+    squirrelUpdate.processStart();
+    return app.quit();
   }
-  if (!squirrelUpdate.supported()) {
-    return this.emitError('Can not find Squirrel');
+
+  setFeedURL(updateURL) {
+    return this.updateURL = updateURL;
   }
-  this.emit('checking-for-update');
-  return squirrelUpdate.download(this.updateURL, (function(_this) {
-    return function(error, update) {
-      if (error != null) {
-        return _this.emitError(error);
-      }
-      if (update == null) {
-        return _this.emit('update-not-available');
-      }
-      _this.emit('update-available');
-      return squirrelUpdate.update(_this.updateURL, function(error) {
-        var date, releaseNotes, version;
+
+  checkForUpdates() {
+    if (!this.updateURL) {
+      return this.emitError('Update URL is not set');
+    }
+    if (!squirrelUpdate.supported()) {
+      return this.emitError('Can not find Squirrel');
+    }
+    this.emit('checking-for-update');
+    return squirrelUpdate.download(this.updateURL, (function(_this) {
+      return function(error, update) {
         if (error != null) {
           return _this.emitError(error);
         }
-        releaseNotes = update.releaseNotes, version = update.version;
+        if (update == null) {
+          return _this.emit('update-not-available');
+        }
+        _this.emit('update-available');
+        return squirrelUpdate.update(_this.updateURL, function(error) {
+          var date, releaseNotes, version;
+          if (error != null) {
+            return _this.emitError(error);
+          }
+          releaseNotes = update.releaseNotes, version = update.version;
 
-        // Following information is not available on Windows, so fake them.
-        date = new Date;
-        url = _this.updateURL;
-        return _this.emit('update-downloaded', {}, releaseNotes, version, date, url, function() {
-          return _this.quitAndInstall();
+          // Following information is not available on Windows, so fake them.
+          date = new Date;
+          url = _this.updateURL;
+          return _this.emit('update-downloaded', {}, releaseNotes, version, date, url, function() {
+            return _this.quitAndInstall();
+          });
         });
-      });
-    };
-  })(this));
-};
-
-// Private: Emit both error object and message, this is to keep compatibility
-// with Old APIs.
-AutoUpdater.prototype.emitError = function(message) {
-  return this.emit('error', new Error(message), message);
-};
+      };
+    })(this));
+  }
+
+  // Private: Emit both error object and message, this is to keep compatibility
+  // with Old APIs.
+  emitError(message) {
+    return this.emit('error', new Error(message), message);
+  }
+}
 
 module.exports = new AutoUpdater;