fix: app.setLoginItemSettings
error getting swallowed by gin conversion (#41667)
* fix: errors getting swallowed by gin conversion Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> * fix: Windows build Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> * test: re-enable disabled test Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
This commit is contained in:
parent
21341a56a7
commit
0f1e52fafe
11 changed files with 211 additions and 154 deletions
86
shell/common/gin_converters/login_item_settings_converter.cc
Normal file
86
shell/common/gin_converters/login_item_settings_converter.cc
Normal file
|
@ -0,0 +1,86 @@
|
|||
// Copyright (c) 2024 Microsoft, GmbH.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "shell/common/gin_converters/login_item_settings_converter.h"
|
||||
|
||||
#if BUILDFLAG(IS_MAC)
|
||||
#include "base/mac/mac_util.h"
|
||||
#endif
|
||||
|
||||
#include "shell/browser/browser.h"
|
||||
#include "shell/common/gin_helper/dictionary.h"
|
||||
|
||||
namespace gin {
|
||||
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
bool Converter<electron::LaunchItem>::FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
electron::LaunchItem* out) {
|
||||
gin_helper::Dictionary dict;
|
||||
if (!ConvertFromV8(isolate, val, &dict))
|
||||
return false;
|
||||
|
||||
dict.Get("name", &(out->name));
|
||||
dict.Get("path", &(out->path));
|
||||
dict.Get("args", &(out->args));
|
||||
dict.Get("scope", &(out->scope));
|
||||
dict.Get("enabled", &(out->enabled));
|
||||
return true;
|
||||
}
|
||||
|
||||
v8::Local<v8::Value> Converter<electron::LaunchItem>::ToV8(
|
||||
v8::Isolate* isolate,
|
||||
electron::LaunchItem val) {
|
||||
auto dict = gin_helper::Dictionary::CreateEmpty(isolate);
|
||||
dict.Set("name", val.name);
|
||||
dict.Set("path", val.path);
|
||||
dict.Set("args", val.args);
|
||||
dict.Set("scope", val.scope);
|
||||
dict.Set("enabled", val.enabled);
|
||||
return dict.GetHandle();
|
||||
}
|
||||
#endif
|
||||
|
||||
bool Converter<electron::LoginItemSettings>::FromV8(
|
||||
v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
electron::LoginItemSettings* out) {
|
||||
gin_helper::Dictionary dict;
|
||||
if (!ConvertFromV8(isolate, val, &dict))
|
||||
return false;
|
||||
|
||||
dict.Get("openAtLogin", &(out->open_at_login));
|
||||
dict.Get("openAsHidden", &(out->open_as_hidden));
|
||||
dict.Get("path", &(out->path));
|
||||
dict.Get("args", &(out->args));
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
dict.Get("name", &(out->name));
|
||||
dict.Get("enabled", &(out->enabled));
|
||||
#elif BUILDFLAG(IS_MAC)
|
||||
dict.Get("serviceName", &(out->service_name));
|
||||
dict.Get("type", &(out->type));
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
v8::Local<v8::Value> Converter<electron::LoginItemSettings>::ToV8(
|
||||
v8::Isolate* isolate,
|
||||
electron::LoginItemSettings val) {
|
||||
auto dict = gin_helper::Dictionary::CreateEmpty(isolate);
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
dict.Set("launchItems", val.launch_items);
|
||||
dict.Set("executableWillLaunchAtLogin", val.executable_will_launch_at_login);
|
||||
#elif BUILDFLAG(IS_MAC)
|
||||
if (base::mac::MacOSMajorVersion() >= 13)
|
||||
dict.Set("status", val.status);
|
||||
#endif
|
||||
dict.Set("openAtLogin", val.open_at_login);
|
||||
dict.Set("openAsHidden", val.open_as_hidden);
|
||||
dict.Set("restoreState", val.restore_state);
|
||||
dict.Set("wasOpenedAtLogin", val.opened_at_login);
|
||||
dict.Set("wasOpenedAsHidden", val.opened_as_hidden);
|
||||
return dict.GetHandle();
|
||||
}
|
||||
|
||||
} // namespace gin
|
39
shell/common/gin_converters/login_item_settings_converter.h
Normal file
39
shell/common/gin_converters/login_item_settings_converter.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
// Copyright (c) 2024 Microsoft, GmbH.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef ELECTRON_SHELL_COMMON_GIN_CONVERTERS_LOGIN_ITEM_SETTINGS_CONVERTER_H_
|
||||
#define ELECTRON_SHELL_COMMON_GIN_CONVERTERS_LOGIN_ITEM_SETTINGS_CONVERTER_H_
|
||||
|
||||
#include "gin/converter.h"
|
||||
|
||||
namespace electron {
|
||||
struct LoginItemSettings;
|
||||
struct LaunchItem;
|
||||
} // namespace electron
|
||||
|
||||
namespace gin {
|
||||
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
template <>
|
||||
struct Converter<electron::LaunchItem> {
|
||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||
electron::LaunchItem val);
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
electron::LaunchItem* out);
|
||||
};
|
||||
#endif
|
||||
|
||||
template <>
|
||||
struct Converter<electron::LoginItemSettings> {
|
||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||
electron::LoginItemSettings val);
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
electron::LoginItemSettings* out);
|
||||
};
|
||||
|
||||
} // namespace gin
|
||||
|
||||
#endif // ELECTRON_SHELL_COMMON_GIN_CONVERTERS_LOGIN_ITEM_SETTINGS_CONVERTER_H_
|
Loading…
Add table
Add a link
Reference in a new issue