refactor: check ELECTRON_ENABLE_LOGGING via native implementation (#25623)
This commit is contained in:
parent
fec1c0b68b
commit
b33f22601e
5 changed files with 59 additions and 1 deletions
|
@ -452,6 +452,7 @@ filenames = {
|
||||||
"shell/common/api/electron_api_clipboard.h",
|
"shell/common/api/electron_api_clipboard.h",
|
||||||
"shell/common/api/electron_api_clipboard_mac.mm",
|
"shell/common/api/electron_api_clipboard_mac.mm",
|
||||||
"shell/common/api/electron_api_command_line.cc",
|
"shell/common/api/electron_api_command_line.cc",
|
||||||
|
"shell/common/api/electron_api_environment.cc",
|
||||||
"shell/common/api/electron_api_key_weak_map.h",
|
"shell/common/api/electron_api_key_weak_map.h",
|
||||||
"shell/common/api/electron_api_native_image.cc",
|
"shell/common/api/electron_api_native_image.cc",
|
||||||
"shell/common/api/electron_api_native_image.h",
|
"shell/common/api/electron_api_native_image.h",
|
||||||
|
|
|
@ -461,8 +461,11 @@ const addReturnValueToEvent = (event: any) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const commandLine = process._linkedBinding('electron_common_command_line');
|
||||||
|
const environment = process._linkedBinding('electron_common_environment');
|
||||||
|
|
||||||
const loggingEnabled = () => {
|
const loggingEnabled = () => {
|
||||||
return process.env.ELECTRON_ENABLE_LOGGING || app.commandLine.hasSwitch('enable-logging');
|
return environment.hasVar('ELECTRON_ENABLE_LOGGING') || commandLine.hasSwitch('enable-logging');
|
||||||
};
|
};
|
||||||
|
|
||||||
// Add JavaScript wrappers for WebContents class.
|
// Add JavaScript wrappers for WebContents class.
|
||||||
|
|
45
shell/common/api/electron_api_environment.cc
Normal file
45
shell/common/api/electron_api_environment.cc
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
// Copyright (c) 2020 GitHub, Inc.
|
||||||
|
// Use of this source code is governed by the MIT license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
#include "base/environment.h"
|
||||||
|
#include "shell/common/gin_helper/dictionary.h"
|
||||||
|
#include "shell/common/node_includes.h"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
v8::Local<v8::Value> GetVar(v8::Isolate* isolate, const std::string& name) {
|
||||||
|
std::string value;
|
||||||
|
if (base::Environment::Create()->GetVar(name, &value)) {
|
||||||
|
return gin::StringToV8(isolate, value);
|
||||||
|
} else {
|
||||||
|
return v8::Null(isolate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool HasVar(const std::string& name) {
|
||||||
|
return base::Environment::Create()->HasVar(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SetVar(const std::string& name, const std::string& value) {
|
||||||
|
return base::Environment::Create()->SetVar(name, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool UnSetVar(const std::string& name) {
|
||||||
|
return base::Environment::Create()->UnSetVar(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Initialize(v8::Local<v8::Object> exports,
|
||||||
|
v8::Local<v8::Value> unused,
|
||||||
|
v8::Local<v8::Context> context,
|
||||||
|
void* priv) {
|
||||||
|
gin_helper::Dictionary dict(context->GetIsolate(), exports);
|
||||||
|
dict.SetMethod("getVar", &GetVar);
|
||||||
|
dict.SetMethod("hasVar", &HasVar);
|
||||||
|
dict.SetMethod("setVar", &SetVar);
|
||||||
|
dict.SetMethod("unSetVar", &UnSetVar);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
NODE_LINKED_MODULE_CONTEXT_AWARE(electron_common_environment, Initialize)
|
|
@ -67,6 +67,7 @@
|
||||||
V(electron_common_asar) \
|
V(electron_common_asar) \
|
||||||
V(electron_common_clipboard) \
|
V(electron_common_clipboard) \
|
||||||
V(electron_common_command_line) \
|
V(electron_common_command_line) \
|
||||||
|
V(electron_common_environment) \
|
||||||
V(electron_common_features) \
|
V(electron_common_features) \
|
||||||
V(electron_common_native_image) \
|
V(electron_common_native_image) \
|
||||||
V(electron_common_native_theme) \
|
V(electron_common_native_theme) \
|
||||||
|
|
8
typings/internal-ambient.d.ts
vendored
8
typings/internal-ambient.d.ts
vendored
|
@ -48,6 +48,13 @@ declare namespace NodeJS {
|
||||||
isSameOrigin(left: string, right: string): boolean;
|
isSameOrigin(left: string, right: string): boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface EnvironmentBinding {
|
||||||
|
getVar(name: string): string | null;
|
||||||
|
hasVar(name: string): boolean;
|
||||||
|
setVar(name: string, value: string): boolean;
|
||||||
|
unSetVar(name: string): boolean;
|
||||||
|
}
|
||||||
|
|
||||||
type AsarFileInfo = {
|
type AsarFileInfo = {
|
||||||
size: number;
|
size: number;
|
||||||
unpacked: boolean;
|
unpacked: boolean;
|
||||||
|
@ -137,6 +144,7 @@ declare namespace NodeJS {
|
||||||
_linkedBinding(name: 'electron_common_features'): FeaturesBinding;
|
_linkedBinding(name: 'electron_common_features'): FeaturesBinding;
|
||||||
_linkedBinding(name: 'electron_browser_app'): { app: Electron.App, App: Function };
|
_linkedBinding(name: 'electron_browser_app'): { app: Electron.App, App: Function };
|
||||||
_linkedBinding(name: 'electron_common_command_line'): Electron.CommandLine;
|
_linkedBinding(name: 'electron_common_command_line'): Electron.CommandLine;
|
||||||
|
_linkedBinding(name: 'electron_common_environment'): EnvironmentBinding;
|
||||||
_linkedBinding(name: 'electron_browser_desktop_capturer'): {
|
_linkedBinding(name: 'electron_browser_desktop_capturer'): {
|
||||||
createDesktopCapturer(): ElectronInternal.DesktopCapturer;
|
createDesktopCapturer(): ElectronInternal.DesktopCapturer;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue