mirror of
https://github.com/electron/electron.git
synced 2026-01-09 15:38:08 -05:00
feat: allow macOS tray to maintain position (#47838)
* feat: allow macOS tray to maintain position * refactor: just use guid * test: fixup tests * docs: clarify UUID format
This commit is contained in:
@@ -7,6 +7,8 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "base/strings/string_util.h"
|
||||
#include "base/uuid.h"
|
||||
#include "gin/converter.h"
|
||||
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
@@ -36,18 +38,40 @@ typedef struct {
|
||||
|
||||
namespace gin {
|
||||
|
||||
template <>
|
||||
struct Converter<base::Uuid> {
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
base::Uuid* out) {
|
||||
std::string guid;
|
||||
if (!gin::ConvertFromV8(isolate, val, &guid))
|
||||
return false;
|
||||
|
||||
base::Uuid parsed = base::Uuid::ParseLowercase(base::ToLowerASCII(guid));
|
||||
if (!parsed.is_valid())
|
||||
return false;
|
||||
|
||||
*out = parsed;
|
||||
return true;
|
||||
}
|
||||
|
||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, base::Uuid val) {
|
||||
const std::string guid = val.AsLowercaseString();
|
||||
return gin::ConvertToV8(isolate, guid);
|
||||
}
|
||||
};
|
||||
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
template <>
|
||||
struct Converter<UUID> {
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
UUID* out) {
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
std::string guid;
|
||||
if (!gin::ConvertFromV8(isolate, val, &guid))
|
||||
return false;
|
||||
|
||||
UUID uid;
|
||||
|
||||
if (!guid.empty()) {
|
||||
if (guid[0] == '{' && guid[guid.length() - 1] == '}') {
|
||||
guid = guid.substr(1, guid.length() - 2);
|
||||
@@ -62,12 +86,8 @@ struct Converter<UUID> {
|
||||
}
|
||||
}
|
||||
return false;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, UUID val) {
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
const GUID GUID_NULL = {};
|
||||
if (val == GUID_NULL) {
|
||||
return v8::String::Empty(isolate);
|
||||
@@ -75,11 +95,9 @@ struct Converter<UUID> {
|
||||
std::wstring uid = base::win::WStringFromGUID(val);
|
||||
return StringToV8(isolate, base::SysWideToUTF8(uid));
|
||||
}
|
||||
#else
|
||||
return v8::Undefined(isolate);
|
||||
#endif
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
} // namespace gin
|
||||
|
||||
|
||||
Reference in New Issue
Block a user