]> khamidou — GitHub mirrors - electron.git/commitdiff
If a user calls makeSingleInstance more than once, just ignore it
authorPaul Betts <paul@paulbetts.org>
Wed, 21 Oct 2015 19:29:00 +0000 (12:29 -0700)
committerPaul Betts <paul@paulbetts.org>
Wed, 21 Oct 2015 19:29:00 +0000 (12:29 -0700)
atom/browser/api/atom_api_app.cc
atom/browser/browser.cc
atom/browser/browser.h

index b16e3460650fa2c4c8802f601424be8babb37985..96f1ce0253722aecfebcb8a9952e616c6cc0b2f0 100644 (file)
@@ -271,15 +271,15 @@ v8::Local<v8::Value> App::DefaultSession(v8::Isolate* isolate) {
 
 bool App::MakeSingleInstance(v8::Local<v8::Function> callback) {
   auto browser = Browser::Get();
-  single_instance_callback_ = callback;
+  if (browser->InitializeSingleInstance()) {
+    single_instance_callback_ = callback;
 
-  browser->InitializeSingleInstance();
+    ProcessSingleton::NotificationCallback cb;
+    mate::Converter<ProcessSingleton::NotificationCallback>::FromV8(
+        isolate(), single_instance_callback_, &cb);
 
-  ProcessSingleton::NotificationCallback cb;
-  mate::Converter<ProcessSingleton::NotificationCallback>::FromV8(
-      isolate(), single_instance_callback_, &cb);
-
-  browser->SetSingleInstanceCallback(cb);
+    browser->SetSingleInstanceCallback(cb);
+  }
 
   switch (browser->GetSingleInstanceResult()) {
     case ProcessSingleton::NotifyResult::PROCESS_NONE:
index c8d6104beae4b9abd354d76d9056c26da0bef746..6bfeae3c56b1aa9b1f5ae4451c484e3d5e833f87 100644 (file)
@@ -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() {
index 1ac4d03e095ae86b24116f831c77bcfdbb00d77b..f9b86b6924a0e31c8136d047359df8eac2b1612e 100644 (file)
@@ -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);