chore: remove redundant @available checks (#34407)
* chore: require macOS 10.13 for Chromium * chore: fix lint
This commit is contained in:
parent
000c3d981c
commit
539a53786c
9 changed files with 121 additions and 217 deletions
|
@ -423,17 +423,14 @@ std::string SystemPreferences::GetSystemColor(gin_helper::ErrorThrower thrower,
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SystemPreferences::CanPromptTouchID() {
|
bool SystemPreferences::CanPromptTouchID() {
|
||||||
if (@available(macOS 10.12.2, *)) {
|
base::scoped_nsobject<LAContext> context([[LAContext alloc] init]);
|
||||||
base::scoped_nsobject<LAContext> context([[LAContext alloc] init]);
|
if (![context
|
||||||
if (![context
|
canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
|
||||||
canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
|
error:nil])
|
||||||
error:nil])
|
return false;
|
||||||
return false;
|
if (@available(macOS 10.13.2, *))
|
||||||
if (@available(macOS 10.13.2, *))
|
return [context biometryType] == LABiometryTypeTouchID;
|
||||||
return [context biometryType] == LABiometryTypeTouchID;
|
return true;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
v8::Local<v8::Promise> SystemPreferences::PromptTouchID(
|
v8::Local<v8::Promise> SystemPreferences::PromptTouchID(
|
||||||
|
@ -442,46 +439,40 @@ v8::Local<v8::Promise> SystemPreferences::PromptTouchID(
|
||||||
gin_helper::Promise<void> promise(isolate);
|
gin_helper::Promise<void> promise(isolate);
|
||||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||||
|
|
||||||
if (@available(macOS 10.12.2, *)) {
|
base::scoped_nsobject<LAContext> context([[LAContext alloc] init]);
|
||||||
base::scoped_nsobject<LAContext> context([[LAContext alloc] init]);
|
base::ScopedCFTypeRef<SecAccessControlRef> access_control =
|
||||||
base::ScopedCFTypeRef<SecAccessControlRef> access_control =
|
base::ScopedCFTypeRef<SecAccessControlRef>(
|
||||||
base::ScopedCFTypeRef<SecAccessControlRef>(
|
SecAccessControlCreateWithFlags(
|
||||||
SecAccessControlCreateWithFlags(
|
kCFAllocatorDefault, kSecAttrAccessibleWhenUnlockedThisDeviceOnly,
|
||||||
kCFAllocatorDefault,
|
kSecAccessControlPrivateKeyUsage | kSecAccessControlUserPresence,
|
||||||
kSecAttrAccessibleWhenUnlockedThisDeviceOnly,
|
nullptr));
|
||||||
kSecAccessControlPrivateKeyUsage |
|
|
||||||
kSecAccessControlUserPresence,
|
|
||||||
nullptr));
|
|
||||||
|
|
||||||
scoped_refptr<base::SequencedTaskRunner> runner =
|
scoped_refptr<base::SequencedTaskRunner> runner =
|
||||||
base::SequencedTaskRunnerHandle::Get();
|
base::SequencedTaskRunnerHandle::Get();
|
||||||
|
|
||||||
|
__block gin_helper::Promise<void> p = std::move(promise);
|
||||||
|
[context
|
||||||
|
evaluateAccessControl:access_control
|
||||||
|
operation:LAAccessControlOperationUseKeySign
|
||||||
|
localizedReason:[NSString stringWithUTF8String:reason.c_str()]
|
||||||
|
reply:^(BOOL success, NSError* error) {
|
||||||
|
if (!success) {
|
||||||
|
std::string err_msg = std::string(
|
||||||
|
[error.localizedDescription UTF8String]);
|
||||||
|
runner->PostTask(
|
||||||
|
FROM_HERE,
|
||||||
|
base::BindOnce(
|
||||||
|
gin_helper::Promise<void>::RejectPromise,
|
||||||
|
std::move(p), std::move(err_msg)));
|
||||||
|
} else {
|
||||||
|
runner->PostTask(
|
||||||
|
FROM_HERE,
|
||||||
|
base::BindOnce(
|
||||||
|
gin_helper::Promise<void>::ResolvePromise,
|
||||||
|
std::move(p)));
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
|
||||||
__block gin_helper::Promise<void> p = std::move(promise);
|
|
||||||
[context
|
|
||||||
evaluateAccessControl:access_control
|
|
||||||
operation:LAAccessControlOperationUseKeySign
|
|
||||||
localizedReason:[NSString stringWithUTF8String:reason.c_str()]
|
|
||||||
reply:^(BOOL success, NSError* error) {
|
|
||||||
if (!success) {
|
|
||||||
std::string err_msg = std::string(
|
|
||||||
[error.localizedDescription UTF8String]);
|
|
||||||
runner->PostTask(
|
|
||||||
FROM_HERE,
|
|
||||||
base::BindOnce(
|
|
||||||
gin_helper::Promise<void>::RejectPromise,
|
|
||||||
std::move(p), std::move(err_msg)));
|
|
||||||
} else {
|
|
||||||
runner->PostTask(
|
|
||||||
FROM_HERE,
|
|
||||||
base::BindOnce(
|
|
||||||
gin_helper::Promise<void>::ResolvePromise,
|
|
||||||
std::move(p)));
|
|
||||||
}
|
|
||||||
}];
|
|
||||||
} else {
|
|
||||||
promise.RejectWithErrorMessage(
|
|
||||||
"This API is not available on macOS versions older than 10.12.2");
|
|
||||||
}
|
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -529,8 +520,7 @@ std::string SystemPreferences::GetColor(gin_helper::ErrorThrower thrower,
|
||||||
} else if (color == "quaternary-label") {
|
} else if (color == "quaternary-label") {
|
||||||
sysColor = [NSColor quaternaryLabelColor];
|
sysColor = [NSColor quaternaryLabelColor];
|
||||||
} else if (color == "scrubber-textured-background") {
|
} else if (color == "scrubber-textured-background") {
|
||||||
if (@available(macOS 10.12.2, *))
|
sysColor = [NSColor scrubberTexturedBackgroundColor];
|
||||||
sysColor = [NSColor scrubberTexturedBackgroundColor];
|
|
||||||
} else if (color == "secondary-label") {
|
} else if (color == "secondary-label") {
|
||||||
sysColor = [NSColor secondaryLabelColor];
|
sysColor = [NSColor secondaryLabelColor];
|
||||||
} else if (color == "selected-content-background") {
|
} else if (color == "selected-content-background") {
|
||||||
|
|
|
@ -19,30 +19,6 @@
|
||||||
|
|
||||||
#import <UserNotifications/UserNotifications.h>
|
#import <UserNotifications/UserNotifications.h>
|
||||||
|
|
||||||
#if BUILDFLAG(USE_ALLOCATOR_SHIM)
|
|
||||||
// On macOS 10.12, the IME system attempts to allocate a 2^64 size buffer,
|
|
||||||
// which would typically cause an OOM crash. To avoid this, the problematic
|
|
||||||
// method is swizzled out and the make-OOM-fatal bit is disabled for the
|
|
||||||
// duration of the original call. https://crbug.com/654695
|
|
||||||
static base::mac::ScopedObjCClassSwizzler* g_swizzle_imk_input_session;
|
|
||||||
@interface OOMDisabledIMKInputSession : NSObject
|
|
||||||
@end
|
|
||||||
@implementation OOMDisabledIMKInputSession
|
|
||||||
- (void)_coreAttributesFromRange:(NSRange)range
|
|
||||||
whichAttributes:(long long)attributes // NOLINT(runtime/int)
|
|
||||||
completionHandler:(void (^)(void))block {
|
|
||||||
// The allocator flag is per-process, so other threads may temporarily
|
|
||||||
// not have fatal OOM occur while this method executes, but it is better
|
|
||||||
// than crashing when using IME.
|
|
||||||
base::allocator::SetCallNewHandlerOnMallocFailure(false);
|
|
||||||
g_swizzle_imk_input_session->InvokeOriginal<
|
|
||||||
void, NSRange, long long, void (^)(void)>( // NOLINT(runtime/int)
|
|
||||||
self, _cmd, range, attributes, block);
|
|
||||||
base::allocator::SetCallNewHandlerOnMallocFailure(true);
|
|
||||||
}
|
|
||||||
@end
|
|
||||||
#endif // BUILDFLAG(USE_ALLOCATOR_SHIM)
|
|
||||||
|
|
||||||
static NSDictionary* UNNotificationResponseToNSDictionary(
|
static NSDictionary* UNNotificationResponseToNSDictionary(
|
||||||
UNNotificationResponse* response) API_AVAILABLE(macosx(10.14)) {
|
UNNotificationResponse* response) API_AVAILABLE(macosx(10.14)) {
|
||||||
// [response isKindOfClass:[UNNotificationResponse class]]
|
// [response isKindOfClass:[UNNotificationResponse class]]
|
||||||
|
@ -109,16 +85,6 @@ static NSDictionary* UNNotificationResponseToNSDictionary(
|
||||||
|
|
||||||
electron::Browser::Get()->DidFinishLaunching(
|
electron::Browser::Get()->DidFinishLaunching(
|
||||||
electron::NSDictionaryToDictionaryValue(notification_info));
|
electron::NSDictionaryToDictionaryValue(notification_info));
|
||||||
|
|
||||||
#if BUILDFLAG(USE_ALLOCATOR_SHIM)
|
|
||||||
// Disable fatal OOM to hack around an OS bug https://crbug.com/654695.
|
|
||||||
if (base::mac::IsOS10_12()) {
|
|
||||||
g_swizzle_imk_input_session = new base::mac::ScopedObjCClassSwizzler(
|
|
||||||
NSClassFromString(@"IMKInputSession"),
|
|
||||||
[OOMDisabledIMKInputSession class],
|
|
||||||
@selector(_coreAttributesFromRange:whichAttributes:completionHandler:));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)applicationDidBecomeActive:(NSNotification*)notification {
|
- (void)applicationDidBecomeActive:(NSNotification*)notification {
|
||||||
|
|
|
@ -220,11 +220,9 @@
|
||||||
withLocal:product.priceLocale] UTF8String];
|
withLocal:product.priceLocale] UTF8String];
|
||||||
|
|
||||||
// Currency Information
|
// Currency Information
|
||||||
if (@available(macOS 10.12, *)) {
|
if (product.priceLocale.currencyCode != nil) {
|
||||||
if (product.priceLocale.currencyCode != nil) {
|
productStruct.currencyCode =
|
||||||
productStruct.currencyCode =
|
[product.priceLocale.currencyCode UTF8String];
|
||||||
[product.priceLocale.currencyCode UTF8String];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -392,13 +392,9 @@ NativeWindowMac::NativeWindowMac(const gin_helper::Dictionary& options,
|
||||||
// Create a tab only if tabbing identifier is specified and window has
|
// Create a tab only if tabbing identifier is specified and window has
|
||||||
// a native title bar.
|
// a native title bar.
|
||||||
if (tabbingIdentifier.empty() || transparent() || !has_frame()) {
|
if (tabbingIdentifier.empty() || transparent() || !has_frame()) {
|
||||||
if (@available(macOS 10.12, *)) {
|
[window_ setTabbingMode:NSWindowTabbingModeDisallowed];
|
||||||
[window_ setTabbingMode:NSWindowTabbingModeDisallowed];
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (@available(macOS 10.12, *)) {
|
[window_ setTabbingIdentifier:base::SysUTF8ToNSString(tabbingIdentifier)];
|
||||||
[window_ setTabbingIdentifier:base::SysUTF8ToNSString(tabbingIdentifier)];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resize to content bounds.
|
// Resize to content bounds.
|
||||||
|
@ -1564,68 +1560,51 @@ void NativeWindowMac::UpdateFrame() {
|
||||||
|
|
||||||
void NativeWindowMac::SetTouchBar(
|
void NativeWindowMac::SetTouchBar(
|
||||||
std::vector<gin_helper::PersistentDictionary> items) {
|
std::vector<gin_helper::PersistentDictionary> items) {
|
||||||
if (@available(macOS 10.12.2, *)) {
|
touch_bar_.reset([[ElectronTouchBar alloc]
|
||||||
touch_bar_.reset([[ElectronTouchBar alloc]
|
initWithDelegate:window_delegate_.get()
|
||||||
initWithDelegate:window_delegate_.get()
|
window:this
|
||||||
window:this
|
settings:std::move(items)]);
|
||||||
settings:std::move(items)]);
|
[window_ setTouchBar:nil];
|
||||||
[window_ setTouchBar:nil];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindowMac::RefreshTouchBarItem(const std::string& item_id) {
|
void NativeWindowMac::RefreshTouchBarItem(const std::string& item_id) {
|
||||||
if (@available(macOS 10.12.2, *)) {
|
if (touch_bar_ && [window_ touchBar])
|
||||||
if (touch_bar_ && [window_ touchBar])
|
[touch_bar_ refreshTouchBarItem:[window_ touchBar] id:item_id];
|
||||||
[touch_bar_ refreshTouchBarItem:[window_ touchBar] id:item_id];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindowMac::SetEscapeTouchBarItem(
|
void NativeWindowMac::SetEscapeTouchBarItem(
|
||||||
gin_helper::PersistentDictionary item) {
|
gin_helper::PersistentDictionary item) {
|
||||||
if (@available(macOS 10.12.2, *)) {
|
if (touch_bar_ && [window_ touchBar])
|
||||||
if (touch_bar_ && [window_ touchBar])
|
[touch_bar_ setEscapeTouchBarItem:std::move(item)
|
||||||
[touch_bar_ setEscapeTouchBarItem:std::move(item)
|
forTouchBar:[window_ touchBar]];
|
||||||
forTouchBar:[window_ touchBar]];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindowMac::SelectPreviousTab() {
|
void NativeWindowMac::SelectPreviousTab() {
|
||||||
if (@available(macOS 10.12, *)) {
|
[window_ selectPreviousTab:nil];
|
||||||
[window_ selectPreviousTab:nil];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindowMac::SelectNextTab() {
|
void NativeWindowMac::SelectNextTab() {
|
||||||
if (@available(macOS 10.12, *)) {
|
[window_ selectNextTab:nil];
|
||||||
[window_ selectNextTab:nil];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindowMac::MergeAllWindows() {
|
void NativeWindowMac::MergeAllWindows() {
|
||||||
if (@available(macOS 10.12, *)) {
|
[window_ mergeAllWindows:nil];
|
||||||
[window_ mergeAllWindows:nil];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindowMac::MoveTabToNewWindow() {
|
void NativeWindowMac::MoveTabToNewWindow() {
|
||||||
if (@available(macOS 10.12, *)) {
|
[window_ moveTabToNewWindow:nil];
|
||||||
[window_ moveTabToNewWindow:nil];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindowMac::ToggleTabBar() {
|
void NativeWindowMac::ToggleTabBar() {
|
||||||
if (@available(macOS 10.12, *)) {
|
[window_ toggleTabBar:nil];
|
||||||
[window_ toggleTabBar:nil];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NativeWindowMac::AddTabbedWindow(NativeWindow* window) {
|
bool NativeWindowMac::AddTabbedWindow(NativeWindow* window) {
|
||||||
if (window_ == window->GetNativeWindow().GetNativeNSWindow()) {
|
if (window_ == window->GetNativeWindow().GetNativeNSWindow()) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
if (@available(macOS 10.12, *))
|
[window_ addTabbedWindow:window->GetNativeWindow().GetNativeNSWindow()
|
||||||
[window_ addTabbedWindow:window->GetNativeWindow().GetNativeNSWindow()
|
ordered:NSWindowAbove];
|
||||||
ordered:NSWindowAbove];
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -422,10 +422,8 @@ static base::scoped_nsobject<NSMenu> recentDocumentsMenuSwap_;
|
||||||
[item setKeyEquivalentModifierMask:modifier_mask];
|
[item setKeyEquivalentModifierMask:modifier_mask];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (@available(macOS 10.13, *)) {
|
[(id)item
|
||||||
[(id)item
|
setAllowsKeyEquivalentWhenHidden:(model->WorksWhenHiddenAt(index))];
|
||||||
setAllowsKeyEquivalentWhenHidden:(model->WorksWhenHiddenAt(index))];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set menu item's role.
|
// Set menu item's role.
|
||||||
[item setTarget:self];
|
[item setTarget:self];
|
||||||
|
|
|
@ -56,7 +56,7 @@ bool ScopedDisableResize::disable_resize_ = false;
|
||||||
return [super contentRectForFrameRect:frameRect];
|
return [super contentRectForFrameRect:frameRect];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSTouchBar*)makeTouchBar API_AVAILABLE(macosx(10.12.2)) {
|
- (NSTouchBar*)makeTouchBar {
|
||||||
if (shell_->touch_bar())
|
if (shell_->touch_bar())
|
||||||
return [shell_->touch_bar() makeTouchBar];
|
return [shell_->touch_bar() makeTouchBar];
|
||||||
else
|
else
|
||||||
|
|
|
@ -329,8 +329,7 @@ using FullScreenTransitionState =
|
||||||
#pragma mark - NSTouchBarDelegate
|
#pragma mark - NSTouchBarDelegate
|
||||||
|
|
||||||
- (NSTouchBarItem*)touchBar:(NSTouchBar*)touchBar
|
- (NSTouchBarItem*)touchBar:(NSTouchBar*)touchBar
|
||||||
makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier
|
makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier {
|
||||||
API_AVAILABLE(macosx(10.12.2)) {
|
|
||||||
if (touchBar && shell_->touch_bar())
|
if (touchBar && shell_->touch_bar())
|
||||||
return [shell_->touch_bar() makeItemForIdentifier:identifier];
|
return [shell_->touch_bar() makeItemForIdentifier:identifier];
|
||||||
else
|
else
|
||||||
|
|
|
@ -29,19 +29,16 @@
|
||||||
window:(electron::NativeWindow*)window
|
window:(electron::NativeWindow*)window
|
||||||
settings:(std::vector<gin_helper::PersistentDictionary>)settings;
|
settings:(std::vector<gin_helper::PersistentDictionary>)settings;
|
||||||
|
|
||||||
- (NSTouchBar*)makeTouchBar API_AVAILABLE(macosx(10.12.2));
|
- (NSTouchBar*)makeTouchBar;
|
||||||
- (NSTouchBar*)touchBarFromItemIdentifiers:(NSMutableArray*)items
|
- (NSTouchBar*)touchBarFromItemIdentifiers:(NSMutableArray*)items;
|
||||||
API_AVAILABLE(macosx(10.12.2));
|
|
||||||
- (NSMutableArray*)identifiersFromSettings:
|
- (NSMutableArray*)identifiersFromSettings:
|
||||||
(const std::vector<gin_helper::PersistentDictionary>&)settings;
|
(const std::vector<gin_helper::PersistentDictionary>&)settings;
|
||||||
- (void)refreshTouchBarItem:(NSTouchBar*)touchBar
|
- (void)refreshTouchBarItem:(NSTouchBar*)touchBar
|
||||||
id:(const std::string&)item_id
|
id:(const std::string&)item_id;
|
||||||
API_AVAILABLE(macosx(10.12.2));
|
|
||||||
- (void)addNonDefaultTouchBarItems:
|
- (void)addNonDefaultTouchBarItems:
|
||||||
(const std::vector<gin_helper::PersistentDictionary>&)items;
|
(const std::vector<gin_helper::PersistentDictionary>&)items;
|
||||||
- (void)setEscapeTouchBarItem:(gin_helper::PersistentDictionary)item
|
- (void)setEscapeTouchBarItem:(gin_helper::PersistentDictionary)item
|
||||||
forTouchBar:(NSTouchBar*)touchBar
|
forTouchBar:(NSTouchBar*)touchBar;
|
||||||
API_AVAILABLE(macosx(10.12.2));
|
|
||||||
|
|
||||||
- (NSString*)idFromIdentifier:(NSString*)identifier
|
- (NSString*)idFromIdentifier:(NSString*)identifier
|
||||||
withPrefix:(NSString*)prefix;
|
withPrefix:(NSString*)prefix;
|
||||||
|
@ -52,47 +49,35 @@
|
||||||
|
|
||||||
// Selector actions
|
// Selector actions
|
||||||
- (void)buttonAction:(id)sender;
|
- (void)buttonAction:(id)sender;
|
||||||
- (void)colorPickerAction:(id)sender API_AVAILABLE(macosx(10.12.2));
|
- (void)colorPickerAction:(id)sender;
|
||||||
- (void)sliderAction:(id)sender API_AVAILABLE(macosx(10.12.2));
|
- (void)sliderAction:(id)sender;
|
||||||
|
|
||||||
// Helpers to create touch bar items
|
// Helpers to create touch bar items
|
||||||
- (NSTouchBarItem*)makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier
|
- (NSTouchBarItem*)makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier;
|
||||||
API_AVAILABLE(macosx(10.12.2));
|
|
||||||
- (NSTouchBarItem*)makeButtonForID:(NSString*)id
|
- (NSTouchBarItem*)makeButtonForID:(NSString*)id
|
||||||
withIdentifier:(NSString*)identifier
|
withIdentifier:(NSString*)identifier;
|
||||||
API_AVAILABLE(macosx(10.12.2));
|
|
||||||
- (NSTouchBarItem*)makeLabelForID:(NSString*)id
|
- (NSTouchBarItem*)makeLabelForID:(NSString*)id
|
||||||
withIdentifier:(NSString*)identifier
|
withIdentifier:(NSString*)identifier;
|
||||||
API_AVAILABLE(macosx(10.12.2));
|
|
||||||
- (NSTouchBarItem*)makeColorPickerForID:(NSString*)id
|
- (NSTouchBarItem*)makeColorPickerForID:(NSString*)id
|
||||||
withIdentifier:(NSString*)identifier
|
withIdentifier:(NSString*)identifier;
|
||||||
API_AVAILABLE(macosx(10.12.2));
|
|
||||||
- (NSTouchBarItem*)makeSliderForID:(NSString*)id
|
- (NSTouchBarItem*)makeSliderForID:(NSString*)id
|
||||||
withIdentifier:(NSString*)identifier
|
withIdentifier:(NSString*)identifier;
|
||||||
API_AVAILABLE(macosx(10.12.2));
|
|
||||||
- (NSTouchBarItem*)makePopoverForID:(NSString*)id
|
- (NSTouchBarItem*)makePopoverForID:(NSString*)id
|
||||||
withIdentifier:(NSString*)identifier
|
withIdentifier:(NSString*)identifier;
|
||||||
API_AVAILABLE(macosx(10.12.2));
|
|
||||||
- (NSTouchBarItem*)makeGroupForID:(NSString*)id
|
- (NSTouchBarItem*)makeGroupForID:(NSString*)id
|
||||||
withIdentifier:(NSString*)identifier
|
withIdentifier:(NSString*)identifier;
|
||||||
API_AVAILABLE(macosx(10.12.2));
|
|
||||||
|
|
||||||
// Helpers to update touch bar items
|
// Helpers to update touch bar items
|
||||||
- (void)updateButton:(NSCustomTouchBarItem*)item
|
- (void)updateButton:(NSCustomTouchBarItem*)item
|
||||||
withSettings:(const gin_helper::PersistentDictionary&)settings
|
withSettings:(const gin_helper::PersistentDictionary&)settings;
|
||||||
API_AVAILABLE(macosx(10.12.2));
|
|
||||||
- (void)updateLabel:(NSCustomTouchBarItem*)item
|
- (void)updateLabel:(NSCustomTouchBarItem*)item
|
||||||
withSettings:(const gin_helper::PersistentDictionary&)settings
|
withSettings:(const gin_helper::PersistentDictionary&)settings;
|
||||||
API_AVAILABLE(macosx(10.12.2));
|
|
||||||
- (void)updateColorPicker:(NSColorPickerTouchBarItem*)item
|
- (void)updateColorPicker:(NSColorPickerTouchBarItem*)item
|
||||||
withSettings:(const gin_helper::PersistentDictionary&)settings
|
withSettings:(const gin_helper::PersistentDictionary&)settings;
|
||||||
API_AVAILABLE(macosx(10.12.2));
|
|
||||||
- (void)updateSlider:(NSSliderTouchBarItem*)item
|
- (void)updateSlider:(NSSliderTouchBarItem*)item
|
||||||
withSettings:(const gin_helper::PersistentDictionary&)settings
|
withSettings:(const gin_helper::PersistentDictionary&)settings;
|
||||||
API_AVAILABLE(macosx(10.12.2));
|
|
||||||
- (void)updatePopover:(NSPopoverTouchBarItem*)item
|
- (void)updatePopover:(NSPopoverTouchBarItem*)item
|
||||||
withSettings:(const gin_helper::PersistentDictionary&)settings
|
withSettings:(const gin_helper::PersistentDictionary&)settings;
|
||||||
API_AVAILABLE(macosx(10.12.2));
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
|
@ -67,38 +67,36 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item";
|
||||||
|
|
||||||
bool has_other_items_proxy = false;
|
bool has_other_items_proxy = false;
|
||||||
|
|
||||||
if (@available(macOS 10.12.2, *)) {
|
for (const auto& item : dicts) {
|
||||||
for (const auto& item : dicts) {
|
std::string type;
|
||||||
std::string type;
|
std::string item_id;
|
||||||
std::string item_id;
|
if (item.Get("type", &type) && item.Get("id", &item_id)) {
|
||||||
if (item.Get("type", &type) && item.Get("id", &item_id)) {
|
NSTouchBarItemIdentifier identifier = nil;
|
||||||
NSTouchBarItemIdentifier identifier = nil;
|
if (type == "spacer") {
|
||||||
if (type == "spacer") {
|
std::string size;
|
||||||
std::string size;
|
item.Get("size", &size);
|
||||||
item.Get("size", &size);
|
if (size == "large") {
|
||||||
if (size == "large") {
|
identifier = NSTouchBarItemIdentifierFixedSpaceLarge;
|
||||||
identifier = NSTouchBarItemIdentifierFixedSpaceLarge;
|
} else if (size == "flexible") {
|
||||||
} else if (size == "flexible") {
|
identifier = NSTouchBarItemIdentifierFlexibleSpace;
|
||||||
identifier = NSTouchBarItemIdentifierFlexibleSpace;
|
|
||||||
} else {
|
|
||||||
identifier = NSTouchBarItemIdentifierFixedSpaceSmall;
|
|
||||||
}
|
|
||||||
} else if (type == "other_items_proxy") {
|
|
||||||
identifier = NSTouchBarItemIdentifierOtherItemsProxy;
|
|
||||||
has_other_items_proxy = true;
|
|
||||||
} else {
|
} else {
|
||||||
identifier = [self identifierFromID:item_id type:type];
|
identifier = NSTouchBarItemIdentifierFixedSpaceSmall;
|
||||||
}
|
}
|
||||||
|
} else if (type == "other_items_proxy") {
|
||||||
|
identifier = NSTouchBarItemIdentifierOtherItemsProxy;
|
||||||
|
has_other_items_proxy = true;
|
||||||
|
} else {
|
||||||
|
identifier = [self identifierFromID:item_id type:type];
|
||||||
|
}
|
||||||
|
|
||||||
if (identifier) {
|
if (identifier) {
|
||||||
settings_[item_id] = item;
|
settings_[item_id] = item;
|
||||||
[identifiers addObject:identifier];
|
[identifiers addObject:identifier];
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!has_other_items_proxy)
|
|
||||||
[identifiers addObject:NSTouchBarItemIdentifierOtherItemsProxy];
|
|
||||||
}
|
}
|
||||||
|
if (!has_other_items_proxy)
|
||||||
|
[identifiers addObject:NSTouchBarItemIdentifierOtherItemsProxy];
|
||||||
|
|
||||||
return identifiers;
|
return identifiers;
|
||||||
}
|
}
|
||||||
|
@ -140,8 +138,7 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item";
|
||||||
- (void)refreshTouchBarItem:(NSTouchBar*)touchBar
|
- (void)refreshTouchBarItem:(NSTouchBar*)touchBar
|
||||||
id:(NSTouchBarItemIdentifier)identifier
|
id:(NSTouchBarItemIdentifier)identifier
|
||||||
withType:(const std::string&)item_type
|
withType:(const std::string&)item_type
|
||||||
withSettings:(const gin_helper::PersistentDictionary&)settings
|
withSettings:(const gin_helper::PersistentDictionary&)settings {
|
||||||
API_AVAILABLE(macosx(10.12.2)) {
|
|
||||||
NSTouchBarItem* item = [touchBar itemForIdentifier:identifier];
|
NSTouchBarItem* item = [touchBar itemForIdentifier:identifier];
|
||||||
if (!item)
|
if (!item)
|
||||||
return;
|
return;
|
||||||
|
@ -289,8 +286,7 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item";
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)scrubber:(NSScrubber*)scrubber
|
- (void)scrubber:(NSScrubber*)scrubber
|
||||||
didSelectItemAtIndex:(NSInteger)selectedIndex
|
didSelectItemAtIndex:(NSInteger)selectedIndex {
|
||||||
API_AVAILABLE(macosx(10.12.2)) {
|
|
||||||
base::DictionaryValue details;
|
base::DictionaryValue details;
|
||||||
details.SetInteger("selectedIndex", selectedIndex);
|
details.SetInteger("selectedIndex", selectedIndex);
|
||||||
details.SetString("type", "select");
|
details.SetString("type", "select");
|
||||||
|
@ -299,8 +295,7 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item";
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)scrubber:(NSScrubber*)scrubber
|
- (void)scrubber:(NSScrubber*)scrubber
|
||||||
didHighlightItemAtIndex:(NSInteger)highlightedIndex
|
didHighlightItemAtIndex:(NSInteger)highlightedIndex {
|
||||||
API_AVAILABLE(macosx(10.12.2)) {
|
|
||||||
base::DictionaryValue details;
|
base::DictionaryValue details;
|
||||||
details.SetInteger("highlightedIndex", highlightedIndex);
|
details.SetInteger("highlightedIndex", highlightedIndex);
|
||||||
details.SetString("type", "highlight");
|
details.SetString("type", "highlight");
|
||||||
|
@ -592,8 +587,7 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item";
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)updateGroup:(NSGroupTouchBarItem*)item
|
- (void)updateGroup:(NSGroupTouchBarItem*)item
|
||||||
withSettings:(const gin_helper::PersistentDictionary&)settings
|
withSettings:(const gin_helper::PersistentDictionary&)settings {
|
||||||
API_AVAILABLE(macosx(10.12.2)) {
|
|
||||||
v8::Isolate* isolate = electron::JavascriptEnvironment::GetIsolate();
|
v8::Isolate* isolate = electron::JavascriptEnvironment::GetIsolate();
|
||||||
v8::HandleScope handle_scope(isolate);
|
v8::HandleScope handle_scope(isolate);
|
||||||
|
|
||||||
|
@ -609,8 +603,7 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item";
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSTouchBarItem*)makeSegmentedControlForID:(NSString*)id
|
- (NSTouchBarItem*)makeSegmentedControlForID:(NSString*)id
|
||||||
withIdentifier:(NSString*)identifier
|
withIdentifier:(NSString*)identifier {
|
||||||
API_AVAILABLE(macosx(10.12.2)) {
|
|
||||||
std::string s_id([id UTF8String]);
|
std::string s_id([id UTF8String]);
|
||||||
if (![self hasItemWithID:s_id])
|
if (![self hasItemWithID:s_id])
|
||||||
return nil;
|
return nil;
|
||||||
|
@ -635,8 +628,8 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item";
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)updateSegmentedControl:(NSCustomTouchBarItem*)item
|
- (void)updateSegmentedControl:(NSCustomTouchBarItem*)item
|
||||||
withSettings:(const gin_helper::PersistentDictionary&)settings
|
withSettings:
|
||||||
API_AVAILABLE(macosx(10.12.2)) {
|
(const gin_helper::PersistentDictionary&)settings {
|
||||||
NSSegmentedControl* control = item.view;
|
NSSegmentedControl* control = item.view;
|
||||||
|
|
||||||
std::string segmentStyle;
|
std::string segmentStyle;
|
||||||
|
@ -697,8 +690,7 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item";
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSTouchBarItem*)makeScrubberForID:(NSString*)id
|
- (NSTouchBarItem*)makeScrubberForID:(NSString*)id
|
||||||
withIdentifier:(NSString*)identifier
|
withIdentifier:(NSString*)identifier {
|
||||||
API_AVAILABLE(macosx(10.12.2)) {
|
|
||||||
std::string s_id([id UTF8String]);
|
std::string s_id([id UTF8String]);
|
||||||
if (![self hasItemWithID:s_id])
|
if (![self hasItemWithID:s_id])
|
||||||
return nil;
|
return nil;
|
||||||
|
@ -729,8 +721,7 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item";
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)updateScrubber:(NSCustomTouchBarItem*)item
|
- (void)updateScrubber:(NSCustomTouchBarItem*)item
|
||||||
withSettings:(const gin_helper::PersistentDictionary&)settings
|
withSettings:(const gin_helper::PersistentDictionary&)settings {
|
||||||
API_AVAILABLE(macosx(10.12.2)) {
|
|
||||||
NSScrubber* scrubber = item.view;
|
NSScrubber* scrubber = item.view;
|
||||||
|
|
||||||
bool showsArrowButtons = false;
|
bool showsArrowButtons = false;
|
||||||
|
@ -780,8 +771,7 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item";
|
||||||
[scrubber reloadData];
|
[scrubber reloadData];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSInteger)numberOfItemsForScrubber:(NSScrubber*)scrubber
|
- (NSInteger)numberOfItemsForScrubber:(NSScrubber*)scrubber {
|
||||||
API_AVAILABLE(macosx(10.12.2)) {
|
|
||||||
std::string s_id([[scrubber identifier] UTF8String]);
|
std::string s_id([[scrubber identifier] UTF8String]);
|
||||||
if (![self hasItemWithID:s_id])
|
if (![self hasItemWithID:s_id])
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -796,8 +786,7 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item";
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSScrubberItemView*)scrubber:(NSScrubber*)scrubber
|
- (NSScrubberItemView*)scrubber:(NSScrubber*)scrubber
|
||||||
viewForItemAtIndex:(NSInteger)index
|
viewForItemAtIndex:(NSInteger)index {
|
||||||
API_AVAILABLE(macosx(10.12.2)) {
|
|
||||||
std::string s_id([[scrubber identifier] UTF8String]);
|
std::string s_id([[scrubber identifier] UTF8String]);
|
||||||
if (![self hasItemWithID:s_id])
|
if (![self hasItemWithID:s_id])
|
||||||
return nil;
|
return nil;
|
||||||
|
@ -839,7 +828,7 @@ static NSString* const ImageScrubberItemIdentifier = @"scrubber.image.item";
|
||||||
|
|
||||||
- (NSSize)scrubber:(NSScrubber*)scrubber
|
- (NSSize)scrubber:(NSScrubber*)scrubber
|
||||||
layout:(NSScrubberFlowLayout*)layout
|
layout:(NSScrubberFlowLayout*)layout
|
||||||
sizeForItemAtIndex:(NSInteger)itemIndex API_AVAILABLE(macosx(10.12.2)) {
|
sizeForItemAtIndex:(NSInteger)itemIndex {
|
||||||
NSInteger width = 50;
|
NSInteger width = 50;
|
||||||
NSInteger height = 30;
|
NSInteger height = 30;
|
||||||
NSInteger margin = 15;
|
NSInteger margin = 15;
|
||||||
|
|
Loading…
Reference in a new issue