Skip to content

Instantly share code, notes, and snippets.

@username0x0a
Created October 2, 2021 18:01
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save username0x0a/b07f4ed2ec66f0228396b16bb1a681ff to your computer and use it in GitHub Desktop.
Save username0x0a/b07f4ed2ec66f0228396b16bb1a681ff to your computer and use it in GitHub Desktop.
Safari 15 Stable Back & Forward buttons in the single-line Unified tab bar
#import <Cocoa/Cocoa.h>
#import <objc/runtime.h>
@interface Injector: NSView @end
@implementation Injector
+ (void)load {
[super load];
if (![[NSBundle mainBundle].bundleIdentifier containsString:@"SafariTechnologyPreview"])
return;
NSLog(@"[SAFARI15FIXER] Swizzling in %@", [NSBundle mainBundle].bundleIdentifier);
Class toolbarClass = NSClassFromString(@"ToolbarController");
SEL orgSel = NSSelectorFromString(@"updateBackForwardState");
Method orgMethod = class_getInstanceMethod(toolbarClass, orgSel);
Method newMethod = class_getInstanceMethod(self, @selector(toolbar_updateBackForwardState));
class_addMethod(toolbarClass, @selector(toolbar_updateBackForwardState),
method_getImplementation(orgMethod),
method_getTypeEncoding(orgMethod));
class_replaceMethod(toolbarClass, orgSel,
method_getImplementation(newMethod),
method_getTypeEncoding(newMethod));
}
- (id)delegate { return nil; }
- (id)unifiedTabBar { return nil; }
- (BOOL)isInteractivelyClosingTabs { return YES; }
- (id)backForwardSegmentedControl { return nil; }
- (void)_prepareBackForwardSegmentedControl:(NSSegmentedControl *)segment { }
- (void)toolbar_updateBackForwardState {
id _self = self;
id _unifiedTabBar = [_self unifiedTabBar];
BOOL interactivelyClosing = [_unifiedTabBar isInteractivelyClosingTabs];
if (interactivelyClosing) return;
id delegate = [_self delegate];
NSSegmentedControl *segment = [_self backForwardSegmentedControl];
if (segment.segmentCount != 2) {
segment.segmentCount = 2;
}
[_self _prepareBackForwardSegmentedControl:segment];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment