diff --git a/whilom.xcodeproj/project.pbxproj b/whilom.xcodeproj/project.pbxproj index 9c94984..f81962c 100644 --- a/whilom.xcodeproj/project.pbxproj +++ b/whilom.xcodeproj/project.pbxproj @@ -275,7 +275,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_TEAM = 24X8MVUSCN; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = whilom/Info.plist; @@ -283,7 +283,7 @@ "$(inherited)", "@executable_path/../Frameworks", ); - MARKETING_VERSION = 0.1.6; + MARKETING_VERSION = 0.1.7; PRODUCT_BUNDLE_IDENTIFIER = com.insanj.whilom; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -299,7 +299,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_TEAM = 24X8MVUSCN; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = whilom/Info.plist; @@ -307,7 +307,7 @@ "$(inherited)", "@executable_path/../Frameworks", ); - MARKETING_VERSION = 0.1.6; + MARKETING_VERSION = 0.1.7; PRODUCT_BUNDLE_IDENTIFIER = com.insanj.whilom; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; diff --git a/whilom/AppDelegate.swift b/whilom/AppDelegate.swift index 27f6a22..5d30ed2 100644 --- a/whilom/AppDelegate.swift +++ b/whilom/AppDelegate.swift @@ -41,6 +41,12 @@ class AppDelegate: NSObject, NSApplicationDelegate { return NSMenuItem(title: "💝 whilom \(versionString)", action: nil, keyEquivalent: "") }() + let aboutMenuItem: NSMenuItem = { + let quitMenuItem = NSMenuItem() + quitMenuItem.title = "About" + return quitMenuItem + }() + let quitMenuItem: NSMenuItem = { let quitMenuItem = NSMenuItem() quitMenuItem.title = "Quit" @@ -91,6 +97,8 @@ class AppDelegate: NSObject, NSApplicationDelegate { whilomStatusItem.button?.addObserver(self, forKeyPath: "effectiveAppearance", options: .new, context: nil) themeifyMenuItems() + + setupRightClickMenu() } func applicationWillTerminate(_ aNotification: Notification) { @@ -111,29 +119,48 @@ class AppDelegate: NSObject, NSApplicationDelegate { } // MARK: - right click handlers - func createWhilomMenu() { + private func setupRightClickMenu() { titleMenuItem.isEnabled = false menu.addItem(titleMenuItem) + menu.delegate = self menu.addItem(NSMenuItem.separator()) + aboutMenuItem.action = #selector(aboutWhilom(_:)) + aboutMenuItem.target = self + menu.addItem(aboutMenuItem) + quitMenuItem.action = #selector(quitWhilom(_:)) quitMenuItem.target = self menu.addItem(quitMenuItem) - + } + + private func createWhilomMenu() { whilomStatusItem.menu = menu - let point = NSApp.currentEvent?.window?.frame.origin ?? .zero menu.popUp(positioning: titleMenuItem, at: point, in: nil) } + private func destroyWhilomMenu() { + whilomStatusItem.menu = nil + } + + @objc func aboutWhilom(_ sender: Any) { + let aboutAlert = NSAlert() + aboutAlert.icon = NSImage(named: NSImage.Name("whilom")) + aboutAlert.messageText = "whilom" + aboutAlert.informativeText = "🪄 keep your mac awake even when the lid is closed\n\n💭 whi·lom, meaning \"at times,\" having once been\n\n🎉 thanks for checking out our app! follow us @SnowcodeDesign\n\n© 2021 Snowcode, LLC" + aboutAlert.addButton(withTitle: "👋 Sweet dreams!") + aboutAlert.runModal() + } + @objc func quitWhilom(_ sender: Any) -> Bool { NSApplication.shared.terminate(self) return true } // MARK: - left click handler - private func toggleSleep() { + func toggleSleep() { if isSleepEnabled { let _ = disableSleep() } else { @@ -142,7 +169,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { } // MARK: execute scripts based on state - @objc private func disableSleep() -> Bool { + @objc func disableSleep() -> Bool { if !isJustMessingAround { var error: NSDictionary? disableSleepScript?.executeAndReturnError(&error) @@ -159,7 +186,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { return true } - @objc private func enableSleep() -> Bool { + @objc func enableSleep() -> Bool { if !isJustMessingAround { var error: NSDictionary? enableSleepScript?.executeAndReturnError(&error) @@ -205,7 +232,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { } // MARK: - dark/light handling - static func isDarkMode(_ statusItem: NSStatusItem) -> Bool { + static private func isDarkMode(_ statusItem: NSStatusItem) -> Bool { let effectiveAppearance = statusItem.button?.effectiveAppearance let themeName = effectiveAppearance?.name.rawValue.lowercased() let containsDark = themeName?.contains("dark") @@ -239,8 +266,13 @@ class AppDelegate: NSObject, NSApplicationDelegate { } } + extension AppDelegate: NSMenuDelegate, NSMenuItemValidation { func validateMenuItem(_ menuItem: NSMenuItem) -> Bool { return true } + + func menuDidClose(_ menu: NSMenu) { + destroyWhilomMenu() + } } diff --git a/whilom/Assets.xcassets/hattie on 3.imageset/Artboard.png b/whilom/Assets.xcassets/hattie on 3.imageset/Artboard.png index d638ca0..5adf8bb 100644 Binary files a/whilom/Assets.xcassets/hattie on 3.imageset/Artboard.png and b/whilom/Assets.xcassets/hattie on 3.imageset/Artboard.png differ diff --git a/whilom/Assets.xcassets/hattie on 3.imageset/Artboard@2x.png b/whilom/Assets.xcassets/hattie on 3.imageset/Artboard@2x.png index 0426cc7..3407644 100644 Binary files a/whilom/Assets.xcassets/hattie on 3.imageset/Artboard@2x.png and b/whilom/Assets.xcassets/hattie on 3.imageset/Artboard@2x.png differ diff --git a/whilom/Assets.xcassets/hattie on 3.imageset/Artboard@3x.png b/whilom/Assets.xcassets/hattie on 3.imageset/Artboard@3x.png index cb52acc..b33ce43 100644 Binary files a/whilom/Assets.xcassets/hattie on 3.imageset/Artboard@3x.png and b/whilom/Assets.xcassets/hattie on 3.imageset/Artboard@3x.png differ diff --git a/whilom/Assets.xcassets/whilom.imageset/Artboard.png b/whilom/Assets.xcassets/whilom.imageset/Artboard.png new file mode 100644 index 0000000..163571e Binary files /dev/null and b/whilom/Assets.xcassets/whilom.imageset/Artboard.png differ diff --git a/whilom/Assets.xcassets/whilom.imageset/Artboard@2x.png b/whilom/Assets.xcassets/whilom.imageset/Artboard@2x.png new file mode 100644 index 0000000..56971b9 Binary files /dev/null and b/whilom/Assets.xcassets/whilom.imageset/Artboard@2x.png differ diff --git a/whilom/Assets.xcassets/whilom.imageset/Artboard@3x.png b/whilom/Assets.xcassets/whilom.imageset/Artboard@3x.png new file mode 100644 index 0000000..ba6ffa8 Binary files /dev/null and b/whilom/Assets.xcassets/whilom.imageset/Artboard@3x.png differ diff --git a/whilom/Assets.xcassets/whilom.imageset/Contents.json b/whilom/Assets.xcassets/whilom.imageset/Contents.json new file mode 100644 index 0000000..936d563 --- /dev/null +++ b/whilom/Assets.xcassets/whilom.imageset/Contents.json @@ -0,0 +1,23 @@ +{ + "images" : [ + { + "filename" : "Artboard.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "Artboard@2x.png", + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "Artboard@3x.png", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +}