diff --git a/LunaMac.xcodeproj/project.pbxproj b/LunaMac.xcodeproj/project.pbxproj index 06c6c2e..6a62fbc 100644 --- a/LunaMac.xcodeproj/project.pbxproj +++ b/LunaMac.xcodeproj/project.pbxproj @@ -14,6 +14,10 @@ 7ECD0D7C28DD2A4100B90958 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7ECD0D7B28DD2A4100B90958 /* AppDelegate.swift */; }; 7ECD0D7E28DD2A4100B90958 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7ECD0D7D28DD2A4100B90958 /* ViewController.swift */; }; 7ECD26CC28E002A9000D5E2C /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7ECD26CA28E002A9000D5E2C /* MainMenu.xib */; }; + 7EF1E35728E7FF5A006F8ED9 /* wang-alt-dark.png in Resources */ = {isa = PBXBuildFile; fileRef = 7EF1E35328E7FF59006F8ED9 /* wang-alt-dark.png */; }; + 7EF1E35828E7FF5A006F8ED9 /* wanc-alt-dark.png in Resources */ = {isa = PBXBuildFile; fileRef = 7EF1E35428E7FF59006F8ED9 /* wanc-alt-dark.png */; }; + 7EF1E35928E7FF5A006F8ED9 /* waxc-alt-dark.png in Resources */ = {isa = PBXBuildFile; fileRef = 7EF1E35528E7FF59006F8ED9 /* waxc-alt-dark.png */; }; + 7EF1E35A28E7FF5A006F8ED9 /* waxg-alt-dark.png in Resources */ = {isa = PBXBuildFile; fileRef = 7EF1E35628E7FF5A006F8ED9 /* waxg-alt-dark.png */; }; 7EF79B3328DE1E4D00FF1F49 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7EF79B3228DE1E4D00FF1F49 /* Assets.xcassets */; }; 7EF79BAE28DE395C00FF1F49 /* firstq-dark.png in Resources */ = {isa = PBXBuildFile; fileRef = 7EF79B9E28DE395C00FF1F49 /* firstq-dark.png */; }; 7EF79BAF28DE395C00FF1F49 /* firstq.png in Resources */ = {isa = PBXBuildFile; fileRef = 7EF79B9F28DE395C00FF1F49 /* firstq.png */; }; @@ -46,6 +50,10 @@ 7ECD0D8428DD2A4200B90958 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 7ECD0D8528DD2A4200B90958 /* LunaMac.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = LunaMac.entitlements; sourceTree = ""; }; 7ECD26CB28E002A9000D5E2C /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = ""; }; + 7EF1E35328E7FF59006F8ED9 /* wang-alt-dark.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "wang-alt-dark.png"; sourceTree = ""; }; + 7EF1E35428E7FF59006F8ED9 /* wanc-alt-dark.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "wanc-alt-dark.png"; sourceTree = ""; }; + 7EF1E35528E7FF59006F8ED9 /* waxc-alt-dark.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "waxc-alt-dark.png"; sourceTree = ""; }; + 7EF1E35628E7FF5A006F8ED9 /* waxg-alt-dark.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "waxg-alt-dark.png"; sourceTree = ""; }; 7EF79B3228DE1E4D00FF1F49 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 7EF79B9E28DE395C00FF1F49 /* firstq-dark.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "firstq-dark.png"; sourceTree = ""; }; 7EF79B9F28DE395C00FF1F49 /* firstq.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = firstq.png; sourceTree = ""; }; @@ -115,6 +123,10 @@ 7EF79B9D28DE395C00FF1F49 /* png */ = { isa = PBXGroup; children = ( + 7EF1E35428E7FF59006F8ED9 /* wanc-alt-dark.png */, + 7EF1E35328E7FF59006F8ED9 /* wang-alt-dark.png */, + 7EF1E35528E7FF59006F8ED9 /* waxc-alt-dark.png */, + 7EF1E35628E7FF5A006F8ED9 /* waxg-alt-dark.png */, 7EF79BBE28DE4D2400FF1F49 /* default-dark.png */, 7EF79BBF28DE4D2400FF1F49 /* default.png */, 7EF79B9E28DE395C00FF1F49 /* firstq-dark.png */, @@ -208,9 +220,13 @@ 7EF79BB828DE395C00FF1F49 /* wang-dark.png in Resources */, 7EF79BC028DE4D2400FF1F49 /* default-dark.png in Resources */, 7EF79BB928DE395C00FF1F49 /* wang.png in Resources */, + 7EF1E35828E7FF5A006F8ED9 /* wanc-alt-dark.png in Resources */, + 7EF1E35728E7FF5A006F8ED9 /* wang-alt-dark.png in Resources */, 7EF79BB628DE395C00FF1F49 /* wanc-dark.png in Resources */, 7EF79BBB28DE395C00FF1F49 /* waxc.png in Resources */, + 7EF1E35A28E7FF5A006F8ED9 /* waxg-alt-dark.png in Resources */, 7EF79BB528DE395C00FF1F49 /* new.png in Resources */, + 7EF1E35928E7FF5A006F8ED9 /* waxc-alt-dark.png in Resources */, 7EF79BB228DE395C00FF1F49 /* lastq-dark.png in Resources */, 7EF79BB328DE395C00FF1F49 /* lastq.png in Resources */, 7E0CBEA428DEB998009967CD /* Changelog.xib in Resources */, diff --git a/LunaMac/AppDelegate.swift b/LunaMac/AppDelegate.swift index a364b67..08368da 100644 --- a/LunaMac/AppDelegate.swift +++ b/LunaMac/AppDelegate.swift @@ -77,7 +77,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { ], "default" : [ "nice" : "Failed to calculate.", - "icon" : "🌙" + "icon" : "⨂" ] ] @@ -89,6 +89,9 @@ class AppDelegate: NSObject, NSApplicationDelegate { // make sure applet stays in memory var statusBarItem: NSStatusItem? + // create a menu for the icon + let statusBarMenu = NSMenu(title: "LunaMac Menu") + // create empty timer for event loop var lunaTimer = Timer() @@ -98,6 +101,9 @@ class AppDelegate: NSObject, NSApplicationDelegate { // is the changelog open? var logOpen = false + // user settings + let defaults = UserDefaults.standard + func applicationDidFinishLaunching(_ aNotification: Notification) { // build the icon and menu updateIcon() @@ -116,42 +122,76 @@ class AppDelegate: NSObject, NSApplicationDelegate { } @objc func buildMenu(key: String = "default") { + // clear the menu + statusBarMenu.removeAllItems() + statusBarItem?.isVisible = false + // get system-wide menu bar let statusBar = NSStatusBar.system // set icon size to square statusBarItem = statusBar.statusItem(withLength: NSStatusItem.squareLength) - // set icon using emoji - //statusBarItem?.button?.title = phaseArray[key]?["icon"] as String? ?? "🌙" - - var suffix = "" - - // check for dark mode and set the right image file - if #available(OSX 10.14, *) { - let darkMode = UserDefaults.standard.string(forKey: "AppleInterfaceStyle") + // if iconPref is set to emoji + if (defaults.string(forKey: "iconPref") == "emoji") { + // change font size + // still not aligned properly + let iconString = phaseArray[key]?["icon"] as String? ?? "⨂" + let iconAttrib = [ NSAttributedString.Key.font: NSFont.menuFont(ofSize: 12.0) ] + let iconAttrString = NSAttributedString(string: iconString, attributes: iconAttrib) + statusBarItem?.button?.attributedTitle = iconAttrString + } + // otherwise use icons + else { + var suffix = "" + + // if key is new2, rename to new + var key2 = key.contains("2") ? "new" : key - if darkMode == "Dark" { - suffix += "-dark" + // check for dark mode and set the right image file + if #available(OSX 10.14, *) { + let darkMode = UserDefaults.standard.string(forKey: "AppleInterfaceStyle") + + if darkMode == "Dark" { + // if theme is set to dark alt make adjustments + if (defaults.string(forKey: "iconPref") == "darkalt") { + switch (key2) { + case "new" : + key2 = "full" + break + case "full" : + key2 = "new" + break + case "firstq" : + key2 = "lastq" + break + case "lastq" : + key2 = "firstq" + break + case "wanc", "wang", "waxc", "waxg" : + suffix += "-alt" + break + default : + break + } + } + + suffix += "-dark" + } } + + // set image filename + let imgName = key2 + suffix + ".png" + + statusBarItem?.button?.image = NSImage(named: imgName) } - // if key is new2, rename to new - - let key2 = key.contains("2") ? "new" : key - - // set image filename - let imgName = key2 + suffix + ".png" - - statusBarItem?.button?.image = NSImage(named: imgName) - - // create a menu for the icon - let statusBarMenu = NSMenu(title: "LunaMac Menu") + statusBarItem?.isVisible = true // add the menu to the menu bar icon statusBarItem?.menu = statusBarMenu - let topTxt = phaseArray["default"]?["nice"] as String? ?? "" + let topTxt = phaseArray["default"]?["nice"] as String? ?? "Failed to calculate." // add menu items to the menu if (!topTxt.isEmpty) { @@ -172,6 +212,63 @@ class AppDelegate: NSObject, NSApplicationDelegate { statusBarMenu.addItem(NSMenuItem.separator()) + // create menu item to hold submenu + let prefMenu = NSMenu(title: "Prefs") + + // default + let optDefault = NSMenuItem( + title: "Default", + action: #selector(setPref), + keyEquivalent: "" + ) + + // alternate dark + let optDarkAlt = NSMenuItem( + title: "Alternate Dark", + action: #selector(setPref), + keyEquivalent: "" + ) + + // emoji + let optEmoji = NSMenuItem( + title: "Emoji", + action: #selector(setPref), + keyEquivalent: "" + ) + + // make sure the right menu item is checked + switch (defaults.string(forKey: "iconPref")) { + case "default" : + // standard icons + optDefault.state = NSControl.StateValue.on + break + case "darkalt" : + // inverted dark mode icons + optDarkAlt.state = NSControl.StateValue.on + break + case "emoji" : + // emoji icons + optEmoji.state = NSControl.StateValue.on + break + default : + // default to standard icons + optDefault.state = NSControl.StateValue.on + break + } + + prefMenu.addItem(optDefault) + prefMenu.addItem(optDarkAlt) + prefMenu.addItem(optEmoji) + + let prefMenuItem = NSMenuItem( + title: "Icon Style", + action: nil, + keyEquivalent: "" + ) + + statusBarMenu.addItem(prefMenuItem) + statusBarMenu.setSubmenu(prefMenu, for: prefMenuItem) + statusBarMenu.addItem( withTitle: "About LunaMac...", action: #selector(AppDelegate.showAbout), @@ -185,6 +282,26 @@ class AppDelegate: NSObject, NSApplicationDelegate { ) } + @objc func setPref(sender: NSMenuItem) { + // sender.title tells us what to do + switch (sender.title) { + case "Default" : + defaults.set("default", forKey: "iconPref") + break + case "Alternate Dark" : + defaults.set("darkalt", forKey: "iconPref") + break + case "Emoji" : + defaults.set("emoji", forKey: "iconPref") + break + default: + break + } + + // rebuild the menu + updateIcon() + } + @objc func showAbout() { if (!infoOpen) { // create infobox window object diff --git a/LunaMac/Info.plist b/LunaMac/Info.plist index 37d4baa..3fb18da 100644 --- a/LunaMac/Info.plist +++ b/LunaMac/Info.plist @@ -19,9 +19,9 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.3 + 1.4 CFBundleVersion - 1.3 + 1.4 LSApplicationCategoryType LSMinimumSystemVersion diff --git a/LunaMac/InfoBox.xib b/LunaMac/InfoBox.xib index a049504..0c1d80f 100644 --- a/LunaMac/InfoBox.xib +++ b/LunaMac/InfoBox.xib @@ -11,14 +11,14 @@ - + - + - + - + - + - LunaMac calculates the current moon phase by your system clock (UTC). If you see a ⨂ instead of a moon phase, try again from the status bar icon's menu. + LunaMac calculates the current moon phase by your system clock (UTC). If you see a ⨂ instead of a moon phase, try again from the status bar icon's menu. + +The Alt Dark theme inverts the dark mode icons, so they look more like the moon. - + diff --git a/LunaMac/changelog.txt b/LunaMac/changelog.txt index 7116f25..e14e335 100644 --- a/LunaMac/changelog.txt +++ b/LunaMac/changelog.txt @@ -1,4 +1,8 @@ ====== Changelog ====== +v1.4 + - Added user preference for icon style + - Alt dark icons (inverted in dark mode to better represent phase) + v1.3 - Fixed window duplication bug - Changelog text loads properly diff --git a/LunaMac/png/wanc-alt-dark.png b/LunaMac/png/wanc-alt-dark.png new file mode 100644 index 0000000..8b734e5 Binary files /dev/null and b/LunaMac/png/wanc-alt-dark.png differ diff --git a/LunaMac/png/wang-alt-dark.png b/LunaMac/png/wang-alt-dark.png new file mode 100644 index 0000000..61097da Binary files /dev/null and b/LunaMac/png/wang-alt-dark.png differ diff --git a/LunaMac/png/waxc-alt-dark.png b/LunaMac/png/waxc-alt-dark.png new file mode 100644 index 0000000..3e7accb Binary files /dev/null and b/LunaMac/png/waxc-alt-dark.png differ diff --git a/LunaMac/png/waxg-alt-dark.png b/LunaMac/png/waxg-alt-dark.png new file mode 100644 index 0000000..55230b8 Binary files /dev/null and b/LunaMac/png/waxg-alt-dark.png differ