fix: net.isOnline always true in utility processes (#48111)

* fix: net.isOnline always true in utilityProcesses

* Update shell/services/node/node_service.cc

Co-authored-by: Robo <hop2deep@gmail.com>

---------

Co-authored-by: Robo <hop2deep@gmail.com>
This commit is contained in:
Shelley Vohr
2025-08-22 14:30:41 +02:00
committed by GitHub
parent 97b0280ad4
commit 6101025368
2 changed files with 8 additions and 0 deletions

View File

@@ -12,6 +12,7 @@
#include "base/process/process.h"
#include "base/strings/utf_string_conversions.h"
#include "electron/mas.h"
#include "net/base/network_change_notifier.h"
#include "services/network/public/cpp/wrapper_shared_url_loader_factory.h"
#include "services/network/public/mojom/host_resolver.mojom.h"
#include "services/network/public/mojom/network_context.mojom.h"
@@ -127,6 +128,10 @@ void NodeService::Initialize(
node_bindings_->Initialize(isolate, isolate->GetCurrentContext());
network_change_notifier_ = net::NetworkChangeNotifier::CreateIfNeeded(
net::NetworkChangeNotifier::CONNECTION_UNKNOWN,
net::NetworkChangeNotifier::ConnectionSubtype::SUBTYPE_UNKNOWN);
// Append program path for process.argv0
auto program = base::CommandLine::ForCurrentProcess()->GetProgram();
#if defined(OS_WIN)

View File

@@ -11,6 +11,7 @@
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "net/base/network_change_notifier.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/mojom/host_resolver.mojom.h"
#include "services/network/public/mojom/url_loader_factory.mojom-forward.h"
@@ -84,6 +85,8 @@ class NodeService : public node::mojom::NodeService {
// depends-on: js_env_'s isolate
std::shared_ptr<node::Environment> node_env_;
std::unique_ptr<net::NetworkChangeNotifier> network_change_notifier_;
};
} // namespace electron