Skip to content

Commit ed3c332

Browse files
zcbenztargos
authored andcommitted
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: #39712 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Shelley Vohr <shelley.vohr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 1a8a26d commit ed3c332

File tree

5 files changed

+16
-1
lines changed

5 files changed

+16
-1
lines changed

src/env-inl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,10 @@ inline bool Environment::tracks_unmanaged_fds() const {
906906
return flags_ & EnvironmentFlags::kTrackUnmanagedFds;
907907
}
908908

909+
inline bool Environment::hide_console_windows() const {
910+
return flags_ & EnvironmentFlags::kHideConsoleWindows;
911+
}
912+
909913
bool Environment::filehandle_close_warning() const {
910914
return emit_filehandle_warning_;
911915
}

src/env.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,7 @@ class Environment : public MemoryRetainer {
10581058
inline bool owns_process_state() const;
10591059
inline bool owns_inspector() const;
10601060
inline bool tracks_unmanaged_fds() const;
1061+
inline bool hide_console_windows() const;
10611062
inline uint64_t thread_id() const;
10621063
inline worker::Worker* worker_context() const;
10631064
Environment* worker_parent_env() const;

src/node.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,11 @@ enum Flags : uint64_t {
424424
kNoRegisterESMLoader = 1 << 3,
425425
// Set this flag to make Node.js track "raw" file descriptors, i.e. managed
426426
// by fs.open() and fs.close(), and close them during FreeEnvironment().
427-
kTrackUnmanagedFds = 1 << 4
427+
kTrackUnmanagedFds = 1 << 4,
428+
// Set this flag to force hiding console windows when spawning child
429+
// processes. This is usually used when embedding Node.js in GUI programs on
430+
// Windows.
431+
kHideConsoleWindows = 1 << 5
428432
};
429433
} // namespace EnvironmentFlags
430434

src/node_worker.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,8 @@ void Worker::New(const FunctionCallbackInfo<Value>& args) {
595595
CHECK(args[4]->IsBoolean());
596596
if (args[4]->IsTrue() || env->tracks_unmanaged_fds())
597597
worker->environment_flags_ |= EnvironmentFlags::kTrackUnmanagedFds;
598+
if (env->hide_console_windows())
599+
worker->environment_flags_ |= EnvironmentFlags::kHideConsoleWindows;
598600
}
599601

600602
void Worker::StartThread(const FunctionCallbackInfo<Value>& args) {

src/process_wrap.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,10 @@ class ProcessWrap : public HandleWrap {
238238
options.flags |= UV_PROCESS_WINDOWS_HIDE;
239239
}
240240

241+
if (env->hide_console_windows()) {
242+
options.flags |= UV_PROCESS_WINDOWS_HIDE_CONSOLE;
243+
}
244+
241245
// options.windows_verbatim_arguments
242246
Local<Value> wva_v =
243247
js_options->Get(context, env->windows_verbatim_arguments_string())

0 commit comments

Comments
 (0)