Browse Source

v1.4 - added user pref for setting icon style

master v1.4
Claire 2 years ago
parent
commit
cfd1b6ea82
  1. 16
      LunaMac.xcodeproj/project.pbxproj
  2. 163
      LunaMac/AppDelegate.swift
  3. 4
      LunaMac/Info.plist
  4. 18
      LunaMac/InfoBox.xib
  5. 4
      LunaMac/changelog.txt
  6. BIN
      LunaMac/png/wanc-alt-dark.png
  7. BIN
      LunaMac/png/wang-alt-dark.png
  8. BIN
      LunaMac/png/waxc-alt-dark.png
  9. BIN
      LunaMac/png/waxg-alt-dark.png

16
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 = "<group>"; };
7ECD0D8528DD2A4200B90958 /* LunaMac.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = LunaMac.entitlements; sourceTree = "<group>"; };
7ECD26CB28E002A9000D5E2C /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = "<group>"; };
7EF1E35328E7FF59006F8ED9 /* wang-alt-dark.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "wang-alt-dark.png"; sourceTree = "<group>"; };
7EF1E35428E7FF59006F8ED9 /* wanc-alt-dark.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "wanc-alt-dark.png"; sourceTree = "<group>"; };
7EF1E35528E7FF59006F8ED9 /* waxc-alt-dark.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "waxc-alt-dark.png"; sourceTree = "<group>"; };
7EF1E35628E7FF5A006F8ED9 /* waxg-alt-dark.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "waxg-alt-dark.png"; sourceTree = "<group>"; };
7EF79B3228DE1E4D00FF1F49 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
7EF79B9E28DE395C00FF1F49 /* firstq-dark.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "firstq-dark.png"; sourceTree = "<group>"; };
7EF79B9F28DE395C00FF1F49 /* firstq.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = firstq.png; sourceTree = "<group>"; };
@ -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 */,

163
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

4
LunaMac/Info.plist

@ -19,9 +19,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.3</string>
<string>1.4</string>
<key>CFBundleVersion</key>
<string>1.3</string>
<string>1.4</string>
<key>LSApplicationCategoryType</key>
<string></string>
<key>LSMinimumSystemVersion</key>

18
LunaMac/InfoBox.xib

@ -11,14 +11,14 @@
<window title="About LunaMac" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" animationBehavior="default" titleVisibility="hidden" id="QvC-M9-y7g">
<windowStyleMask key="styleMask" titled="YES" closable="YES"/>
<windowPositionMask key="initialPositionMask" topStrut="YES"/>
<rect key="contentRect" x="591" y="408" width="235" height="265"/>
<rect key="contentRect" x="591" y="408" width="264" height="327"/>
<rect key="screenRect" x="0.0" y="0.0" width="1366" height="745"/>
<view key="contentView" wantsLayer="YES" id="EiT-Mj-1SZ">
<rect key="frame" x="0.0" y="0.0" width="235" height="265"/>
<rect key="frame" x="0.0" y="0.0" width="264" height="327"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="OpR-pc-qnX">
<rect key="frame" x="69" y="157" width="97" height="97"/>
<rect key="frame" x="84" y="223" width="97" height="97"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="square" bezelStyle="shadowlessSquare" image="LunaMac" imagePosition="overlaps" alignment="center" imageScaling="proportionallyUpOrDown" inset="2" id="ewn-Jd-BGA">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
@ -29,27 +29,29 @@
</buttonCell>
</button>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="24S-3e-fTg">
<rect key="frame" x="11" y="121" width="212" height="19"/>
<rect key="frame" x="26" y="188" width="212" height="19"/>
<autoresizingMask key="autoresizingMask"/>
<textFieldCell key="cell" lineBreakMode="clipping" alignment="center" title="Using LunaMac" id="3Ea-1B-yru">
<textFieldCell key="cell" lineBreakMode="clipping" alignment="center" title="Using LunaMac 1.4" id="3Ea-1B-yru">
<font key="font" metaFont="system" size="15"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Jwa-x9-RgK">
<rect key="frame" x="11" y="20" width="211" height="85"/>
<rect key="frame" x="18" y="20" width="228" height="153"/>
<autoresizingMask key="autoresizingMask"/>
<textFieldCell key="cell" selectable="YES" alignment="justified" id="ZyF-AY-vyC">
<font key="font" metaFont="system"/>
<string key="title">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.</string>
<string key="title">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.</string>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
</view>
<point key="canvasLocation" x="36.5" y="180.5"/>
<point key="canvasLocation" x="51" y="211.5"/>
</window>
<viewController id="1Dw-mw-LdK" customClass="ViewController" customModule="LunaMac" customModuleProvider="target">
<connections>

4
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

BIN
LunaMac/png/wanc-alt-dark.png

diff.bin_not_shown

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
LunaMac/png/wang-alt-dark.png

diff.bin_not_shown

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
LunaMac/png/waxc-alt-dark.png

diff.bin_not_shown

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
LunaMac/png/waxg-alt-dark.png

diff.bin_not_shown

After

Width:  |  Height:  |  Size: 1.2 KiB

Loading…
Cancel
Save