Move all the browser.cc code over to atom_api_app.cc
This commit is contained in:
parent
658a9872fb
commit
938d68eb36
4 changed files with 34 additions and 85 deletions
|
@ -161,6 +161,14 @@ void App::OnWindowAllClosed() {
|
|||
|
||||
void App::OnQuit() {
|
||||
Emit("quit");
|
||||
|
||||
if (process_singleton_.get()) {
|
||||
if (process_notify_result_ == ProcessSingleton::PROCESS_NONE) {
|
||||
process_singleton_->Cleanup();
|
||||
}
|
||||
|
||||
process_singleton_.reset();
|
||||
}
|
||||
}
|
||||
|
||||
void App::OnOpenFile(bool* prevent_default, const std::string& file_path) {
|
||||
|
@ -187,6 +195,10 @@ void App::OnFinishLaunching() {
|
|||
AtomBrowserMainParts::Get()->browser_context());
|
||||
auto handle = Session::CreateFrom(isolate(), browser_context);
|
||||
default_session_.Reset(isolate(), handle.ToV8());
|
||||
|
||||
if (process_singleton_.get()) {
|
||||
process_singleton_->Unlock();
|
||||
}
|
||||
|
||||
Emit("ready");
|
||||
}
|
||||
|
@ -269,28 +281,32 @@ v8::Local<v8::Value> App::DefaultSession(v8::Isolate* isolate) {
|
|||
return v8::Local<v8::Value>::New(isolate, default_session_);
|
||||
}
|
||||
|
||||
bool App::MakeSingleInstance(v8::Local<v8::Function> callback) {
|
||||
auto browser = Browser::Get();
|
||||
if (browser->InitializeSingleInstance()) {
|
||||
single_instance_callback_ = callback;
|
||||
bool App::MakeSingleInstance(ProcessSingleton::NotificationCallback callback) {
|
||||
|
||||
base::FilePath userDir;
|
||||
PathService::Get(brightray::DIR_USER_DATA, &userDir);
|
||||
|
||||
if (!process_singleton_.get()) {
|
||||
auto browser = Browser::Get();
|
||||
process_singleton_.reset(new AtomProcessSingleton(userDir, callback));
|
||||
|
||||
if (browser->is_ready()) {
|
||||
process_singleton_->Unlock();
|
||||
}
|
||||
|
||||
ProcessSingleton::NotificationCallback cb;
|
||||
mate::Converter<ProcessSingleton::NotificationCallback>::FromV8(
|
||||
isolate(), single_instance_callback_, &cb);
|
||||
|
||||
browser->SetSingleInstanceCallback(cb);
|
||||
process_notify_result_ = process_singleton_->NotifyOtherProcessOrCreate();
|
||||
}
|
||||
|
||||
switch (browser->GetSingleInstanceResult()) {
|
||||
switch (process_notify_result_) {
|
||||
case ProcessSingleton::NotifyResult::PROCESS_NONE:
|
||||
return false;
|
||||
case ProcessSingleton::NotifyResult::LOCK_ERROR:
|
||||
case ProcessSingleton::NotifyResult::PROFILE_IN_USE:
|
||||
case ProcessSingleton::NotifyResult::PROCESS_NOTIFIED:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
mate::ObjectTemplateBuilder App::GetObjectTemplateBuilder(
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <string>
|
||||
|
||||
#include "atom/browser/api/event_emitter.h"
|
||||
#include "atom/browser/atom_process_singleton.h"
|
||||
#include "atom/browser/browser_observer.h"
|
||||
#include "atom/common/native_mate_converters/callback.h"
|
||||
#include "chrome/browser/process_singleton.h"
|
||||
|
@ -70,13 +71,15 @@ class App : public mate::EventEmitter,
|
|||
|
||||
void AllowNTLMCredentialsForAllDomains(bool should_allow);
|
||||
|
||||
bool MakeSingleInstance(v8::Local<v8::Function> callback);
|
||||
bool MakeSingleInstance(ProcessSingleton::NotificationCallback callback);
|
||||
|
||||
std::string GetLocale();
|
||||
v8::Local<v8::Value> DefaultSession(v8::Isolate* isolate);
|
||||
|
||||
v8::Local<v8::Function> single_instance_callback_;
|
||||
v8::Global<v8::Value> default_session_;
|
||||
|
||||
scoped_ptr<AtomProcessSingleton> process_singleton_;
|
||||
ProcessSingleton::NotifyResult process_notify_result_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(App);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue