Cleanup command line handling code
This commit is contained in:
parent
d9c22396ea
commit
922def8ce0
4 changed files with 17 additions and 25 deletions
|
@ -6,13 +6,14 @@
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
void AtomCommandLine::Init(int argc,
|
// static
|
||||||
const char* const* argv) {
|
std::vector<std::string> AtomCommandLine::argv_;
|
||||||
|
|
||||||
|
// static
|
||||||
|
void AtomCommandLine::Init(int argc, const char* const* argv) {
|
||||||
for (int i = 0; i < argc; ++i) {
|
for (int i = 0; i < argc; ++i) {
|
||||||
argv_.push_back(argv[i]);
|
argv_.push_back(argv[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> AtomCommandLine::argv_;
|
|
||||||
|
|
||||||
} // namespace atom
|
} // namespace atom
|
||||||
|
|
|
@ -8,10 +8,11 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "base/logging.h"
|
#include "base/macros.h"
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
|
// Singleton to remember the original "argc" and "argv".
|
||||||
class AtomCommandLine {
|
class AtomCommandLine {
|
||||||
public:
|
public:
|
||||||
static void Init(int argc, const char* const* argv);
|
static void Init(int argc, const char* const* argv);
|
||||||
|
@ -20,7 +21,7 @@ class AtomCommandLine {
|
||||||
private:
|
private:
|
||||||
static std::vector<std::string> argv_;
|
static std::vector<std::string> argv_;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(AtomCommandLine);
|
DISALLOW_IMPLICIT_CONSTRUCTORS(AtomCommandLine);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace atom
|
} // namespace atom
|
||||||
|
|
|
@ -67,9 +67,6 @@ void AtomMainDelegate::PreSandboxStartup() {
|
||||||
if (!process_type.empty())
|
if (!process_type.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Add a flag to mark the start of switches added by atom-shell.
|
|
||||||
command_line->AppendSwitch("atom-shell-switches-start");
|
|
||||||
|
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
// Disable the LegacyRenderWidgetHostHWND, it made frameless windows unable
|
// Disable the LegacyRenderWidgetHostHWND, it made frameless windows unable
|
||||||
// to move and resize. We may consider enabling it again after upgraded to
|
// to move and resize. We may consider enabling it again after upgraded to
|
||||||
|
@ -84,9 +81,6 @@ void AtomMainDelegate::PreSandboxStartup() {
|
||||||
// Enable AVFoundation.
|
// Enable AVFoundation.
|
||||||
command_line->AppendSwitch("enable-avfoundation");
|
command_line->AppendSwitch("enable-avfoundation");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Add a flag to mark the end of switches added by atom-shell.
|
|
||||||
command_line->AppendSwitch("atom-shell-switches-end");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
content::ContentBrowserClient* AtomMainDelegate::CreateContentBrowserClient() {
|
content::ContentBrowserClient* AtomMainDelegate::CreateContentBrowserClient() {
|
||||||
|
|
|
@ -18,10 +18,6 @@
|
||||||
#include "native_mate/locker.h"
|
#include "native_mate/locker.h"
|
||||||
#include "native_mate/dictionary.h"
|
#include "native_mate/dictionary.h"
|
||||||
|
|
||||||
#if defined(OS_WIN)
|
|
||||||
#include "base/strings/utf_string_conversions.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "atom/common/node_includes.h"
|
#include "atom/common/node_includes.h"
|
||||||
|
|
||||||
using content::BrowserThread;
|
using content::BrowserThread;
|
||||||
|
@ -104,10 +100,11 @@ scoped_ptr<const char*[]> StringVectorToArgArray(
|
||||||
return array.Pass();
|
return array.Pass();
|
||||||
}
|
}
|
||||||
|
|
||||||
base::FilePath GetResourcesPath(base::CommandLine* command_line,
|
base::FilePath GetResourcesPath(bool is_browser) {
|
||||||
bool is_browser) {
|
auto command_line = base::CommandLine::ForCurrentProcess();
|
||||||
base::FilePath exec_path(command_line->argv()[0]);
|
base::FilePath exec_path(command_line->GetProgram());
|
||||||
PathService::Get(base::FILE_EXE, &exec_path);
|
PathService::Get(base::FILE_EXE, &exec_path);
|
||||||
|
|
||||||
base::FilePath resources_path =
|
base::FilePath resources_path =
|
||||||
#if defined(OS_MACOSX)
|
#if defined(OS_MACOSX)
|
||||||
is_browser ? exec_path.DirName().DirName().Append("Resources") :
|
is_browser ? exec_path.DirName().DirName().Append("Resources") :
|
||||||
|
@ -159,12 +156,11 @@ void NodeBindings::Initialize() {
|
||||||
node::Environment* NodeBindings::CreateEnvironment(
|
node::Environment* NodeBindings::CreateEnvironment(
|
||||||
v8::Handle<v8::Context> context) {
|
v8::Handle<v8::Context> context) {
|
||||||
auto args = AtomCommandLine::argv();
|
auto args = AtomCommandLine::argv();
|
||||||
auto command_line = base::CommandLine::ForCurrentProcess();
|
|
||||||
|
|
||||||
// Feed node the path to initialization script.
|
// Feed node the path to initialization script.
|
||||||
base::FilePath::StringType process_type = is_browser_ ?
|
base::FilePath::StringType process_type = is_browser_ ?
|
||||||
FILE_PATH_LITERAL("browser") : FILE_PATH_LITERAL("renderer");
|
FILE_PATH_LITERAL("browser") : FILE_PATH_LITERAL("renderer");
|
||||||
base::FilePath resources_path = GetResourcesPath(command_line, is_browser_);
|
base::FilePath resources_path = GetResourcesPath(is_browser_);
|
||||||
base::FilePath script_path =
|
base::FilePath script_path =
|
||||||
resources_path.Append(FILE_PATH_LITERAL("atom.asar"))
|
resources_path.Append(FILE_PATH_LITERAL("atom.asar"))
|
||||||
.Append(process_type)
|
.Append(process_type)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue