]> khamidou — GitHub mirrors - electron.git/commitdiff
Emit Date object in C++ directly
authorCheng Zhao <zcbenz@gmail.com>
Fri, 23 Oct 2015 06:58:19 +0000 (14:58 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Fri, 23 Oct 2015 06:58:19 +0000 (14:58 +0800)
atom/browser/api/atom_api_auto_updater.cc
atom/browser/api/lib/auto-updater.coffee

index d8407f60b3275773b29c149f022b62a2e649ff72..9a240a27903c704b77442248c8bd24a8a1f5ba4b 100644 (file)
 #include "native_mate/dictionary.h"
 #include "native_mate/object_template_builder.h"
 
+namespace mate {
+
+template<>
+struct Converter<base::Time> {
+  static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
+                                   const base::Time& val) {
+    v8::MaybeLocal<v8::Value> date = v8::Date::New(
+        isolate->GetCurrentContext(), val.ToJsTime());
+    if (date.IsEmpty())
+      return v8::Null(isolate);
+    else
+      return date.ToLocalChecked();
+  }
+};
+
+}  // namespace mate
+
 namespace atom {
 
 namespace api {
@@ -49,11 +66,10 @@ void AutoUpdater::OnUpdateNotAvailable() {
 void AutoUpdater::OnUpdateDownloaded(const std::string& release_notes,
                                      const std::string& release_name,
                                      const base::Time& release_date,
-                                     const std::string& update_url,
+                                     const std::string& url,
                                      const base::Closure& quit_and_install) {
   quit_and_install_ = quit_and_install;
-  Emit("update-downloaded-raw", release_notes, release_name,
-       release_date.ToJsTime(), update_url);
+  Emit("update-downloaded", release_notes, release_name, release_date, url);
 }
 
 mate::ObjectTemplateBuilder AutoUpdater::GetObjectTemplateBuilder(
index c039bd12dc4635edc54aa656830df372dc719926..7e3fa99a76d92506d15cd20b94bcd76c4adeedcd 100644 (file)
@@ -1,15 +1,12 @@
-switch process.platform
-  when 'win32'
-    autoUpdater = require './auto-updater/auto-updater-win'
-  else
-    # take the default binding for the current platform
-    autoUpdater  = process.atomBinding('auto_updater').autoUpdater
-    EventEmitter = require('events').EventEmitter
-    autoUpdater.__proto__ = EventEmitter.prototype
+if process.platform is 'win32'
+  module.exports = require './auto-updater/auto-updater-win'
+  return
 
-autoUpdater.on 'update-downloaded-raw', (args...) ->
-  args[3] = new Date(args[3])  # releaseDate
-  @emit 'update-downloaded', args..., => @quitAndInstall()
+# Implementation on OS X.
+autoUpdater  = process.atomBinding('auto_updater').autoUpdater
+EventEmitter = require('events').EventEmitter
+
+autoUpdater.__proto__ = EventEmitter.prototype
 
 autoUpdater.quitAndInstall = ->
   # If we don't have any window then quitAndInstall immediately.