mirror of
https://github.com/electron/electron.git
synced 2026-05-02 03:00:22 -04:00
Implement app.relaunch on OS X
This commit is contained in:
@@ -21,10 +21,18 @@
|
||||
#include "ui/base/l10n/l10n_util.h"
|
||||
#include "ui/base/resource/resource_bundle.h"
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
#include "chrome/browser/mac/relauncher.h"
|
||||
#endif
|
||||
|
||||
namespace atom {
|
||||
|
||||
namespace {
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
const char* kRelauncherProcess = "relauncher";
|
||||
#endif
|
||||
|
||||
bool IsBrowserProcess(base::CommandLine* cmd) {
|
||||
std::string process_type = cmd->GetSwitchValueASCII(switches::kProcessType);
|
||||
return process_type.empty();
|
||||
@@ -146,6 +154,26 @@ content::ContentUtilityClient* AtomMainDelegate::CreateContentUtilityClient() {
|
||||
return utility_client_.get();
|
||||
}
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
int AtomMainDelegate::RunProcess(
|
||||
const std::string& process_type,
|
||||
const content::MainFunctionParams& main_function_params) {
|
||||
if (process_type == kRelauncherProcess)
|
||||
return mac_relauncher::internal::RelauncherMain(main_function_params);
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool AtomMainDelegate::ShouldSendMachPort(const std::string& process_type) {
|
||||
return process_type != kRelauncherProcess;
|
||||
}
|
||||
|
||||
bool AtomMainDelegate::DelaySandboxInitialization(
|
||||
const std::string& process_type) {
|
||||
return process_type == kRelauncherProcess;
|
||||
}
|
||||
#endif
|
||||
|
||||
std::unique_ptr<brightray::ContentClient>
|
||||
AtomMainDelegate::CreateContentClient() {
|
||||
return std::unique_ptr<brightray::ContentClient>(new AtomContentClient);
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
#ifndef ATOM_APP_ATOM_MAIN_DELEGATE_H_
|
||||
#define ATOM_APP_ATOM_MAIN_DELEGATE_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "brightray/common/main_delegate.h"
|
||||
#include "brightray/common/content_client.h"
|
||||
|
||||
@@ -22,6 +24,13 @@ class AtomMainDelegate : public brightray::MainDelegate {
|
||||
content::ContentBrowserClient* CreateContentBrowserClient() override;
|
||||
content::ContentRendererClient* CreateContentRendererClient() override;
|
||||
content::ContentUtilityClient* CreateContentUtilityClient() override;
|
||||
#if defined(OS_MACOSX)
|
||||
int RunProcess(
|
||||
const std::string& process_type,
|
||||
const content::MainFunctionParams& main_function_params) override;
|
||||
bool ShouldSendMachPort(const std::string& process_type) override;
|
||||
bool DelaySandboxInitialization(const std::string& process_type) override;
|
||||
#endif
|
||||
|
||||
// brightray::MainDelegate:
|
||||
std::unique_ptr<brightray::ContentClient> CreateContentClient() override;
|
||||
|
||||
@@ -450,6 +450,7 @@ void App::BuildPrototype(
|
||||
mate::ObjectTemplateBuilder(isolate, prototype)
|
||||
.SetMethod("quit", base::Bind(&Browser::Quit, browser))
|
||||
.SetMethod("exit", base::Bind(&Browser::Exit, browser))
|
||||
.SetMethod("relaunch", base::Bind(&Browser::Relaunch, browser))
|
||||
.SetMethod("focus", base::Bind(&Browser::Focus, browser))
|
||||
.SetMethod("getVersion", base::Bind(&Browser::GetVersion, browser))
|
||||
.SetMethod("setVersion", base::Bind(&Browser::SetVersion, browser))
|
||||
|
||||
@@ -53,6 +53,10 @@ class Browser : public WindowListObserver {
|
||||
// Cleanup everything and shutdown the application gracefully.
|
||||
void Shutdown();
|
||||
|
||||
// Restart the app.
|
||||
void Relaunch(const std::vector<std::string>& args,
|
||||
const std::string& app);
|
||||
|
||||
// Focus the application.
|
||||
void Focus();
|
||||
|
||||
|
||||
@@ -13,11 +13,22 @@
|
||||
#include "base/mac/foundation_util.h"
|
||||
#include "base/strings/sys_string_conversions.h"
|
||||
#include "brightray/common/application_info.h"
|
||||
#include "brightray/common/mac/main_application_bundle.h"
|
||||
#include "chrome/browser/mac/relauncher.h"
|
||||
#include "net/base/mac/url_conversions.h"
|
||||
#include "url/gurl.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
void Browser::Relaunch(const std::vector<std::string>& args,
|
||||
const std::string& app) {
|
||||
std::vector<std::string> args_with_app(args);
|
||||
args_with_app.insert(
|
||||
args_with_app.begin(),
|
||||
app.empty() ? brightray::MainApplicationBundlePath().value() : app);
|
||||
mac_relauncher::RelaunchApp(args_with_app);
|
||||
}
|
||||
|
||||
void Browser::Focus() {
|
||||
[[AtomApplication sharedApplication] activateIgnoringOtherApps:YES];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user