Created
November 1, 2019 04:15
-
-
Save charliewilco/764054b556e1a56e3b9365ece7b8a21c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Cocoa | |
import SwiftUI | |
import ServiceManagement | |
@NSApplicationMain | |
class AppDelegate: NSObject, NSApplicationDelegate { | |
var statusBarItem: NSStatusItem! | |
func applicationDidFinishLaunching(_ aNotification: Notification) { | |
// Create the SwiftUI view that provides the window contents. | |
let statusBar = NSStatusBar.system | |
statusBarItem = statusBar.statusItem( | |
withLength: NSStatusItem.squareLength) | |
let statusBarMenu = NSMenu(title: "Cap Status Bar Menu") | |
statusBarItem.menu = statusBarMenu | |
statusBarItem.button?.title = DarkMode.isEnabled ? "☀️" : "🌘" | |
statusBarMenu.addItem( | |
withTitle: "Toggle DarkMode", | |
action: #selector(AppDelegate.toggle), | |
keyEquivalent: "") | |
} | |
func applicationWillTerminate(_ aNotification: Notification) { | |
// Insert code here to tear down your application | |
NSApplication.shared.terminate(self) | |
} | |
@objc func toggle() { | |
print("Attempting to toggle") | |
DarkMode.toggle(); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment