refactor: eliminate duplicate C++ / JavaScript implementation of app.isPackaged (#29464)
This commit is contained in:
parent
f0d3e1d1cf
commit
44491b023a
4 changed files with 19 additions and 22 deletions
|
@ -55,14 +55,6 @@ Object.defineProperty(app, 'applicationMenu', {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
(app as any).isPackaged = (() => {
|
|
||||||
const execFile = path.basename(process.execPath).toLowerCase();
|
|
||||||
if (process.platform === 'win32') {
|
|
||||||
return execFile !== 'electron.exe';
|
|
||||||
}
|
|
||||||
return execFile !== 'electron';
|
|
||||||
})();
|
|
||||||
|
|
||||||
// The native implementation is not provided on non-windows platforms
|
// The native implementation is not provided on non-windows platforms
|
||||||
app.setAppUserModelId = app.setAppUserModelId || (() => {});
|
app.setAppUserModelId = app.setAppUserModelId || (() => {});
|
||||||
|
|
||||||
|
|
|
@ -936,6 +936,20 @@ void App::SetAppLogsPath(gin_helper::ErrorThrower thrower,
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// static
|
||||||
|
bool App::IsPackaged() {
|
||||||
|
base::FilePath exe_path;
|
||||||
|
base::PathService::Get(base::FILE_EXE, &exe_path);
|
||||||
|
base::FilePath::StringType base_name =
|
||||||
|
base::ToLowerASCII(exe_path.BaseName().value());
|
||||||
|
|
||||||
|
#if defined(OS_WIN)
|
||||||
|
return base_name != FILE_PATH_LITERAL("electron.exe");
|
||||||
|
#else
|
||||||
|
return base_name != FILE_PATH_LITERAL("electron");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
base::FilePath App::GetPath(gin_helper::ErrorThrower thrower,
|
base::FilePath App::GetPath(gin_helper::ErrorThrower thrower,
|
||||||
const std::string& name) {
|
const std::string& name) {
|
||||||
bool succeed = false;
|
bool succeed = false;
|
||||||
|
@ -1628,6 +1642,7 @@ gin::ObjectTemplateBuilder App::GetObjectTemplateBuilder(v8::Isolate* isolate) {
|
||||||
.SetMethod("isUnityRunning",
|
.SetMethod("isUnityRunning",
|
||||||
base::BindRepeating(&Browser::IsUnityRunning, browser))
|
base::BindRepeating(&Browser::IsUnityRunning, browser))
|
||||||
#endif
|
#endif
|
||||||
|
.SetProperty("isPackaged", &App::IsPackaged)
|
||||||
.SetMethod("setAppPath", &App::SetAppPath)
|
.SetMethod("setAppPath", &App::SetAppPath)
|
||||||
.SetMethod("getAppPath", &App::GetAppPath)
|
.SetMethod("getAppPath", &App::GetAppPath)
|
||||||
.SetMethod("setPath", &App::SetPath)
|
.SetMethod("setPath", &App::SetPath)
|
||||||
|
|
|
@ -75,6 +75,8 @@ class App : public ElectronBrowserClient::Delegate,
|
||||||
void RenderProcessReady(content::RenderProcessHost* host);
|
void RenderProcessReady(content::RenderProcessHost* host);
|
||||||
void RenderProcessExited(content::RenderProcessHost* host);
|
void RenderProcessExited(content::RenderProcessHost* host);
|
||||||
|
|
||||||
|
static bool IsPackaged();
|
||||||
|
|
||||||
App();
|
App();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include "content/public/browser/browser_thread.h"
|
#include "content/public/browser/browser_thread.h"
|
||||||
#include "content/public/common/content_paths.h"
|
#include "content/public/common/content_paths.h"
|
||||||
#include "electron/buildflags/buildflags.h"
|
#include "electron/buildflags/buildflags.h"
|
||||||
|
#include "shell/browser/api/electron_api_app.h"
|
||||||
#include "shell/common/api/electron_bindings.h"
|
#include "shell/common/api/electron_bindings.h"
|
||||||
#include "shell/common/electron_command_line.h"
|
#include "shell/common/electron_command_line.h"
|
||||||
#include "shell/common/gin_converters/file_path_converter.h"
|
#include "shell/common/gin_converters/file_path_converter.h"
|
||||||
|
@ -130,19 +131,6 @@ void stop_and_close_uv_loop(uv_loop_t* loop) {
|
||||||
|
|
||||||
bool g_is_initialized = false;
|
bool g_is_initialized = false;
|
||||||
|
|
||||||
bool IsPackagedApp() {
|
|
||||||
base::FilePath exe_path;
|
|
||||||
base::PathService::Get(base::FILE_EXE, &exe_path);
|
|
||||||
base::FilePath::StringType base_name =
|
|
||||||
base::ToLowerASCII(exe_path.BaseName().value());
|
|
||||||
|
|
||||||
#if defined(OS_WIN)
|
|
||||||
return base_name != FILE_PATH_LITERAL("electron.exe");
|
|
||||||
#else
|
|
||||||
return base_name != FILE_PATH_LITERAL("electron");
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void V8FatalErrorCallback(const char* location, const char* message) {
|
void V8FatalErrorCallback(const char* location, const char* message) {
|
||||||
LOG(ERROR) << "Fatal error in V8: " << location << " " << message;
|
LOG(ERROR) << "Fatal error in V8: " << location << " " << message;
|
||||||
|
|
||||||
|
@ -257,7 +245,7 @@ void SetNodeOptions(base::Environment* env) {
|
||||||
std::vector<std::string> parts = base::SplitString(
|
std::vector<std::string> parts = base::SplitString(
|
||||||
options, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
|
options, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
|
||||||
|
|
||||||
bool is_packaged_app = IsPackagedApp();
|
bool is_packaged_app = electron::api::App::IsPackaged();
|
||||||
|
|
||||||
for (const auto& part : parts) {
|
for (const auto& part : parts) {
|
||||||
// Strip off values passed to individual NODE_OPTIONs
|
// Strip off values passed to individual NODE_OPTIONs
|
||||||
|
|
Loading…
Reference in a new issue