Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: add option to hide console window #39712

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/env-inl.h
Expand Up @@ -877,6 +877,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_;
}
Expand Down
1 change: 1 addition & 0 deletions src/env.h
Expand Up @@ -1198,6 +1198,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;
Expand Down
6 changes: 5 additions & 1 deletion src/node.h
Expand Up @@ -403,7 +403,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

Expand Down
2 changes: 2 additions & 0 deletions src/node_worker.cc
Expand Up @@ -558,6 +558,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) {
Expand Down
4 changes: 4 additions & 0 deletions src/process_wrap.cc
Expand Up @@ -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())
Expand Down