Merge pull request #6018 from electron/string-map
Cleanup code for autoUpdater
This commit is contained in:
commit
8fe5dd22b2
9 changed files with 32 additions and 67 deletions
|
@ -9,7 +9,6 @@
|
||||||
#include "atom/browser/native_window.h"
|
#include "atom/browser/native_window.h"
|
||||||
#include "atom/browser/window_list.h"
|
#include "atom/browser/window_list.h"
|
||||||
#include "atom/common/native_mate_converters/callback.h"
|
#include "atom/common/native_mate_converters/callback.h"
|
||||||
#include "atom/common/native_mate_converters/string_map_converter.h"
|
|
||||||
#include "atom/common/node_includes.h"
|
#include "atom/common/node_includes.h"
|
||||||
#include "native_mate/dictionary.h"
|
#include "native_mate/dictionary.h"
|
||||||
#include "native_mate/object_template_builder.h"
|
#include "native_mate/object_template_builder.h"
|
||||||
|
@ -80,6 +79,12 @@ void AutoUpdater::OnWindowAllClosed() {
|
||||||
QuitAndInstall();
|
QuitAndInstall();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AutoUpdater::SetFeedURL(const std::string& url, mate::Arguments* args) {
|
||||||
|
auto_updater::AutoUpdater::HeaderMap headers;
|
||||||
|
args->GetNext(&headers);
|
||||||
|
auto_updater::AutoUpdater::SetFeedURL(url, headers);
|
||||||
|
}
|
||||||
|
|
||||||
void AutoUpdater::QuitAndInstall() {
|
void AutoUpdater::QuitAndInstall() {
|
||||||
// If we don't have any window then quitAndInstall immediately.
|
// If we don't have any window then quitAndInstall immediately.
|
||||||
WindowList* window_list = WindowList::GetInstance();
|
WindowList* window_list = WindowList::GetInstance();
|
||||||
|
@ -103,8 +108,8 @@ mate::Handle<AutoUpdater> AutoUpdater::Create(v8::Isolate* isolate) {
|
||||||
void AutoUpdater::BuildPrototype(
|
void AutoUpdater::BuildPrototype(
|
||||||
v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> prototype) {
|
v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> prototype) {
|
||||||
mate::ObjectTemplateBuilder(isolate, prototype)
|
mate::ObjectTemplateBuilder(isolate, prototype)
|
||||||
.SetMethod("_setFeedURL", &auto_updater::AutoUpdater::SetFeedURL)
|
|
||||||
.SetMethod("checkForUpdates", &auto_updater::AutoUpdater::CheckForUpdates)
|
.SetMethod("checkForUpdates", &auto_updater::AutoUpdater::CheckForUpdates)
|
||||||
|
.SetMethod("setFeedURL", &AutoUpdater::SetFeedURL)
|
||||||
.SetMethod("quitAndInstall", &AutoUpdater::QuitAndInstall);
|
.SetMethod("quitAndInstall", &AutoUpdater::QuitAndInstall);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include "atom/browser/api/event_emitter.h"
|
#include "atom/browser/api/event_emitter.h"
|
||||||
#include "atom/browser/auto_updater.h"
|
#include "atom/browser/auto_updater.h"
|
||||||
#include "atom/browser/window_list_observer.h"
|
#include "atom/browser/window_list_observer.h"
|
||||||
|
#include "native_mate/arguments.h"
|
||||||
#include "native_mate/handle.h"
|
#include "native_mate/handle.h"
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
@ -43,6 +44,7 @@ class AutoUpdater : public mate::EventEmitter<AutoUpdater>,
|
||||||
void OnWindowAllClosed() override;
|
void OnWindowAllClosed() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void SetFeedURL(const std::string& url, mate::Arguments* args);
|
||||||
void QuitAndInstall();
|
void QuitAndInstall();
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(AutoUpdater);
|
DISALLOW_COPY_AND_ASSIGN(AutoUpdater);
|
||||||
|
|
|
@ -38,34 +38,33 @@ void AutoUpdater::SetFeedURL(const std::string& feed,
|
||||||
NSURL* url = [NSURL URLWithString:base::SysUTF8ToNSString(feed)];
|
NSURL* url = [NSURL URLWithString:base::SysUTF8ToNSString(feed)];
|
||||||
NSMutableURLRequest* urlRequest = [NSMutableURLRequest requestWithURL:url];
|
NSMutableURLRequest* urlRequest = [NSMutableURLRequest requestWithURL:url];
|
||||||
|
|
||||||
for (auto&& it : requestHeaders) {
|
for (const auto& it : requestHeaders) {
|
||||||
[urlRequest setValue:base::SysUTF8ToNSString(it.second)
|
[urlRequest setValue:base::SysUTF8ToNSString(it.second)
|
||||||
forHTTPHeaderField:base::SysUTF8ToNSString(it.first)];
|
forHTTPHeaderField:base::SysUTF8ToNSString(it.first)];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_updater == nil) {
|
if (g_updater)
|
||||||
// Initialize the SQRLUpdater.
|
[g_updater release];
|
||||||
@try {
|
|
||||||
g_updater = [[SQRLUpdater alloc] initWithUpdateRequest:urlRequest];
|
|
||||||
} @catch (NSException* error) {
|
|
||||||
delegate->OnError(base::SysNSStringToUTF8(error.reason));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[g_updater rac_valuesForKeyPath:@"state" observer:g_updater]
|
// Initialize the SQRLUpdater.
|
||||||
subscribeNext:^(NSNumber *stateNumber) {
|
@try {
|
||||||
int state = [stateNumber integerValue];
|
g_updater = [[SQRLUpdater alloc] initWithUpdateRequest:urlRequest];
|
||||||
// Dispatching the event on main thread.
|
} @catch (NSException* error) {
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
delegate->OnError(base::SysNSStringToUTF8(error.reason));
|
||||||
if (state == SQRLUpdaterStateCheckingForUpdate)
|
return;
|
||||||
delegate->OnCheckingForUpdate();
|
|
||||||
else if (state == SQRLUpdaterStateDownloadingUpdate)
|
|
||||||
delegate->OnUpdateAvailable();
|
|
||||||
});
|
|
||||||
}];
|
|
||||||
} else {
|
|
||||||
g_updater.updateRequest = urlRequest;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[g_updater rac_valuesForKeyPath:@"state" observer:g_updater]
|
||||||
|
subscribeNext:^(NSNumber *stateNumber) {
|
||||||
|
int state = [stateNumber integerValue];
|
||||||
|
// Dispatching the event on main thread.
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
if (state == SQRLUpdaterStateCheckingForUpdate)
|
||||||
|
delegate->OnCheckingForUpdate();
|
||||||
|
else if (state == SQRLUpdaterStateDownloadingUpdate)
|
||||||
|
delegate->OnUpdateAvailable();
|
||||||
|
});
|
||||||
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "atom/common/crash_reporter/crash_reporter.h"
|
#include "atom/common/crash_reporter/crash_reporter.h"
|
||||||
#include "atom/common/native_mate_converters/string_map_converter.h"
|
|
||||||
#include "base/bind.h"
|
#include "base/bind.h"
|
||||||
#include "native_mate/dictionary.h"
|
#include "native_mate/dictionary.h"
|
||||||
|
|
||||||
|
|
|
@ -1,35 +0,0 @@
|
||||||
// Copyright (c) 2016 GitHub, Inc.
|
|
||||||
// Use of this source code is governed by the MIT license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
#ifndef ATOM_COMMON_NATIVE_MATE_CONVERTERS_STRING_MAP_CONVERTER_H_
|
|
||||||
#define ATOM_COMMON_NATIVE_MATE_CONVERTERS_STRING_MAP_CONVERTER_H_
|
|
||||||
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "native_mate/converter.h"
|
|
||||||
|
|
||||||
namespace mate {
|
|
||||||
|
|
||||||
template<>
|
|
||||||
struct Converter<std::map<std::string, std::string> > {
|
|
||||||
static bool FromV8(v8::Isolate* isolate,
|
|
||||||
v8::Local<v8::Value> val,
|
|
||||||
std::map<std::string, std::string>* out) {
|
|
||||||
if (!val->IsObject())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
v8::Local<v8::Object> dict = val->ToObject();
|
|
||||||
v8::Local<v8::Array> keys = dict->GetOwnPropertyNames();
|
|
||||||
for (uint32_t i = 0; i < keys->Length(); ++i) {
|
|
||||||
v8::Local<v8::Value> key = keys->Get(i);
|
|
||||||
(*out)[V8ToString(key)] = V8ToString(dict->Get(key));
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace mate
|
|
||||||
|
|
||||||
#endif // ATOM_COMMON_NATIVE_MATE_CONVERTERS_STRING_MAP_CONVERTER_H_
|
|
|
@ -97,7 +97,7 @@ The `autoUpdater` object has the following methods:
|
||||||
### `autoUpdater.setFeedURL(url[, requestHeaders])`
|
### `autoUpdater.setFeedURL(url[, requestHeaders])`
|
||||||
|
|
||||||
* `url` String
|
* `url` String
|
||||||
* `requestHeaders` Object - HTTP request headers (_OS X_)
|
* `requestHeaders` Object _OS X_ - HTTP request headers.
|
||||||
|
|
||||||
Sets the `url` and initialize the auto updater.
|
Sets the `url` and initialize the auto updater.
|
||||||
|
|
||||||
|
|
|
@ -377,7 +377,6 @@
|
||||||
'atom/common/native_mate_converters/net_converter.cc',
|
'atom/common/native_mate_converters/net_converter.cc',
|
||||||
'atom/common/native_mate_converters/net_converter.h',
|
'atom/common/native_mate_converters/net_converter.h',
|
||||||
'atom/common/native_mate_converters/string16_converter.h',
|
'atom/common/native_mate_converters/string16_converter.h',
|
||||||
'atom/common/native_mate_converters/string_map_converter.h',
|
|
||||||
'atom/common/native_mate_converters/ui_base_types_converter.h',
|
'atom/common/native_mate_converters/ui_base_types_converter.h',
|
||||||
'atom/common/native_mate_converters/v8_value_converter.cc',
|
'atom/common/native_mate_converters/v8_value_converter.cc',
|
||||||
'atom/common/native_mate_converters/v8_value_converter.h',
|
'atom/common/native_mate_converters/v8_value_converter.h',
|
||||||
|
|
|
@ -3,8 +3,4 @@ const autoUpdater = process.atomBinding('auto_updater').autoUpdater
|
||||||
|
|
||||||
Object.setPrototypeOf(autoUpdater, EventEmitter.prototype)
|
Object.setPrototypeOf(autoUpdater, EventEmitter.prototype)
|
||||||
|
|
||||||
autoUpdater.setFeedURL = function (url, headers) {
|
|
||||||
return autoUpdater._setFeedURL(url, headers || {})
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = autoUpdater
|
module.exports = autoUpdater
|
||||||
|
|
2
vendor/native_mate
vendored
2
vendor/native_mate
vendored
|
@ -1 +1 @@
|
||||||
Subproject commit 4ad6ecd19617ac33c09e93ccb6d8e652ac1ac126
|
Subproject commit e75f2aa087db346efc4b530f9e1ce7d3a72a3434
|
Loading…
Add table
Add a link
Reference in a new issue