Skip to content

Commit

Permalink
Remove availability workarounds for macOS 10.9 and 10.10
Browse files Browse the repository at this point in the history
  • Loading branch information
Eitot committed Jun 23, 2020
1 parent 736860c commit 69fe3b8
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 139 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@ -(void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
}

// Initialize a graphics context
CGContextRef context;
if (@available(macOS 10.10, *)) {
context = (CGContextRef)[[NSGraphicsContext currentContext] CGContext];
} else {
context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
}
CGContextRef context = NSGraphicsContext.currentContext.CGContext;
CGContextSetTextMatrix(context, CGAffineTransformIdentity);
CGRect rect = NSRectToCGRect([self titleRectForBounds:cellFrame]);
// hack context to avoid flipped text
Expand Down
24 changes: 4 additions & 20 deletions Vienna/Sources/Application/AppController.m
Original file line number Diff line number Diff line change
Expand Up @@ -423,11 +423,7 @@ -(void)applicationDidFinishLaunching:(NSNotification *)aNot

// Set the placeholder string for the global search field
SearchMethod * currentSearchMethod = [Preferences standardPreferences].searchMethod;
if (@available(macOS 10.10, *)) {
self.toolbarSearchField.placeholderString = currentSearchMethod.friendlyName;
} else {
((NSSearchFieldCell *)self.toolbarSearchField.cell).placeholderString = currentSearchMethod.friendlyName;
}
self.toolbarSearchField.placeholderString = currentSearchMethod.friendlyName;

// Add Scripts menu if we have any scripts
if (!hasOSScriptsMenu())
Expand Down Expand Up @@ -3070,11 +3066,7 @@ -(void)updateSearchPlaceholderAndSearchMethod
for (NSMenuItem * menuItem in ((NSSearchFieldCell *)self.toolbarSearchField.cell).searchMenuTemplate.itemArray)
{
if ([[menuItem.representedObject friendlyName] isEqualToString:[SearchMethod searchCurrentWebPageMethod].friendlyName]) {
if (@available(macOS 10.10, *)) {
self.toolbarSearchField.placeholderString = [SearchMethod searchCurrentWebPageMethod].friendlyName;
} else {
((NSSearchFieldCell *)self.toolbarSearchField.cell).placeholderString = [SearchMethod searchCurrentWebPageMethod].friendlyName;
}
self.toolbarSearchField.placeholderString = [SearchMethod searchCurrentWebPageMethod].friendlyName;
[Preferences standardPreferences].searchMethod = menuItem.representedObject;
}
}
Expand All @@ -3088,20 +3080,12 @@ -(void)updateSearchPlaceholderAndSearchMethod
for (NSMenuItem * menuItem in ((NSSearchFieldCell *)self.toolbarSearchField.cell).searchMenuTemplate.itemArray)
{
if ([[menuItem.representedObject friendlyName] isEqualToString:[SearchMethod searchAllArticlesMethod].friendlyName]) {
if (@available(macOS 10.10, *)) {
self.toolbarSearchField.placeholderString = [SearchMethod searchAllArticlesMethod].friendlyName;
} else {
((NSSearchFieldCell *)self.toolbarSearchField.cell).placeholderString = [SearchMethod searchAllArticlesMethod].friendlyName;
}
self.toolbarSearchField.placeholderString = [SearchMethod searchAllArticlesMethod].friendlyName;
[Preferences standardPreferences].searchMethod = menuItem.representedObject;
}
}
} else {
if (@available(macOS 10.10, *)) {
self.toolbarSearchField.placeholderString = prefs.searchMethod.friendlyName;
} else {
((NSSearchFieldCell *)self.toolbarSearchField.cell).placeholderString = prefs.searchMethod.friendlyName;
}
self.toolbarSearchField.placeholderString = prefs.searchMethod.friendlyName;
}
// END of switching between "Search all articles" and "Search current web page".
}
Expand Down
24 changes: 6 additions & 18 deletions Vienna/Sources/Main window/ArticleListView.m
Original file line number Diff line number Diff line change
Expand Up @@ -127,29 +127,17 @@ -(void)initialiseArticleView
style.lineBreakMode = NSLineBreakByTruncatingTail;
style.tighteningFactorForTruncation = 0.0;

if (@available(macOS 10.10, *)) {
reportCellDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:style, NSParagraphStyleAttributeName, [NSColor textColor], NSForegroundColorAttributeName, nil];
unreadReportCellDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:style, NSParagraphStyleAttributeName, [NSColor textColor], NSForegroundColorAttributeName, nil];
} else {
reportCellDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:style, NSParagraphStyleAttributeName, nil];
unreadReportCellDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:style, NSParagraphStyleAttributeName, nil];
}
reportCellDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:style, NSParagraphStyleAttributeName, [NSColor textColor], NSForegroundColorAttributeName, nil];
unreadReportCellDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:style, NSParagraphStyleAttributeName, [NSColor textColor], NSForegroundColorAttributeName, nil];

selectionDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:style, NSParagraphStyleAttributeName, [NSColor whiteColor], NSForegroundColorAttributeName, nil];
unreadTopLineDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:style, NSParagraphStyleAttributeName, [NSColor textColor], NSForegroundColorAttributeName, nil];
topLineDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:style, NSParagraphStyleAttributeName, [NSColor textColor], NSForegroundColorAttributeName, nil];
unreadTopLineSelectionDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:style, NSParagraphStyleAttributeName, [NSColor whiteColor], NSForegroundColorAttributeName, nil];
if (@available(macOS 10.10, *)) {
middleLineDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:style, NSParagraphStyleAttributeName, [NSColor systemBlueColor], NSForegroundColorAttributeName, nil];
linkLineDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:style, NSParagraphStyleAttributeName, [NSColor systemBlueColor], NSForegroundColorAttributeName, nil];
bottomLineDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:style, NSParagraphStyleAttributeName, [NSColor systemGrayColor], NSForegroundColorAttributeName, nil];
} else {
middleLineDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:style, NSParagraphStyleAttributeName, [NSColor blueColor], NSForegroundColorAttributeName, nil];
linkLineDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:style, NSParagraphStyleAttributeName, [NSColor blueColor], NSForegroundColorAttributeName, nil];
bottomLineDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:style, NSParagraphStyleAttributeName, [NSColor grayColor], NSForegroundColorAttributeName, nil];
}


middleLineDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:style, NSParagraphStyleAttributeName, [NSColor systemBlueColor], NSForegroundColorAttributeName, nil];
linkLineDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:style, NSParagraphStyleAttributeName, [NSColor systemBlueColor], NSForegroundColorAttributeName, nil];
bottomLineDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:style, NSParagraphStyleAttributeName, [NSColor systemGrayColor], NSForegroundColorAttributeName, nil];

// Set the reading pane orientation
[self setOrientation:prefs.layout];

Expand Down
12 changes: 2 additions & 10 deletions Vienna/Sources/Main window/FoldersTree.m
Original file line number Diff line number Diff line change
Expand Up @@ -963,17 +963,9 @@ -(id)outlineView:(NSOutlineView *)olv objectValueForTableColumn:(NSTableColumn *
Folder * folder = node.folder;
NSMutableDictionary * myInfo = [NSMutableDictionary dictionaryWithDictionary:info];
if (folder.isUnsubscribed) {
if (@available(macOS 10.10, *)) {
myInfo[NSForegroundColorAttributeName] = NSColor.secondaryLabelColor;
} else {
myInfo[NSForegroundColorAttributeName] = NSColor.disabledControlTextColor;
}
myInfo[NSForegroundColorAttributeName] = NSColor.secondaryLabelColor;
} else {
if (@available(macOS 10.10, *)) {
myInfo[NSForegroundColorAttributeName] = NSColor.labelColor;
} else {
myInfo[NSForegroundColorAttributeName] = NSColor.controlTextColor;
}
myInfo[NSForegroundColorAttributeName] = NSColor.labelColor;
}
// Set the font
if (folder.unreadCount || (folder.childUnreadCount && ![olv isItemExpanded:item]))
Expand Down
7 changes: 0 additions & 7 deletions Vienna/Sources/Main window/MainWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,6 @@ final class MainWindowController: NSWindowController {
// TODO: Move this to windowDidLoad()
statusBarState(disclosed: Preferences.standard().showStatusBar, animate: false)

if #available(OSX 10.10, *) {
// Leave the default
} else {
statusLabel.cell?.backgroundStyle = .raised
filterLabel.cell?.backgroundStyle = .raised
}

let filterMenu = (NSApp as? ViennaApp)?.filterMenu
let filterMode = Preferences.standard().filterMode
if let menuTitle = filterMenu?.item(withTag: filterMode)?.title {
Expand Down
9 changes: 2 additions & 7 deletions Vienna/Sources/Main window/TabbedWebView.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,8 @@ @implementation TabbedWebView
+(NSString *)userAgent
{
if (!_userAgent) {
NSString *osVersion;
if (@available(macOS 10.10, *)) {
NSOperatingSystemVersion version = [NSProcessInfo processInfo].operatingSystemVersion;
osVersion = [NSString stringWithFormat:@"%ld_%ld_%ld", version.majorVersion, version.minorVersion, version.patchVersion];
} else {
osVersion = @"10_9_x";
}
NSOperatingSystemVersion version = [NSProcessInfo processInfo].operatingSystemVersion;
NSString *osVersion = [NSString stringWithFormat:@"%ld_%ld_%ld", version.majorVersion, version.minorVersion, version.patchVersion];
NSString *webkitVersion = [NSBundle bundleWithIdentifier:@"com.apple.WebKit"].infoDictionary[@"CFBundleVersion"];
if (!webkitVersion) {
webkitVersion = @"536.30";
Expand Down
7 changes: 2 additions & 5 deletions Vienna/Sources/Shared/DateFormatterExtension.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,15 @@
@implementation NSDateFormatter (RelativeDateFormatter)

+ (NSDateFormatter *)relativeDateFormatter {
static NSDateFormatter *_relativeDateFormatter = nil;
static NSDateFormatter *_relativeDateFormatter;
static dispatch_once_t onceToken;

dispatch_once(&onceToken, ^{
_relativeDateFormatter = [self new];
_relativeDateFormatter.doesRelativeDateFormatting = YES;
_relativeDateFormatter.dateStyle = NSDateFormatterShortStyle;
_relativeDateFormatter.timeStyle = NSDateFormatterShortStyle;

if (@available(macOS 10.10, *)) {
_relativeDateFormatter.formattingContext = NSFormattingContextDynamic;
}
_relativeDateFormatter.formattingContext = NSFormattingContextDynamic;
});

return _relativeDateFormatter;
Expand Down
81 changes: 15 additions & 66 deletions Vienna/Sources/Shared/OverlayStatusBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,10 @@ final class OverlayStatusBar: NSView {

// MARK: Subviews

private var backgroundView: NSView = {
let backgroundView: NSView
if #available(OSX 10.10, *) {
let view = NSVisualEffectView(frame: NSRect.zero)
view.wantsLayer = true
view.blendingMode = .withinWindow
backgroundView = view
} else {
backgroundView = NSView(frame: NSRect.zero)
backgroundView.wantsLayer = true
backgroundView.layer?.backgroundColor = CGColor(gray: 0, alpha: 0.65)
}

private var backgroundView: NSVisualEffectView = {
let backgroundView = NSVisualEffectView(frame: NSRect.zero)
backgroundView.wantsLayer = true
backgroundView.blendingMode = .withinWindow
backgroundView.alphaValue = 0
backgroundView.layer?.cornerRadius = 3

Expand All @@ -58,30 +49,12 @@ final class OverlayStatusBar: NSView {
addressField.isBezeled = false
addressField.isSelectable = false
addressField.drawsBackground = false

if #available(OSX 10.10, *) {
addressField.textColor = .labelColor
}
}

if #available(OSX 10.11, *) {
addressField.font = .systemFont(ofSize: 12, weight: .medium)
} else if #available(OSX 10.10, *) {
addressField.font = NSFont(name: "Helvetica Neue Medium", size: 12)
} else {
addressField.font = .systemFont(ofSize: 11)
addressField.textColor = .labelColor
}

if #available(OSX 10.10, *) {
addressField.lineBreakMode = .byTruncatingMiddle

if #available(OSX 10.11, *) {
addressField.allowsDefaultTighteningForTruncation = true
}
} else {
addressField.cell?.lineBreakMode = .byTruncatingMiddle
addressField.cell?.backgroundStyle = .dark
}
addressField.font = .systemFont(ofSize: 12, weight: .medium)
addressField.lineBreakMode = .byTruncatingMiddle
addressField.allowsDefaultTighteningForTruncation = true

return addressField
}()
Expand Down Expand Up @@ -115,13 +88,8 @@ final class OverlayStatusBar: NSView {
addressFieldConstraints += NSLayoutConstraint.constraints(withVisualFormat: "H:|-6-[label]-6-|",
metrics: nil, views: ["label": addressField])

if #available(OSX 10.10, *) {
NSLayoutConstraint.activate(backgroundViewConstraints)
NSLayoutConstraint.activate(addressFieldConstraints)
} else {
addConstraints(backgroundViewConstraints)
backgroundView.addConstraints(addressFieldConstraints)
}
NSLayoutConstraint.activate(backgroundViewConstraints)
NSLayoutConstraint.activate(addressFieldConstraints)
}

// Make this initialiser unavailable.
Expand All @@ -146,21 +114,15 @@ final class OverlayStatusBar: NSView {
}

// Layer-backing will make sure that the visual-effect view redraws.
if #available(OSX 10.10, *) {
superview.wantsLayer = true
}
superview.wantsLayer = true

var baseContraints: [NSLayoutConstraint] = []
baseContraints += NSLayoutConstraint.constraints(withVisualFormat: "V:|->=0-[view]-0-|",
options: [], metrics: nil, views: ["view": self])
baseContraints += NSLayoutConstraint.constraints(withVisualFormat: "H:|->=0-[view]->=0-|",
options: [], metrics: nil, views: ["view": self])

if #available(OSX 10.10, *) {
NSLayoutConstraint.activate(baseContraints)
} else {
superview.addConstraints(baseContraints)
}
NSLayoutConstraint.activate(baseContraints)

// Pin the view to the left side.
pin(to: .leadingEdge, of: superview)
Expand Down Expand Up @@ -208,18 +170,10 @@ final class OverlayStatusBar: NSView {
}

// Remove existing constraints.
if #available(OSX 10.10, *) {
NSLayoutConstraint.deactivate(oldConstraints)
} else {
positioningView.removeConstraints(oldConstraints)
}
NSLayoutConstraint.deactivate(oldConstraints)

// Add new constraints.
if #available(OSX 10.10, *) {
NSLayoutConstraint.activate(newConstraints)
} else {
positioningView.addConstraints(newConstraints)
}
NSLayoutConstraint.activate(newConstraints)

self.position = position
}
Expand Down Expand Up @@ -321,12 +275,7 @@ final class OverlayStatusBar: NSView {
toItem: nil, attribute: .notAnAttribute, multiplier: 1,
constant: superview.bounds.midX - 8)
self.widthConstraint = widthConstraint

if #available(OSX 10.10, *) {
widthConstraint.isActive = true
} else {
addConstraint(widthConstraint)
}
widthConstraint.isActive = true
}
}

Expand Down

0 comments on commit 69fe3b8

Please sign in to comment.