From a160891a27ddfa7ad68860ed45a61300f2ef2c5e Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Wed, 21 Oct 2015 12:29:00 -0700 Subject: [PATCH] If a user calls makeSingleInstance more than once, just ignore it --- atom/browser/api/atom_api_app.cc | 14 +++++++------- atom/browser/browser.cc | 7 ++++--- atom/browser/browser.h | 2 +- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index b16e346065..96f1ce0253 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -271,15 +271,15 @@ v8::Local App::DefaultSession(v8::Isolate* isolate) { bool App::MakeSingleInstance(v8::Local callback) { auto browser = Browser::Get(); - single_instance_callback_ = callback; + if (browser->InitializeSingleInstance()) { + single_instance_callback_ = callback; - browser->InitializeSingleInstance(); + ProcessSingleton::NotificationCallback cb; + mate::Converter::FromV8( + isolate(), single_instance_callback_, &cb); - ProcessSingleton::NotificationCallback cb; - mate::Converter::FromV8( - isolate(), single_instance_callback_, &cb); - - browser->SetSingleInstanceCallback(cb); + browser->SetSingleInstanceCallback(cb); + } switch (browser->GetSingleInstanceResult()) { case ProcessSingleton::NotifyResult::PROCESS_NONE: diff --git a/atom/browser/browser.cc b/atom/browser/browser.cc index c8d6104bea..6bfeae3c56 100644 --- a/atom/browser/browser.cc +++ b/atom/browser/browser.cc @@ -165,7 +165,7 @@ bool Browser::HandleBeforeQuit() { return !prevent_default; } -void Browser::InitializeSingleInstance() { +bool Browser::InitializeSingleInstance() { base::FilePath userDir; PathService::Get(brightray::DIR_USER_DATA, &userDir); @@ -174,11 +174,12 @@ void Browser::InitializeSingleInstance() { userDir, base::Bind(&Browser::OnProcessSingletonNotification, no_refcount_this))); - process_notify_result_ = process_singleton_->NotifyOtherProcessOrCreate(); - if (is_ready_) { process_singleton_->Unlock(); } + + process_notify_result_ = process_singleton_->NotifyOtherProcessOrCreate(); + return true; } ProcessSingleton::NotifyResult Browser::GetSingleInstanceResult() { diff --git a/atom/browser/browser.h b/atom/browser/browser.h index 1ac4d03e09..f9b86b6924 100644 --- a/atom/browser/browser.h +++ b/atom/browser/browser.h @@ -66,7 +66,7 @@ class Browser : public WindowListObserver { // Clear the recent documents list. void ClearRecentDocuments(); - void InitializeSingleInstance(); + bool InitializeSingleInstance(); ProcessSingleton::NotifyResult GetSingleInstanceResult(); void SetSingleInstanceCallback( ProcessSingleton::NotificationCallback callback);