1.4 code update

master
Claire 2 years ago
parent
commit
5ff07c6bae
  1. 5
      Home.md

5
Home.md

@ -154,11 +154,13 @@ To prevent issues with icon duplication in the menu bar, we're going to connect
Since this application just shows a single icon in the menu bar, we don't need a variable-length icon area, so we'll use the [`NSStatusItem.squareLength`](https://developer.apple.com/documentation/appkit/nsstatusitem/1534224-squarelength) constant with [`NSStatusBar.statusItem()`](https://developer.apple.com/documentation/appkit/nsstatusbar/1532895-statusitem).
Note that this should be the **first** thing your `applicationDidFinishLaunching()` function calls. This ensures the menu bar icon is drawn immediately, even if the application isn't finished loading. I discovered that putting this assignment at the end of the load function caused a noticeable lag between launching the application and displaying the icon.
```swift
func applicationDidFinishLaunching(_ aNotification: Notification) {
...
// set icon size to square
statusBarItem = statusBar.statusItem(withLength: NSStatusItem.squareLength)
...
}
```
@ -585,6 +587,7 @@ Now that `updateIcon()` calls `buildMenu()`, we need to take a quick detour back
```swift
func applicationDidFinishLaunching(_ aNotification: Notification) {
...
// build the icon and menu
updateIcon()

Loading…
Cancel
Save