Emit Date object in C++ directly

This commit is contained in:
Cheng Zhao 2015-10-23 14:58:19 +08:00
parent a3f62da615
commit 85c84a0eb0
2 changed files with 27 additions and 14 deletions

View file

@ -11,6 +11,23 @@
#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(

View 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
if process.platform is 'win32'
module.exports = require './auto-updater/auto-updater-win'
return
# Implementation on OS X.
autoUpdater = process.atomBinding('auto_updater').autoUpdater
EventEmitter = require('events').EventEmitter
autoUpdater.__proto__ = EventEmitter.prototype
autoUpdater.on 'update-downloaded-raw', (args...) ->
args[3] = new Date(args[3]) # releaseDate
@emit 'update-downloaded', args..., => @quitAndInstall()
autoUpdater.__proto__ = EventEmitter.prototype
autoUpdater.quitAndInstall = ->
# If we don't have any window then quitAndInstall immediately.