Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render in an NSMenuItem instead of an NSPopover #11

Merged
merged 6 commits into from Jul 17, 2021

Conversation

hmarr
Copy link
Owner

@hmarr hmarr commented Mar 26, 2021

Replace the popover with a menu item that has a custom view.

Pros:

  • Simplifies the code a fair bit
  • Native behaviour comes for free (e.g. press and hold menu item to show temporarily rather than toggling)
  • Looks better?

Cons:

  • View dimensions are hard-coded
  • Looks worse?

Thoughts on whether the new look is a "pro" or a "con" welcome!

@jlledo
Copy link
Contributor

jlledo commented Mar 27, 2021

Imo a menu item is more appropriate for a status bar view, and the handling of login options and quitting is more intuitive this way.

Plus it simplifies the code quite a bit.

LGTM

var statusBar: StatusBarController?
let processMonitor = ProcessMonitor()

func applicationDidFinishLaunching(_ aNotification: Notification) {
processMonitor.start()

// Create the SwiftUI view that provides the contents
let viewModel = ContentViewModel(monitor: processMonitor, contentVisible: false)
let viewModel = ContentViewModel(monitor: processMonitor, contentVisible: true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The contentVisible property can never be false anymore. Thoughts on removing it?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing this out!

I actually chose to fix it up rather than remove it (11b12dd). Without it, the SwiftUI ContentView gets re-rendered every second, even when the menu bar is closed, and that eats a bit of unnecessary CPU. If you know a better way of handling this, I'm all ears though 😄

@@ -114,7 +114,7 @@ struct ContentView: View {
.frame(width: 45, alignment: .trailing)
}
}
}.frame(maxWidth: .infinity, maxHeight: .infinity).padding(10)
}.frame(maxWidth: .infinity, maxHeight: .infinity).padding(EdgeInsets(top: 4, leading: 22, bottom: 4, trailing: 12))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM on Big Sur.
Screenshot 2021-03-27 at 18 01 32

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed the process names aren't aligned with the other menu items on Big Sur (whereas they are on Catalina). I've tried to account for this, but I still don't have access to Big Sur, so the padding value is a guess that's likely to be a bit off. If you get a second, would you mind checking and seeing what looks right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

12 px inset
Screenshot 2021-07-18 at 18 39 34

14 px inset
Screenshot 2021-07-18 at 18 42 59

In my very scientific testing using a Preview.app selection box's edge to compare vertical alignment, I've found 14 px works a bit better than the current 12 px.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Top science! 🧑‍🔬

I've updated it to 14px and released in v0.5.

Vitals/AppDelegate.swift Outdated Show resolved Hide resolved
@hmarr hmarr marked this pull request as ready for review July 17, 2021 17:08
@hmarr
Copy link
Owner Author

hmarr commented Jul 17, 2021

@jlledo thanks very much for your review, and apologies for totally missing it 😬. I've addressed most of your feedback - there's just one outstanding question about the left inset size on Big Sur, then I think this is good to go.

@hmarr
Copy link
Owner Author

hmarr commented Jul 17, 2021

@jlledo in fact, I'm going to merge this as-is, then we can tweak the left inset size as a follow-up PR if necessary.

@hmarr hmarr merged commit 3f2c0b0 into main Jul 17, 2021
@hmarr hmarr deleted the menuitem-instead-of-popover branch July 17, 2021 17:18
@@ -77,6 +77,13 @@ struct ContentView: View {
private static let processListHeight = 460
private static let topPadding = 6
private static let bottomPadding = 4
private static var leftPadding: Int {
if #available(macOS 10.0, *) {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should actually be macOS 11.0, * to check for Big Sur – I just decremented it to check the conditional was working as expected and forgot to update. Fixed in db4068f.

hmarr added a commit that referenced this pull request Jul 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants