Skip to content

Commit 3f284cf

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 <[email protected]> Reviewed-By: Shelley Vohr <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 3041d57 commit 3f284cf

File tree

5 files changed

+16
-1
lines changed

5 files changed

+16
-1
lines changed

src/env-inl.h

+4
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,10 @@ inline bool Environment::tracks_unmanaged_fds() const {
877877
return flags_ & EnvironmentFlags::kTrackUnmanagedFds;
878878
}
879879

880+
inline bool Environment::hide_console_windows() const {
881+
return flags_ & EnvironmentFlags::kHideConsoleWindows;
882+
}
883+
880884
bool Environment::filehandle_close_warning() const {
881885
return emit_filehandle_warning_;
882886
}

src/env.h

+1
Original file line numberDiff line numberDiff line change
@@ -1198,6 +1198,7 @@ class Environment : public MemoryRetainer {
11981198
inline bool owns_process_state() const;
11991199
inline bool owns_inspector() const;
12001200
inline bool tracks_unmanaged_fds() const;
1201+
inline bool hide_console_windows() const;
12011202
inline uint64_t thread_id() const;
12021203
inline worker::Worker* worker_context() const;
12031204
Environment* worker_parent_env() const;

src/node.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,11 @@ enum Flags : uint64_t {
402402
kNoRegisterESMLoader = 1 << 3,
403403
// Set this flag to make Node.js track "raw" file descriptors, i.e. managed
404404
// by fs.open() and fs.close(), and close them during FreeEnvironment().
405-
kTrackUnmanagedFds = 1 << 4
405+
kTrackUnmanagedFds = 1 << 4,
406+
// Set this flag to force hiding console windows when spawning child
407+
// processes. This is usually used when embedding Node.js in GUI programs on
408+
// Windows.
409+
kHideConsoleWindows = 1 << 5
406410
};
407411
} // namespace EnvironmentFlags
408412

src/node_worker.cc

+2
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,8 @@ void Worker::New(const FunctionCallbackInfo<Value>& args) {
558558
CHECK(args[4]->IsBoolean());
559559
if (args[4]->IsTrue() || env->tracks_unmanaged_fds())
560560
worker->environment_flags_ |= EnvironmentFlags::kTrackUnmanagedFds;
561+
if (env->hide_console_windows())
562+
worker->environment_flags_ |= EnvironmentFlags::kHideConsoleWindows;
561563
}
562564

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

src/process_wrap.cc

+4
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)