From cfd1b6ea82823696ecf848b69fb505c04662594e Mon Sep 17 00:00:00 2001 From: Claire Date: Fri, 30 Sep 2022 22:47:06 -0700 Subject: [PATCH] v1.4 - added user pref for setting icon style --- LunaMac.xcodeproj/project.pbxproj | 16 +++ LunaMac/AppDelegate.swift | 163 +++++++++++++++++++++++++----- LunaMac/Info.plist | 4 +- LunaMac/InfoBox.xib | 18 ++-- LunaMac/changelog.txt | 4 + LunaMac/png/wanc-alt-dark.png | Bin 0 -> 1261 bytes LunaMac/png/wang-alt-dark.png | Bin 0 -> 1244 bytes LunaMac/png/waxc-alt-dark.png | Bin 0 -> 1262 bytes LunaMac/png/waxg-alt-dark.png | Bin 0 -> 1254 bytes 9 files changed, 172 insertions(+), 33 deletions(-) create mode 100644 LunaMac/png/wanc-alt-dark.png create mode 100644 LunaMac/png/wang-alt-dark.png create mode 100644 LunaMac/png/waxc-alt-dark.png create mode 100644 LunaMac/png/waxg-alt-dark.png 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 0000000000000000000000000000000000000000..8b734e5356ec66fecf91a85a51b468a67d2c4f32 GIT binary patch literal 1261 zcmaJ>TWl0n7#;%}f`L>E5$l7~A!wU0*PY$DWVg7t(zR|`mo+vKgfnN(cE@%u%uL6yUqG^coKnxP=jaVPBp6PZg4-J#doOAy3 zfB*mew;9fL?cA`wX+1#@8!{cKJYF{k@47qi_sl&L$MABmpYHZ|+eN<&TtvimTSH{V z1U)E^fIe_w21N;C&GSZ~+waakqC(qbK%m1^Ob4S0BD$mE0N9IsQbRq46{F_Qe?*an z9-|%)XSuACL?xr6>Z0A%t^%y~LPe)`w2{$@iVc{^2V}+UvplsDqn7Ndcpr#aid<6h zdt+3MRChKIxT7;iIzne zp#>2XAw&`cid?s|8lI1HA|FpAL$cD&^XZhr%kiWX;nIm@yTpaXIyPf@KCmFF`!=xe zWo+V>ST*S);M;D&w)^UBkSp1~?UihY6a+>jTe1KeRv>8&s#FU)g$pBVK5^%o*Q&!Ua;vmJUHtTgZ?F9G*4W7G(Ji~0UXSh@ z{BwSC@4wIPJ#ppd&hJmX+k4`v3okdm{a|&p^U&sFpDVB2`0Dp-2Tf+vr5CqMef`+f jeOYiJx*6dqYyB$y&<(G<~PLP>+2$Ii~qD_P5SXOpaT*SKA26p`Gyb2k~X^T^DN zy9r`R)z&~MVq*=oLQsO{j}ePi&{{R1wJK^1SVgTAtXibD^_4%0ce2^oAE5&?_ug~Q zcg}ZSGtpbM~em=iy*bP@QMRLa1fX~M{fp?rJux0HK7t#MT*3=G5qdww`DD*}GND5MJ zZGcJguI?yOBy9A11DjL@R16P}ILO60BgK##&ay3CK+sC6VM35%7?gu<#4lvz;% zWeAZ1fu=U>tcA}SX<1Q(u7s*(Uisl^ws;6NJtodgN?2!aapxYz$#V} zu?mm?tEqCC6_BY|GEhw@LWU<4`KWWQ=%j{-v}d$k9Sm|<9WCUNc?!tjTvl#=m<-*8 zoRKcozWH^sW5fHx^?MI**kAf?YGU!Izi#ZQ+Yij#`N`yX;^NayrOso8_pa%F?S;$A zv!~x(m@^Li`6KAK?+<0*gIi~(q&Bvv?RUAuJ$=W=OE>&HS!$_l{BT{`>2K~=7RG;i zJ=Xg2@r6y)uD6Fzh4Yu5*4GS{@Q;qcJkoX P=zo*T7K~T6_wV@+=gF~; literal 0 HcmV?d00001 diff --git a/LunaMac/png/waxc-alt-dark.png b/LunaMac/png/waxc-alt-dark.png new file mode 100644 index 0000000000000000000000000000000000000000..3e7accb3035057c0212708329954c8cfae7490e8 GIT binary patch literal 1262 zcmaJ>TWs4@7FBr(MRP&xFVd+*$gzGqrbzl4_i-AK|Mv<okYS|Q?(3$p}n z>LFr(Fvi5PVVE{|mmN4*?n`LpQBBf`uAO*iQAP$b&;@ugGiK%FVu)C^E2F(9rU`si z#T^Y1HB!mg03Nm-i1QRfY7E2Uf<);+1)8cpjzcNO zdlrFe=iLy2sMcc0WMi>)!&YuBQz&P25oBpU#n73I7uc$H&W*$WX>6#SOO&#Zj>DXt zcQjNGqrDDB$-BKHPZ6<^`yCTi1&k@Smd`-TjVd7m-B7xz%M8@?plAe1o(dvMbypFhQ=4jaoSuSQ@PR zHj(c&EPq?99CjdZZ6{&dWA!!|NZYQROWRqTWhoBd5d)fOd6GxHD%FBkpkt0hy~nXL z_-dMEa{~&ZVTd3Ylt>*IEXj$IL;_Vuy#)oJi9AY20EJM)>$jw@)~85_v*IROYUYymop22Y2sViamE${_b+>ouhv>ojEo6 z>6WK|6rY)yJoWIz)WP@LW`2k~fAs47&|u?8~)HJam1_lep1KF#VrYn<#V75m3eNd3lLBbmRDPa{6$~ z5W9Wusmj)SA0aDK(L%NTWcAhJro{)pZ*2@->w0TCbm4l_#Ao^WO6BH1&syitUCb{M zKYzWjb9naV^1|DPKTQAf&3!Ac{9AqfbLE7%Z~H>i-_2W3Po#!RUwwSTdE?ImU+%s7 l(D|Rp6Xm7&Y%ATc8I!k_-g|7k<1X(H6pi#LXLpTE{s)Yrw8;Pf literal 0 HcmV?d00001 diff --git a/LunaMac/png/waxg-alt-dark.png b/LunaMac/png/waxg-alt-dark.png new file mode 100644 index 0000000000000000000000000000000000000000..55230b8a9cf39baaab9f7a574dac53710594ad08 GIT binary patch literal 1254 zcmaJ>YiJx*6rMg~6bP)v6o!_pP@!A`|s}lHoV*TV1yxfe8DjM`_s0l(yWNqJsWZnfs zund7c_Q;noO%N*{cPdp>E!?kJzRQ4EhiSP1MiWGOTPpxo10vFdLyniBE=_$zk&d0A zc8LY95aeLp**+e^!SQ0n8gE#tO>MiIOt&;_z=a5qEqB<9v{r_ix2xfOEM_TkUIjHW zRGU<_P$F}F2uX?IXp7?{QdSuon7}g4EhNwJNtP4Xq(F0=mQpoAAQv7Ay9@1_R@Mg= zoZ(Z3sv{I=EZb~0nP!Ud!yz`Qsw&IzEYH(egO0{L1X{EgZSGjmVPu6)fE?c=V~fD_ zM^J{sRNFDQL7}i{*ozi2g>%NXK)@y$j&DgbuC>7}kAj#DyNp>lq5)Ft%fB9JFjvsfo12r)*jzk2LV*0R;`_s$HYnA7Gb=7Omc4OX-6;0_z3$hCUU^_0+EJXiVfU&t^u3M#2-%pn(R=f2rnFEu=o