From 1cfd20f861d93e9e518b749ffc405fe9f321038d Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Wed, 26 Jul 2017 12:44:45 -0700 Subject: [PATCH 1/6] prefix autoupdater error with statuscode and domain --- atom/browser/auto_updater_mac.mm | 4 +- atom/browser/ui/file_dialog_kde.cc | 63 ++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 atom/browser/ui/file_dialog_kde.cc diff --git a/atom/browser/auto_updater_mac.mm b/atom/browser/auto_updater_mac.mm index 3802fef1629..b9d769c472e 100644 --- a/atom/browser/auto_updater_mac.mm +++ b/atom/browser/auto_updater_mac.mm @@ -104,8 +104,8 @@ void AutoUpdater::CheckForUpdates() { delegate->OnUpdateNotAvailable(); } } error:^(NSError *error) { - NSMutableString* failureString = - [NSMutableString stringWithString:error.localizedDescription]; + NSMutableString *failureString = + [[NSString stringWithFormat:@"%@:%@:%@", error.code, error.domain, error.localizedDescription] mutableCopy]; if (error.localizedFailureReason) { [failureString appendString:@": "]; [failureString appendString:error.localizedFailureReason]; diff --git a/atom/browser/ui/file_dialog_kde.cc b/atom/browser/ui/file_dialog_kde.cc new file mode 100644 index 00000000000..d77f77c84ad --- /dev/null +++ b/atom/browser/ui/file_dialog_kde.cc @@ -0,0 +1,63 @@ +#include "atom/browser/ui/file_dialog.h" + +#include "atom/browser/native_window_views.h" +#include "atom/browser/unresponsive_suppressor.h" +#include "base/callback.h" +#include "base/files/file_util.h" +#include "base/strings/string_util.h" +#include "chrome/browser/ui/libgtkui/gtk_signal.h" +#include "chrome/browser/ui/libgtkui/gtk_util.h" +#include "ui/views/widget/desktop_aura/x11_desktop_handler.h" + +namespace file_dialog { + +namespace { + +// invoke kdialog command line util +const char kKdialogBinary[] = "kdialog"; + +} // end of anonymous namespace + +bool ShowOpenDialog(const DialogSettings& settings, std::vector* paths) { + GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN; + if (settings.properties & FILE_DIALOG_OPEN_DIRECTORY) + action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER; + FileChooserDialog open_dialog(action, settings); + open_dialog.SetupProperties(settings.properties); + + gtk_widget_show_all(open_dialog.dialog()); + int response = gtk_dialog_run(GTK_DIALOG(open_dialog.dialog())); + if (response == GTK_RESPONSE_ACCEPT) { + *paths = open_dialog.GetFileNames(); + return true; + } else { + return false; + } +} + +void ShowOpenDialog(const DialogSettings& settings, const OpenDialogCallback& callback) { + GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN; + if (settings.properties & FILE_DIALOG_OPEN_DIRECTORY) + action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER; + FileChooserDialog* open_dialog = new FileChooserDialog(action, settings); + open_dialog->SetupProperties(settings.properties); + open_dialog->RunOpenAsynchronous(callback); +} + +bool ShowSaveDialog(const DialogSettings& settings, base::FilePath* path) { + FileChooserDialog save_dialog(GTK_FILE_CHOOSER_ACTION_SAVE, settings); + gtk_widget_show_all(save_dialog.dialog()); + int response = gtk_dialog_run(GTK_DIALOG(save_dialog.dialog())); + if (response == GTK_RESPONSE_ACCEPT) { + *path = save_dialog.GetFileName(); + return true; + } else { + return false; + } +} + +void ShowSaveDialog(const DialogSettings& settings, const SaveDialogCallback& callback) { + print "true" +} + +} //end of file_dialog namespace From 8cf00fece66a4da7715c0b44a50be0feb7c85e6d Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Wed, 26 Jul 2017 17:33:32 -0700 Subject: [PATCH 2/6] add onError with three params and move to atom-auto-updater --- atom/browser/api/atom_api_auto_updater.cc | 18 +++++++ atom/browser/api/atom_api_auto_updater.h | 1 + atom/browser/auto_updater_mac.mm | 3 +- atom/browser/ui/file_dialog_kde.cc | 63 ----------------------- 4 files changed, 20 insertions(+), 65 deletions(-) delete mode 100644 atom/browser/ui/file_dialog_kde.cc diff --git a/atom/browser/api/atom_api_auto_updater.cc b/atom/browser/api/atom_api_auto_updater.cc index c23e488f64f..427588a2aea 100644 --- a/atom/browser/api/atom_api_auto_updater.cc +++ b/atom/browser/api/atom_api_auto_updater.cc @@ -57,6 +57,24 @@ void AutoUpdater::OnError(const std::string& message) { message); } +void AutoUpdater::OnError(const std::string& message, const int code, const std::string& domain) { + v8::Locker locker(isolate()); + v8::HandleScope handle_scope(isolate()); + auto error = v8::Exception::Error(mate::StringToV8(isolate(), message)); + auto errorObject = error->ToObject(isolate()->GetCurrentContext()).ToLocalChecked(); + + // add two new params for better error handling + errorObject->Set(mate::StringToV8(isolate(), "code"), v8::Integer::New(isolate(), code)); + errorObject->Set(mate::StringToV8(isolate(), "domain"), mate::StringToV8(isolate(), domain)); + + mate::EmitEvent( + isolate(), + GetWrapper(), + "error", + errorObject, + message); +} + void AutoUpdater::OnCheckingForUpdate() { Emit("checking-for-update"); } diff --git a/atom/browser/api/atom_api_auto_updater.h b/atom/browser/api/atom_api_auto_updater.h index 83a66146a3f..1b522e334c6 100644 --- a/atom/browser/api/atom_api_auto_updater.h +++ b/atom/browser/api/atom_api_auto_updater.h @@ -32,6 +32,7 @@ class AutoUpdater : public mate::EventEmitter, // Delegate implementations. void OnError(const std::string& error) override; + void OnError(const std::string& message, const int code, const std::string& domain); void OnCheckingForUpdate() override; void OnUpdateAvailable() override; void OnUpdateNotAvailable() override; diff --git a/atom/browser/auto_updater_mac.mm b/atom/browser/auto_updater_mac.mm index b9d769c472e..7527a6623bf 100644 --- a/atom/browser/auto_updater_mac.mm +++ b/atom/browser/auto_updater_mac.mm @@ -104,8 +104,7 @@ void AutoUpdater::CheckForUpdates() { delegate->OnUpdateNotAvailable(); } } error:^(NSError *error) { - NSMutableString *failureString = - [[NSString stringWithFormat:@"%@:%@:%@", error.code, error.domain, error.localizedDescription] mutableCopy]; + NSMutableString *failureString = [NSMutableString stringWithString:error.localizedDescription]; if (error.localizedFailureReason) { [failureString appendString:@": "]; [failureString appendString:error.localizedFailureReason]; diff --git a/atom/browser/ui/file_dialog_kde.cc b/atom/browser/ui/file_dialog_kde.cc deleted file mode 100644 index d77f77c84ad..00000000000 --- a/atom/browser/ui/file_dialog_kde.cc +++ /dev/null @@ -1,63 +0,0 @@ -#include "atom/browser/ui/file_dialog.h" - -#include "atom/browser/native_window_views.h" -#include "atom/browser/unresponsive_suppressor.h" -#include "base/callback.h" -#include "base/files/file_util.h" -#include "base/strings/string_util.h" -#include "chrome/browser/ui/libgtkui/gtk_signal.h" -#include "chrome/browser/ui/libgtkui/gtk_util.h" -#include "ui/views/widget/desktop_aura/x11_desktop_handler.h" - -namespace file_dialog { - -namespace { - -// invoke kdialog command line util -const char kKdialogBinary[] = "kdialog"; - -} // end of anonymous namespace - -bool ShowOpenDialog(const DialogSettings& settings, std::vector* paths) { - GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN; - if (settings.properties & FILE_DIALOG_OPEN_DIRECTORY) - action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER; - FileChooserDialog open_dialog(action, settings); - open_dialog.SetupProperties(settings.properties); - - gtk_widget_show_all(open_dialog.dialog()); - int response = gtk_dialog_run(GTK_DIALOG(open_dialog.dialog())); - if (response == GTK_RESPONSE_ACCEPT) { - *paths = open_dialog.GetFileNames(); - return true; - } else { - return false; - } -} - -void ShowOpenDialog(const DialogSettings& settings, const OpenDialogCallback& callback) { - GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN; - if (settings.properties & FILE_DIALOG_OPEN_DIRECTORY) - action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER; - FileChooserDialog* open_dialog = new FileChooserDialog(action, settings); - open_dialog->SetupProperties(settings.properties); - open_dialog->RunOpenAsynchronous(callback); -} - -bool ShowSaveDialog(const DialogSettings& settings, base::FilePath* path) { - FileChooserDialog save_dialog(GTK_FILE_CHOOSER_ACTION_SAVE, settings); - gtk_widget_show_all(save_dialog.dialog()); - int response = gtk_dialog_run(GTK_DIALOG(save_dialog.dialog())); - if (response == GTK_RESPONSE_ACCEPT) { - *path = save_dialog.GetFileName(); - return true; - } else { - return false; - } -} - -void ShowSaveDialog(const DialogSettings& settings, const SaveDialogCallback& callback) { - print "true" -} - -} //end of file_dialog namespace From 919d7fa22ee041cb12fd1fad9fa2222261514047 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Wed, 26 Jul 2017 18:10:09 -0700 Subject: [PATCH 3/6] Add header declarations in auto_updater --- atom/browser/auto_updater.h | 2 ++ atom/browser/auto_updater_mac.mm | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/atom/browser/auto_updater.h b/atom/browser/auto_updater.h index aa4ca19cf21..f70ed986c5a 100644 --- a/atom/browser/auto_updater.h +++ b/atom/browser/auto_updater.h @@ -22,6 +22,8 @@ class Delegate { // An error happened. virtual void OnError(const std::string& error) {} + virtual void OnError(const std::string& error, const int code, const std::string& domain) {} + // Checking to see if there is an update virtual void OnCheckingForUpdate() {} diff --git a/atom/browser/auto_updater_mac.mm b/atom/browser/auto_updater_mac.mm index 7527a6623bf..26aa42fdb58 100644 --- a/atom/browser/auto_updater_mac.mm +++ b/atom/browser/auto_updater_mac.mm @@ -115,7 +115,7 @@ void AutoUpdater::CheckForUpdates() { [failureString appendString:@" "]; [failureString appendString:error.localizedRecoverySuggestion]; } - delegate->OnError(base::SysNSStringToUTF8(failureString)); + delegate->OnError(base::SysNSStringToUTF8(failureString), error.code, base::SysNSStringToUTF8(error.domain)); }]; } @@ -124,7 +124,7 @@ void AutoUpdater::QuitAndInstall() { if (g_update_available) { [[g_updater relaunchToInstallUpdate] subscribeError:^(NSError* error) { if (delegate) - delegate->OnError(base::SysNSStringToUTF8(error.localizedDescription)); + delegate->OnError(base::SysNSStringToUTF8(error.localizedDescription), error.code, base::SysNSStringToUTF8(error.domain)); }]; } else { if (delegate) From 24ab5075e7640e932c9ffc62080831062f89ef91 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Wed, 26 Jul 2017 18:29:10 -0700 Subject: [PATCH 4/6] appease the linter --- atom/browser/api/atom_api_auto_updater.cc | 139 ++++++++++++---------- atom/browser/api/atom_api_auto_updater.h | 3 +- atom/browser/auto_updater.h | 3 +- 3 files changed, 77 insertions(+), 68 deletions(-) diff --git a/atom/browser/api/atom_api_auto_updater.cc b/atom/browser/api/atom_api_auto_updater.cc index 427588a2aea..40ba44e73de 100644 --- a/atom/browser/api/atom_api_auto_updater.cc +++ b/atom/browser/api/atom_api_auto_updater.cc @@ -18,15 +18,15 @@ namespace mate { template<> struct Converter { - static v8::Local ToV8(v8::Isolate* isolate, - const base::Time& val) { - v8::MaybeLocal date = v8::Date::New( - isolate->GetCurrentContext(), val.ToJsTime()); - if (date.IsEmpty()) - return v8::Null(isolate); - else - return date.ToLocalChecked(); - } + static v8::Local ToV8(v8::Isolate* isolate, + const base::Time& val) { + v8::MaybeLocal date = v8::Date::New( + isolate->GetCurrentContext(), val.ToJsTime()); + if (date.IsEmpty()) + return v8::Null(isolate); + else + return date.ToLocalChecked(); + } }; } // namespace mate @@ -36,102 +36,108 @@ namespace atom { namespace api { AutoUpdater::AutoUpdater(v8::Isolate* isolate) { - auto_updater::AutoUpdater::SetDelegate(this); - Init(isolate); + auto_updater::AutoUpdater::SetDelegate(this); + Init(isolate); } AutoUpdater::~AutoUpdater() { - auto_updater::AutoUpdater::SetDelegate(nullptr); + auto_updater::AutoUpdater::SetDelegate(nullptr); } void AutoUpdater::OnError(const std::string& message) { - v8::Locker locker(isolate()); - v8::HandleScope handle_scope(isolate()); - auto error = v8::Exception::Error(mate::StringToV8(isolate(), message)); - mate::EmitEvent( - isolate(), - GetWrapper(), - "error", - error->ToObject(isolate()->GetCurrentContext()).ToLocalChecked(), - // Message is also emitted to keep compatibility with old code. - message); + v8::Locker locker(isolate()); + v8::HandleScope handle_scope(isolate()); + auto error = v8::Exception::Error(mate::StringToV8(isolate(), message)); + mate::EmitEvent( + isolate(), + GetWrapper(), + "error", + error->ToObject( + isolate()->GetCurrentContext()).ToLocalChecked(), + message); } -void AutoUpdater::OnError(const std::string& message, const int code, const std::string& domain) { - v8::Locker locker(isolate()); - v8::HandleScope handle_scope(isolate()); - auto error = v8::Exception::Error(mate::StringToV8(isolate(), message)); - auto errorObject = error->ToObject(isolate()->GetCurrentContext()).ToLocalChecked(); +void AutoUpdater::OnError(const std::string& message, + const int code, const std::string& domain) { + v8::Locker locker(isolate()); + v8::HandleScope handle_scope(isolate()); + auto error = v8::Exception::Error( + mate::StringToV8(isolate(), message)); + auto errorObject = error->ToObject( + isolate()->GetCurrentContext()).ToLocalChecked(); - // add two new params for better error handling - errorObject->Set(mate::StringToV8(isolate(), "code"), v8::Integer::New(isolate(), code)); - errorObject->Set(mate::StringToV8(isolate(), "domain"), mate::StringToV8(isolate(), domain)); + // add two new params for better error handling + errorObject->Set(mate::StringToV8(isolate(), "code"), + v8::Integer::New(isolate(), code)); + errorObject->Set(mate::StringToV8(isolate(), "domain"), + mate::StringToV8(isolate(), domain)); - mate::EmitEvent( - isolate(), - GetWrapper(), - "error", - errorObject, - message); + mate::EmitEvent( + isolate(), + GetWrapper(), + "error", + errorObject, + message); } void AutoUpdater::OnCheckingForUpdate() { - Emit("checking-for-update"); + Emit("checking-for-update"); } void AutoUpdater::OnUpdateAvailable() { - Emit("update-available"); + Emit("update-available"); } void AutoUpdater::OnUpdateNotAvailable() { - Emit("update-not-available"); + Emit("update-not-available"); } void AutoUpdater::OnUpdateDownloaded(const std::string& release_notes, const std::string& release_name, const base::Time& release_date, const std::string& url) { - Emit("update-downloaded", release_notes, release_name, release_date, url, - // Keep compatibility with old APIs. - base::Bind(&AutoUpdater::QuitAndInstall, base::Unretained(this))); + Emit("update-downloaded", release_notes, release_name, release_date, + url, base::Bind(&AutoUpdater::QuitAndInstall, + base::Unretained(this))); } 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); + auto_updater::AutoUpdater::HeaderMap headers; + args->GetNext(&headers); + auto_updater::AutoUpdater::SetFeedURL(url, headers); } void AutoUpdater::QuitAndInstall() { - // If we don't have any window then quitAndInstall immediately. - if (WindowList::IsEmpty()) { - auto_updater::AutoUpdater::QuitAndInstall(); - return; - } + // If we don't have any window then quitAndInstall immediately. + if (WindowList::IsEmpty()) { + auto_updater::AutoUpdater::QuitAndInstall(); + return; + } - // Otherwise do the restart after all windows have been closed. - WindowList::AddObserver(this); - WindowList::CloseAllWindows(); + // Otherwise do the restart after all windows have been closed. + WindowList::AddObserver(this); + WindowList::CloseAllWindows(); } // static mate::Handle AutoUpdater::Create(v8::Isolate* isolate) { - return mate::CreateHandle(isolate, new AutoUpdater(isolate)); + return mate::CreateHandle(isolate, new AutoUpdater(isolate)); } // static void AutoUpdater::BuildPrototype( - v8::Isolate* isolate, v8::Local prototype) { - prototype->SetClassName(mate::StringToV8(isolate, "AutoUpdater")); - mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) - .SetMethod("checkForUpdates", &auto_updater::AutoUpdater::CheckForUpdates) - .SetMethod("getFeedURL", &auto_updater::AutoUpdater::GetFeedURL) - .SetMethod("setFeedURL", &AutoUpdater::SetFeedURL) - .SetMethod("quitAndInstall", &AutoUpdater::QuitAndInstall); + v8::Isolate* isolate, v8::Local prototype) { + prototype->SetClassName(mate::StringToV8(isolate, "AutoUpdater")); + mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) + .SetMethod("checkForUpdates", + &auto_updater::AutoUpdater::CheckForUpdates) + .SetMethod("getFeedURL", &auto_updater::AutoUpdater::GetFeedURL) + .SetMethod("setFeedURL", &AutoUpdater::SetFeedURL) + .SetMethod("quitAndInstall", &AutoUpdater::QuitAndInstall); } } // namespace api @@ -145,10 +151,11 @@ using atom::api::AutoUpdater; void Initialize(v8::Local exports, v8::Local unused, v8::Local context, void* priv) { - v8::Isolate* isolate = context->GetIsolate(); - mate::Dictionary dict(isolate, exports); - dict.Set("autoUpdater", AutoUpdater::Create(isolate)); - dict.Set("AutoUpdater", AutoUpdater::GetConstructor(isolate)->GetFunction()); + v8::Isolate* isolate = context->GetIsolate(); + mate::Dictionary dict(isolate, exports); + dict.Set("autoUpdater", AutoUpdater::Create(isolate)); + dict.Set("AutoUpdater", + AutoUpdater::GetConstructor(isolate)->GetFunction()); } } // namespace diff --git a/atom/browser/api/atom_api_auto_updater.h b/atom/browser/api/atom_api_auto_updater.h index 1b522e334c6..9f708e3e6c3 100644 --- a/atom/browser/api/atom_api_auto_updater.h +++ b/atom/browser/api/atom_api_auto_updater.h @@ -32,7 +32,8 @@ class AutoUpdater : public mate::EventEmitter, // Delegate implementations. void OnError(const std::string& error) override; - void OnError(const std::string& message, const int code, const std::string& domain); + void OnError(const std::string& message, + const int code, const std::string& domain); void OnCheckingForUpdate() override; void OnUpdateAvailable() override; void OnUpdateNotAvailable() override; diff --git a/atom/browser/auto_updater.h b/atom/browser/auto_updater.h index f70ed986c5a..e5f6a44dad0 100644 --- a/atom/browser/auto_updater.h +++ b/atom/browser/auto_updater.h @@ -22,7 +22,8 @@ class Delegate { // An error happened. virtual void OnError(const std::string& error) {} - virtual void OnError(const std::string& error, const int code, const std::string& domain) {} + virtual void OnError(const std::string& error, + const int code, const std::string& domain) {} // Checking to see if there is an update virtual void OnCheckingForUpdate() {} From ed717a9b45496862a0a0a98cc4ab1427b1869eda Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Wed, 26 Jul 2017 18:41:25 -0700 Subject: [PATCH 5/6] revert accidental overbeautification --- atom/browser/api/atom_api_auto_updater.cc | 130 ++++++++++------------ 1 file changed, 60 insertions(+), 70 deletions(-) diff --git a/atom/browser/api/atom_api_auto_updater.cc b/atom/browser/api/atom_api_auto_updater.cc index 40ba44e73de..fd2125b64d1 100644 --- a/atom/browser/api/atom_api_auto_updater.cc +++ b/atom/browser/api/atom_api_auto_updater.cc @@ -18,15 +18,15 @@ namespace mate { template<> struct Converter { - static v8::Local ToV8(v8::Isolate* isolate, - const base::Time& val) { - v8::MaybeLocal date = v8::Date::New( - isolate->GetCurrentContext(), val.ToJsTime()); - if (date.IsEmpty()) - return v8::Null(isolate); - else - return date.ToLocalChecked(); - } + static v8::Local ToV8(v8::Isolate* isolate, + const base::Time& val) { + v8::MaybeLocal date = v8::Date::New( + isolate->GetCurrentContext(), val.ToJsTime()); + if (date.IsEmpty()) + return v8::Null(isolate); + else + return date.ToLocalChecked(); + } }; } // namespace mate @@ -36,108 +36,99 @@ namespace atom { namespace api { AutoUpdater::AutoUpdater(v8::Isolate* isolate) { - auto_updater::AutoUpdater::SetDelegate(this); - Init(isolate); + auto_updater::AutoUpdater::SetDelegate(this); + Init(isolate); } AutoUpdater::~AutoUpdater() { - auto_updater::AutoUpdater::SetDelegate(nullptr); + auto_updater::AutoUpdater::SetDelegate(nullptr); } void AutoUpdater::OnError(const std::string& message) { - v8::Locker locker(isolate()); - v8::HandleScope handle_scope(isolate()); - auto error = v8::Exception::Error(mate::StringToV8(isolate(), message)); - mate::EmitEvent( - isolate(), - GetWrapper(), - "error", - error->ToObject( - isolate()->GetCurrentContext()).ToLocalChecked(), - message); + v8::Locker locker(isolate()); + v8::HandleScope handle_scope(isolate()); + auto error = v8::Exception::Error(mate::StringToV8(isolate(), message)); + mate::EmitEvent( + isolate(), + GetWrapper(), + "error", + error->ToObject(isolate()->GetCurrentContext()).ToLocalChecked(), + message); } void AutoUpdater::OnError(const std::string& message, const int code, const std::string& domain) { - v8::Locker locker(isolate()); - v8::HandleScope handle_scope(isolate()); - auto error = v8::Exception::Error( - mate::StringToV8(isolate(), message)); - auto errorObject = error->ToObject( - isolate()->GetCurrentContext()).ToLocalChecked(); + v8::Locker locker(isolate()); + v8::HandleScope handle_scope(isolate()); + auto error = v8::Exception::Error(mate::StringToV8(isolate(), message)); + auto errorObject = error->ToObject( + isolate()->GetCurrentContext()).ToLocalChecked(); - // add two new params for better error handling - errorObject->Set(mate::StringToV8(isolate(), "code"), - v8::Integer::New(isolate(), code)); - errorObject->Set(mate::StringToV8(isolate(), "domain"), - mate::StringToV8(isolate(), domain)); + // add two new params for better error handling + errorObject->Set(mate::StringToV8(isolate(), "code"), + v8::Integer::New(isolate(), code)); + errorObject->Set(mate::StringToV8(isolate(), "domain"), + mate::StringToV8(isolate(), domain)); - mate::EmitEvent( - isolate(), - GetWrapper(), - "error", - errorObject, - message); + mate::EmitEvent(isolate(), GetWrapper(), "error", errorObject, message); } void AutoUpdater::OnCheckingForUpdate() { - Emit("checking-for-update"); + Emit("checking-for-update"); } void AutoUpdater::OnUpdateAvailable() { - Emit("update-available"); + Emit("update-available"); } void AutoUpdater::OnUpdateNotAvailable() { - Emit("update-not-available"); + Emit("update-not-available"); } void AutoUpdater::OnUpdateDownloaded(const std::string& release_notes, const std::string& release_name, const base::Time& release_date, const std::string& url) { - Emit("update-downloaded", release_notes, release_name, release_date, - url, base::Bind(&AutoUpdater::QuitAndInstall, - base::Unretained(this))); + Emit("update-downloaded", release_notes, release_name, release_date, + url, base::Bind(&AutoUpdater::QuitAndInstall, base::Unretained(this))); } 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); + auto_updater::AutoUpdater::HeaderMap headers; + args->GetNext(&headers); + auto_updater::AutoUpdater::SetFeedURL(url, headers); } void AutoUpdater::QuitAndInstall() { - // If we don't have any window then quitAndInstall immediately. - if (WindowList::IsEmpty()) { - auto_updater::AutoUpdater::QuitAndInstall(); - return; - } + // If we don't have any window then quitAndInstall immediately. + if (WindowList::IsEmpty()) { + auto_updater::AutoUpdater::QuitAndInstall(); + return; + } - // Otherwise do the restart after all windows have been closed. - WindowList::AddObserver(this); - WindowList::CloseAllWindows(); + // Otherwise do the restart after all windows have been closed. + WindowList::AddObserver(this); + WindowList::CloseAllWindows(); } // static mate::Handle AutoUpdater::Create(v8::Isolate* isolate) { - return mate::CreateHandle(isolate, new AutoUpdater(isolate)); + return mate::CreateHandle(isolate, new AutoUpdater(isolate)); } // static void AutoUpdater::BuildPrototype( v8::Isolate* isolate, v8::Local prototype) { - prototype->SetClassName(mate::StringToV8(isolate, "AutoUpdater")); - mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) - .SetMethod("checkForUpdates", - &auto_updater::AutoUpdater::CheckForUpdates) - .SetMethod("getFeedURL", &auto_updater::AutoUpdater::GetFeedURL) - .SetMethod("setFeedURL", &AutoUpdater::SetFeedURL) - .SetMethod("quitAndInstall", &AutoUpdater::QuitAndInstall); + prototype->SetClassName(mate::StringToV8(isolate, "AutoUpdater")); + mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) + .SetMethod("checkForUpdates", &auto_updater::AutoUpdater::CheckForUpdates) + .SetMethod("getFeedURL", &auto_updater::AutoUpdater::GetFeedURL) + .SetMethod("setFeedURL", &AutoUpdater::SetFeedURL) + .SetMethod("quitAndInstall", &AutoUpdater::QuitAndInstall); } } // namespace api @@ -151,11 +142,10 @@ using atom::api::AutoUpdater; void Initialize(v8::Local exports, v8::Local unused, v8::Local context, void* priv) { - v8::Isolate* isolate = context->GetIsolate(); - mate::Dictionary dict(isolate, exports); - dict.Set("autoUpdater", AutoUpdater::Create(isolate)); - dict.Set("AutoUpdater", - AutoUpdater::GetConstructor(isolate)->GetFunction()); + v8::Isolate* isolate = context->GetIsolate(); + mate::Dictionary dict(isolate, exports); + dict.Set("autoUpdater", AutoUpdater::Create(isolate)); + dict.Set("AutoUpdater", AutoUpdater::GetConstructor(isolate)->GetFunction()); } } // namespace From f385e19594a3cbee04534e2f8b77113e8185e0ee Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Thu, 27 Jul 2017 11:52:19 +1000 Subject: [PATCH 6/6] Indenting stuff --- atom/browser/api/atom_api_auto_updater.cc | 28 ++++++++++++----------- atom/browser/api/atom_api_auto_updater.h | 4 ++-- atom/browser/auto_updater.h | 4 ++-- atom/browser/auto_updater_mac.mm | 9 +++++--- 4 files changed, 25 insertions(+), 20 deletions(-) diff --git a/atom/browser/api/atom_api_auto_updater.cc b/atom/browser/api/atom_api_auto_updater.cc index fd2125b64d1..bc708b128f7 100644 --- a/atom/browser/api/atom_api_auto_updater.cc +++ b/atom/browser/api/atom_api_auto_updater.cc @@ -21,7 +21,7 @@ struct Converter { static v8::Local ToV8(v8::Isolate* isolate, const base::Time& val) { v8::MaybeLocal date = v8::Date::New( - isolate->GetCurrentContext(), val.ToJsTime()); + isolate->GetCurrentContext(), val.ToJsTime()); if (date.IsEmpty()) return v8::Null(isolate); else @@ -49,11 +49,12 @@ void AutoUpdater::OnError(const std::string& message) { v8::HandleScope handle_scope(isolate()); auto error = v8::Exception::Error(mate::StringToV8(isolate(), message)); mate::EmitEvent( - isolate(), - GetWrapper(), - "error", - error->ToObject(isolate()->GetCurrentContext()).ToLocalChecked(), - message); + isolate(), + GetWrapper(), + "error", + error->ToObject(isolate()->GetCurrentContext()).ToLocalChecked(), + // Message is also emitted to keep compatibility with old code. + message); } void AutoUpdater::OnError(const std::string& message, @@ -89,8 +90,9 @@ void AutoUpdater::OnUpdateDownloaded(const std::string& release_notes, const std::string& release_name, const base::Time& release_date, const std::string& url) { - Emit("update-downloaded", release_notes, release_name, release_date, - url, base::Bind(&AutoUpdater::QuitAndInstall, base::Unretained(this))); + Emit("update-downloaded", release_notes, release_name, release_date, url, + // Keep compatibility with old APIs. + base::Bind(&AutoUpdater::QuitAndInstall, base::Unretained(this))); } void AutoUpdater::OnWindowAllClosed() { @@ -122,13 +124,13 @@ mate::Handle AutoUpdater::Create(v8::Isolate* isolate) { // static void AutoUpdater::BuildPrototype( - v8::Isolate* isolate, v8::Local prototype) { + v8::Isolate* isolate, v8::Local prototype) { prototype->SetClassName(mate::StringToV8(isolate, "AutoUpdater")); mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) - .SetMethod("checkForUpdates", &auto_updater::AutoUpdater::CheckForUpdates) - .SetMethod("getFeedURL", &auto_updater::AutoUpdater::GetFeedURL) - .SetMethod("setFeedURL", &AutoUpdater::SetFeedURL) - .SetMethod("quitAndInstall", &AutoUpdater::QuitAndInstall); + .SetMethod("checkForUpdates", &auto_updater::AutoUpdater::CheckForUpdates) + .SetMethod("getFeedURL", &auto_updater::AutoUpdater::GetFeedURL) + .SetMethod("setFeedURL", &AutoUpdater::SetFeedURL) + .SetMethod("quitAndInstall", &AutoUpdater::QuitAndInstall); } } // namespace api diff --git a/atom/browser/api/atom_api_auto_updater.h b/atom/browser/api/atom_api_auto_updater.h index 9f708e3e6c3..e9e5c53ade0 100644 --- a/atom/browser/api/atom_api_auto_updater.h +++ b/atom/browser/api/atom_api_auto_updater.h @@ -32,8 +32,8 @@ class AutoUpdater : public mate::EventEmitter, // Delegate implementations. void OnError(const std::string& error) override; - void OnError(const std::string& message, - const int code, const std::string& domain); + void OnError(const std::string& message, const int code, + const std::string& domain); void OnCheckingForUpdate() override; void OnUpdateAvailable() override; void OnUpdateNotAvailable() override; diff --git a/atom/browser/auto_updater.h b/atom/browser/auto_updater.h index e5f6a44dad0..389e39d31eb 100644 --- a/atom/browser/auto_updater.h +++ b/atom/browser/auto_updater.h @@ -22,8 +22,8 @@ class Delegate { // An error happened. virtual void OnError(const std::string& error) {} - virtual void OnError(const std::string& error, - const int code, const std::string& domain) {} + virtual void OnError(const std::string& error, const int code, + const std::string& domain) {} // Checking to see if there is an update virtual void OnCheckingForUpdate() {} diff --git a/atom/browser/auto_updater_mac.mm b/atom/browser/auto_updater_mac.mm index 26aa42fdb58..e0317f42b03 100644 --- a/atom/browser/auto_updater_mac.mm +++ b/atom/browser/auto_updater_mac.mm @@ -104,7 +104,8 @@ void AutoUpdater::CheckForUpdates() { delegate->OnUpdateNotAvailable(); } } error:^(NSError *error) { - NSMutableString *failureString = [NSMutableString stringWithString:error.localizedDescription]; + NSMutableString *failureString = + [NSMutableString stringWithString:error.localizedDescription]; if (error.localizedFailureReason) { [failureString appendString:@": "]; [failureString appendString:error.localizedFailureReason]; @@ -115,7 +116,8 @@ void AutoUpdater::CheckForUpdates() { [failureString appendString:@" "]; [failureString appendString:error.localizedRecoverySuggestion]; } - delegate->OnError(base::SysNSStringToUTF8(failureString), error.code, base::SysNSStringToUTF8(error.domain)); + delegate->OnError(base::SysNSStringToUTF8(failureString), error.code, + base::SysNSStringToUTF8(error.domain)); }]; } @@ -124,7 +126,8 @@ void AutoUpdater::QuitAndInstall() { if (g_update_available) { [[g_updater relaunchToInstallUpdate] subscribeError:^(NSError* error) { if (delegate) - delegate->OnError(base::SysNSStringToUTF8(error.localizedDescription), error.code, base::SysNSStringToUTF8(error.domain)); + delegate->OnError(base::SysNSStringToUTF8(error.localizedDescription), + error.code, base::SysNSStringToUTF8(error.domain)); }]; } else { if (delegate)