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>
This commit is contained in:
Cheng Zhao authored and Michaël Zasso committed 2021-09-04 15:14:54 +02:00
1 parent 1a8a26d92e
commit ed3c332089
5 files changed
+16 -1

No files matched your search

+4
View File
@@ -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_;
}
+1
View File
@@ -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;
+5 -1
View File
@@ -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
+2
View File
@@ -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) {
+4
View File
@@ -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())