Merge pull request #3594 from atom/public-env
Add ELECTRON_RUN_AS_NODE environment variable
This commit is contained in:
commit
ed866900e7
3 changed files with 83 additions and 18 deletions
|
@ -5,7 +5,6 @@
|
||||||
#include "atom/app/atom_main.h"
|
#include "atom/app/atom_main.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -36,10 +35,33 @@
|
||||||
#include "base/at_exit.h"
|
#include "base/at_exit.h"
|
||||||
#include "base/i18n/icu_util.h"
|
#include "base/i18n/icu_util.h"
|
||||||
|
|
||||||
#if defined(OS_WIN)
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
const char* kRunAsNode = "ELECTRON_RUN_AS_NODE";
|
||||||
|
const char* kOldRunAsNode = "ATOM_SHELL_INTERNAL_RUN_AS_NODE";
|
||||||
|
|
||||||
|
bool IsEnvSet(const char* name) {
|
||||||
|
#if defined(OS_WIN)
|
||||||
|
size_t required_size;
|
||||||
|
getenv_s(&required_size, nullptr, 0, name);
|
||||||
|
return required_size != 0;
|
||||||
|
#else
|
||||||
|
char* indicator = getenv(name);
|
||||||
|
return indicator && indicator[0] != '\0';
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsRunAsNode() {
|
||||||
|
return IsEnvSet(kRunAsNode) || IsEnvSet(kOldRunAsNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(OS_WIN)
|
||||||
|
bool IsCygwin() {
|
||||||
|
std::string os;
|
||||||
|
scoped_ptr<base::Environment> env(base::Environment::Create());
|
||||||
|
return env->GetVar("OS", &os) && os == "cygwin";
|
||||||
|
}
|
||||||
|
|
||||||
// Win8.1 supports monitor-specific DPI scaling.
|
// Win8.1 supports monitor-specific DPI scaling.
|
||||||
bool SetProcessDpiAwarenessWrapper(PROCESS_DPI_AWARENESS value) {
|
bool SetProcessDpiAwarenessWrapper(PROCESS_DPI_AWARENESS value) {
|
||||||
typedef HRESULT(WINAPI *SetProcessDpiAwarenessPtr)(PROCESS_DPI_AWARENESS);
|
typedef HRESULT(WINAPI *SetProcessDpiAwarenessPtr)(PROCESS_DPI_AWARENESS);
|
||||||
|
@ -77,24 +99,22 @@ void EnableHighDPISupport() {
|
||||||
SetProcessDPIAwareWrapper();
|
SetProcessDPIAwareWrapper();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
#if defined(OS_WIN)
|
||||||
int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) {
|
int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) {
|
||||||
int argc = 0;
|
int argc = 0;
|
||||||
wchar_t** wargv = ::CommandLineToArgvW(::GetCommandLineW(), &argc);
|
wchar_t** wargv = ::CommandLineToArgvW(::GetCommandLineW(), &argc);
|
||||||
|
|
||||||
scoped_ptr<base::Environment> env(base::Environment::Create());
|
|
||||||
|
|
||||||
// Make output work in console if we are not in cygiwn.
|
// Make output work in console if we are not in cygiwn.
|
||||||
std::string os;
|
if (!IsCygwin() && !IsEnvSet("ELECTRON_NO_ATTACH_CONSOLE")) {
|
||||||
if (env->GetVar("OS", &os) && os != "cygwin") {
|
|
||||||
AttachConsole(ATTACH_PARENT_PROCESS);
|
AttachConsole(ATTACH_PARENT_PROCESS);
|
||||||
|
|
||||||
FILE* dontcare;
|
FILE* dontcare;
|
||||||
freopen_s(&dontcare, "CON", "w", stdout);
|
freopen_s(&dontcare, "CON", "w", stdout);
|
||||||
freopen_s(&dontcare, "CON", "w", stderr);
|
freopen_s(&dontcare, "CON", "w", stderr);
|
||||||
freopen_s(&dontcare, "CON", "r", stdin);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert argv to to UTF8
|
// Convert argv to to UTF8
|
||||||
|
@ -131,16 +151,12 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string node_indicator, crash_service_indicator;
|
if (IsRunAsNode()) {
|
||||||
if (env->GetVar("ATOM_SHELL_INTERNAL_RUN_AS_NODE", &node_indicator) &&
|
|
||||||
node_indicator == "1") {
|
|
||||||
// Now that argv conversion is done, we can finally start.
|
// Now that argv conversion is done, we can finally start.
|
||||||
base::AtExitManager atexit_manager;
|
base::AtExitManager atexit_manager;
|
||||||
base::i18n::InitializeICU();
|
base::i18n::InitializeICU();
|
||||||
return atom::NodeMain(argc, argv);
|
return atom::NodeMain(argc, argv);
|
||||||
} else if (env->GetVar("ATOM_SHELL_INTERNAL_CRASH_SERVICE",
|
} else if (IsEnvSet("ATOM_SHELL_INTERNAL_CRASH_SERVICE")) {
|
||||||
&crash_service_indicator) &&
|
|
||||||
crash_service_indicator == "1") {
|
|
||||||
return crash_service::Main(cmd);
|
return crash_service::Main(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,8 +180,7 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd, int) {
|
||||||
#elif defined(OS_LINUX) // defined(OS_WIN)
|
#elif defined(OS_LINUX) // defined(OS_WIN)
|
||||||
|
|
||||||
int main(int argc, const char* argv[]) {
|
int main(int argc, const char* argv[]) {
|
||||||
char* node_indicator = getenv("ATOM_SHELL_INTERNAL_RUN_AS_NODE");
|
if (IsRunAsNode()) {
|
||||||
if (node_indicator != NULL && strcmp(node_indicator, "1") == 0) {
|
|
||||||
base::i18n::InitializeICU();
|
base::i18n::InitializeICU();
|
||||||
base::AtExitManager atexit_manager;
|
base::AtExitManager atexit_manager;
|
||||||
return atom::NodeMain(argc, const_cast<char**>(argv));
|
return atom::NodeMain(argc, const_cast<char**>(argv));
|
||||||
|
@ -182,8 +197,7 @@ int main(int argc, const char* argv[]) {
|
||||||
#else // defined(OS_LINUX)
|
#else // defined(OS_LINUX)
|
||||||
|
|
||||||
int main(int argc, const char* argv[]) {
|
int main(int argc, const char* argv[]) {
|
||||||
char* node_indicator = getenv("ATOM_SHELL_INTERNAL_RUN_AS_NODE");
|
if (IsRunAsNode()) {
|
||||||
if (node_indicator != NULL && strcmp(node_indicator, "1") == 0) {
|
|
||||||
return AtomInitializeICUandStartNode(argc, const_cast<char**>(argv));
|
return AtomInitializeICUandStartNode(argc, const_cast<char**>(argv));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ select the tag that matches your version.
|
||||||
* [Synopsis](api/synopsis.md)
|
* [Synopsis](api/synopsis.md)
|
||||||
* [Process Object](api/process.md)
|
* [Process Object](api/process.md)
|
||||||
* [Supported Chrome Command Line Switches](api/chrome-command-line-switches.md)
|
* [Supported Chrome Command Line Switches](api/chrome-command-line-switches.md)
|
||||||
|
* [Environment Variables](api/environment-variables.md)
|
||||||
|
|
||||||
### Custom DOM Elements:
|
### Custom DOM Elements:
|
||||||
|
|
||||||
|
|
50
docs/api/environment-variables.md
Normal file
50
docs/api/environment-variables.md
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
# Environment variables
|
||||||
|
|
||||||
|
Some behaviors of Electron are controlled by environment variables, because they
|
||||||
|
are initialized earlier than command line and the app's code.
|
||||||
|
|
||||||
|
Examples on POSIX shells:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ export ELECTRON_ENABLE_LOGGING=true
|
||||||
|
$ electron
|
||||||
|
```
|
||||||
|
|
||||||
|
on Windows console:
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
> set ELECTRON_ENABLE_LOGGING=true
|
||||||
|
> electron
|
||||||
|
```
|
||||||
|
|
||||||
|
## `ELECTRON_RUN_AS_NODE`
|
||||||
|
|
||||||
|
Starts the process as a normal Node.js process.
|
||||||
|
|
||||||
|
## `ELECTRON_ENABLE_LOGGING`
|
||||||
|
|
||||||
|
Prints Chrome's internal logging to console.
|
||||||
|
|
||||||
|
## `ELECTRON_ENABLE_STACK_DUMPING`
|
||||||
|
|
||||||
|
When Electron crashed, prints the stack trace to console.
|
||||||
|
|
||||||
|
This environment variable will not work if `crashReporter` is started.
|
||||||
|
|
||||||
|
## `ELECTRON_DEFAULT_ERROR_MODE` _Windows_
|
||||||
|
|
||||||
|
Shows Windows's crash dialog when Electron crashed.
|
||||||
|
|
||||||
|
This environment variable will not work if `crashReporter` is started.
|
||||||
|
|
||||||
|
## `ELECTRON_NO_ATTACH_CONSOLE` _Windows_
|
||||||
|
|
||||||
|
Don't attach to current console session.
|
||||||
|
|
||||||
|
## `ELECTRON_FORCE_WINDOW_MENU_BAR` _Linux_
|
||||||
|
|
||||||
|
Don't use global menu bar on Linux.
|
||||||
|
|
||||||
|
## `ELECTRON_HIDE_INTERNAL_MODULES`
|
||||||
|
|
||||||
|
Turns off compatibility mode for old built-in modules like `require('ipc')`.
|
Loading…
Reference in a new issue