diff options
author | Cheng Zhao <zcbenz@gmail.com> | 2021-08-09 20:02:50 +0900 |
---|---|---|
committer | Michaƫl Zasso <targos@protonmail.com> | 2021-09-04 15:14:54 +0200 |
commit | ed3c33208954fbbb6d10dd33c9d1aaa230fdb0c5 (patch) | |
tree | e37eb247bc28e86c699167c65d21e76172efb02f /src | |
parent | 1a8a26d92e495df564e0f729ddbd671fc655406b (diff) | |
download | node-new-ed3c33208954fbbb6d10dd33c9d1aaa230fdb0c5.tar.gz |
build: add option to hide console window
Adds a Environment flag to allow embedders to set CREATE_NO_WINDOW
property when spawning processes, which is useful for GUI programs
that do not want to show console windows when running terminal
commands.
PR-URL: https://github.com/nodejs/node/pull/39712
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Shelley Vohr <shelley.vohr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/env-inl.h | 4 | ||||
-rw-r--r-- | src/env.h | 1 | ||||
-rw-r--r-- | src/node.h | 6 | ||||
-rw-r--r-- | src/node_worker.cc | 2 | ||||
-rw-r--r-- | src/process_wrap.cc | 4 |
5 files changed, 16 insertions, 1 deletions
diff --git a/src/env-inl.h b/src/env-inl.h index 7944eaa250..533a8284e9 100644 --- a/src/env-inl.h +++ b/src/env-inl.h @@ -906,6 +906,10 @@ inline bool Environment::tracks_unmanaged_fds() const { return flags_ & EnvironmentFlags::kTrackUnmanagedFds; } +inline bool Environment::hide_console_windows() const { + return flags_ & EnvironmentFlags::kHideConsoleWindows; +} + bool Environment::filehandle_close_warning() const { return emit_filehandle_warning_; } @@ -1058,6 +1058,7 @@ class Environment : public MemoryRetainer { inline bool owns_process_state() const; inline bool owns_inspector() const; inline bool tracks_unmanaged_fds() const; + inline bool hide_console_windows() const; inline uint64_t thread_id() const; inline worker::Worker* worker_context() const; Environment* worker_parent_env() const; diff --git a/src/node.h b/src/node.h index 2824de3bf8..8d4ec2276b 100644 --- a/src/node.h +++ b/src/node.h @@ -424,7 +424,11 @@ enum Flags : uint64_t { kNoRegisterESMLoader = 1 << 3, // Set this flag to make Node.js track "raw" file descriptors, i.e. managed // by fs.open() and fs.close(), and close them during FreeEnvironment(). - kTrackUnmanagedFds = 1 << 4 + kTrackUnmanagedFds = 1 << 4, + // Set this flag to force hiding console windows when spawning child + // processes. This is usually used when embedding Node.js in GUI programs on + // Windows. + kHideConsoleWindows = 1 << 5 }; } // namespace EnvironmentFlags diff --git a/src/node_worker.cc b/src/node_worker.cc index 6c1e7b99d1..db14616427 100644 --- a/src/node_worker.cc +++ b/src/node_worker.cc @@ -595,6 +595,8 @@ void Worker::New(const FunctionCallbackInfo<Value>& args) { CHECK(args[4]->IsBoolean()); if (args[4]->IsTrue() || env->tracks_unmanaged_fds()) worker->environment_flags_ |= EnvironmentFlags::kTrackUnmanagedFds; + if (env->hide_console_windows()) + worker->environment_flags_ |= EnvironmentFlags::kHideConsoleWindows; } void Worker::StartThread(const FunctionCallbackInfo<Value>& args) { diff --git a/src/process_wrap.cc b/src/process_wrap.cc index 45920c2603..679429286b 100644 --- a/src/process_wrap.cc +++ b/src/process_wrap.cc @@ -238,6 +238,10 @@ class ProcessWrap : public HandleWrap { options.flags |= UV_PROCESS_WINDOWS_HIDE; } + if (env->hide_console_windows()) { + options.flags |= UV_PROCESS_WINDOWS_HIDE_CONSOLE; + } + // options.windows_verbatim_arguments Local<Value> wva_v = js_options->Get(context, env->windows_verbatim_arguments_string()) |