From 5ff07c6bae141e4bff6bf27f42b69b9df816bef8 Mon Sep 17 00:00:00 2001 From: Claire Date: Mon, 10 Oct 2022 17:17:23 -0700 Subject: [PATCH] 1.4 code update --- Home.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Home.md b/Home.md index 4b45929..57d14a2 100644 --- a/Home.md +++ b/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()