Skip to content

Commit

Permalink
Add support for macOS 10.13
Browse files Browse the repository at this point in the history
The problem is that macOS 10.13 does not allow to simply mutate `items`
in menu. You have to use addItem/removeItem instead. The support for
direct mutation was added in Mojave.

https://developer.apple.com/documentation/macos_release_notes/macos_mojave_10_14_release_notes/appkit_release_notes_for_macos_10_14
  • Loading branch information
p0deje committed Sep 23, 2019
1 parent 0900063 commit 85794a0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Maccy.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.14;
MACOSX_DEPLOYMENT_TARGET = 10.13;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
Expand Down Expand Up @@ -664,7 +664,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.14;
MACOSX_DEPLOYMENT_TARGET = 10.13;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
Expand Down
17 changes: 12 additions & 5 deletions Maccy/Menu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ class Menu: NSMenu, NSMenuDelegate {
}

func menuWillOpen(_ menu: NSMenu) {
self.items = allItems
removeAllItems()

let oldAllItems = allItems
oldAllItems.forEach(addItem(_:))
allItems = oldAllItems

setKeyEquivalents(items)
highlight(highlightableItems(items).first)
}
Expand Down Expand Up @@ -48,16 +53,18 @@ class Menu: NSMenu, NSMenuDelegate {
}

func updateFilter(filter: String) {
removeAllItems()

let oldAllItems = allItems

let searchItem = allItems.first
let results = search.search(string: filter, within: searchableItems())
let systemItems = allItems.filter({ isSystemItem(item: $0) })

items = [searchItem!]
items += results
items += [NSMenuItem.separator()]
items += systemItems
addItem(searchItem!)
results.forEach(addItem(_:))
addItem(NSMenuItem.separator())
systemItems.forEach(addItem(_:))

allItems = oldAllItems

Expand Down

0 comments on commit 85794a0

Please sign in to comment.