leits / MeetingBar

🇺🇦 Your meetings at your fingertips in the macOS menu bar
https://meetingbar.app
Apache License 2.0
4.53k stars 203 forks source link

Feature: Open the preference window when relaunching the app while it already running. #756

Open megabitsenmzq opened 3 months ago

megabitsenmzq commented 3 months ago

Issue that this suggestion fixes

On a MacBook with the notch. the OS will hide a long status bar item. So sometimes the status bar item of this app is invisible. In this state, I can't access the app's preference to change the status bar item to a single icon.

Now the only way I can access MeetingBar is by reducing the icons I have on the bar. And it's not intuitive.

Solution description

Some apps open the preference window if the user tries to relaunch the app (maybe by clicking on Launchpad) while the app is already running. (AltTab, Unclutter, etc.)

You might handle this by adding code in:

func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows: Bool) {
    // Open preference window here
}

Alternatives considered

Or maybe you can also check if the status bar item is invisible.

By checking if the window of status bar button is on screen.

func isWindowOnScreen(_ windowNumber: Int) -> Bool {
    guard let allWindowsInfo = CGWindowListCopyWindowInfo(.optionOnScreenOnly, kCGNullWindowID) else {
        return false
    }
    guard let convertedInfo = allWindowsInfo as? [[String: Any]] else { return false }
    for item in convertedInfo {
        if item[kCGWindowIsOnscreen as String] as? Bool == true && item[kCGWindowNumber as String] as? Int == windowNumber {
            return true
        }
    }
    return false
}

Additional context

I'm confused the app disappeared after I connected my calendar. This small feature can make it a lot easier to let the app appear again.