mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
feat: add net.online / net.isOnline() (#21004)
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "gin/handle.h"
|
||||
#include "net/base/network_change_notifier.h"
|
||||
#include "services/network/public/cpp/features.h"
|
||||
#include "shell/browser/api/electron_api_url_loader.h"
|
||||
#include "shell/common/gin_helper/dictionary.h"
|
||||
@@ -14,6 +15,10 @@
|
||||
|
||||
namespace {
|
||||
|
||||
bool IsOnline() {
|
||||
return !net::NetworkChangeNotifier::IsOffline();
|
||||
}
|
||||
|
||||
bool IsValidHeaderName(std::string header_name) {
|
||||
return net::HttpUtil::IsValidHeaderName(header_name);
|
||||
}
|
||||
@@ -31,6 +36,7 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||
v8::Isolate* isolate = context->GetIsolate();
|
||||
|
||||
gin_helper::Dictionary dict(isolate, exports);
|
||||
dict.SetMethod("isOnline", &IsOnline);
|
||||
dict.SetMethod("isValidHeaderName", &IsValidHeaderName);
|
||||
dict.SetMethod("isValidHeaderValue", &IsValidHeaderValue);
|
||||
dict.SetMethod("createURLLoader", &SimpleURLLoaderWrapper::Create);
|
||||
|
||||
Reference in New Issue
Block a user