refactor: eliminate duplicate C++ / JavaScript implementation of app.isPackaged (#29464)

This commit is contained in:
Milan Burda 2021-06-02 21:17:08 +02:00 committed by GitHub
parent f0d3e1d1cf
commit 44491b023a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 22 deletions

View file

@ -936,6 +936,20 @@ void App::SetAppLogsPath(gin_helper::ErrorThrower thrower,
}
#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,
const std::string& name) {
bool succeed = false;
@ -1628,6 +1642,7 @@ gin::ObjectTemplateBuilder App::GetObjectTemplateBuilder(v8::Isolate* isolate) {
.SetMethod("isUnityRunning",
base::BindRepeating(&Browser::IsUnityRunning, browser))
#endif
.SetProperty("isPackaged", &App::IsPackaged)
.SetMethod("setAppPath", &App::SetAppPath)
.SetMethod("getAppPath", &App::GetAppPath)
.SetMethod("setPath", &App::SetPath)