diff --git a/ChineseTime.xcodeproj/project.pbxproj b/ChineseTime.xcodeproj/project.pbxproj index 2342fd7..35e9fe0 100644 --- a/ChineseTime.xcodeproj/project.pbxproj +++ b/ChineseTime.xcodeproj/project.pbxproj @@ -302,7 +302,7 @@ CODE_SIGN_IDENTITY = "-"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 22; + CURRENT_PROJECT_VERSION = 24; DEVELOPMENT_TEAM = 28HU5A7B46; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = ChineseTime/Info.plist; @@ -311,7 +311,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 11.0; - MARKETING_VERSION = 2.0; + MARKETING_VERSION = 2.1; PRODUCT_BUNDLE_IDENTIFIER = "Yuncao-Liu.ChineseTime"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; @@ -327,7 +327,7 @@ CODE_SIGN_IDENTITY = "-"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 22; + CURRENT_PROJECT_VERSION = 24; DEVELOPMENT_TEAM = 28HU5A7B46; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = ChineseTime/Info.plist; @@ -336,7 +336,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 11.0; - MARKETING_VERSION = 2.0; + MARKETING_VERSION = 2.1; PRODUCT_BUNDLE_IDENTIFIER = "Yuncao-Liu.ChineseTime"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; diff --git a/ChineseTime/AppDelegate.swift b/ChineseTime/AppDelegate.swift index b4cd076..fe3a8c1 100644 --- a/ChineseTime/AppDelegate.swift +++ b/ChineseTime/AppDelegate.swift @@ -9,6 +9,22 @@ import Cocoa @main class AppDelegate: NSObject, NSApplicationDelegate { + + @IBOutlet weak var lockedMenuItem: NSMenuItem! + @IBOutlet weak var keepTopMenuItem: NSMenuItem! + + @IBAction func toggleLocked(_ sender: Any) { + if let watchFace = WatchFace.currentInstance { + watchFace.locked(!watchFace.isLocked) + lockedMenuItem.state = watchFace.isLocked ? .on : .off + } + } + @IBAction func togglekeepTop(_ sender: Any) { + if let watchFace = WatchFace.currentInstance { + watchFace.setTop(!watchFace.isTop) + keepTopMenuItem.state = watchFace.isTop ? .on : .off + } + } @IBAction func showHelp(_ sender: Any) { NSWorkspace.shared.open(URL(string: "https://github.com/LEOYoon-Tsaw/ChineseTime")!) diff --git a/ChineseTime/Layout.swift b/ChineseTime/Layout.swift index 98c1d42..97a1d95 100644 --- a/ChineseTime/Layout.swift +++ b/ChineseTime/Layout.swift @@ -281,16 +281,16 @@ class WatchLayout { var encoded = "" encoded += "globalMonth: \(ChineseCalendar.globalMonth)\n" encoded += "backAlpha: \(backAlpha)\n" - encoded += "firstRing: \(firstRing.encode().replacingOccurrences(of: "\n", with: "{}"))\n" - encoded += "secondRing: \(secondRing.encode().replacingOccurrences(of: "\n", with: "{}"))\n" - encoded += "thirdRing: \(thirdRing.encode().replacingOccurrences(of: "\n", with: "{}"))\n" + encoded += "firstRing: \(firstRing.encode().replacingOccurrences(of: "\n", with: "; "))\n" + encoded += "secondRing: \(secondRing.encode().replacingOccurrences(of: "\n", with: "; "))\n" + encoded += "thirdRing: \(thirdRing.encode().replacingOccurrences(of: "\n", with: "; "))\n" encoded += "innerColor: \(innerColor.hexCode)\n" encoded += "majorTickColor: \(majorTickColor.hexCode)\n" encoded += "majorTickAlpha: \(majorTickAlpha)\n" encoded += "minorTickColor: \(minorTickColor.hexCode)\n" encoded += "minorTickAlpha: \(minorTickAlpha)\n" encoded += "fontColor: \(fontColor.hexCode)\n" - encoded += "centerFontColor: \(centerFontColor.encode().replacingOccurrences(of: "\n", with: "{}"))\n" + encoded += "centerFontColor: \(centerFontColor.encode().replacingOccurrences(of: "\n", with: "; "))\n" encoded += "evenSolarTermTickColor: \(evenSolarTermTickColor.hexCode)\n" encoded += "oddSolarTermTickColor: \(oddSolarTermTickColor.hexCode)\n" encoded += "innerColorDark: \(innerColorDark.hexCode)\n" @@ -328,18 +328,26 @@ class WatchLayout { } } + let seperatorRegex = try! NSRegularExpression(pattern: "(\\s*;|\\{\\})", options: .caseInsensitive) + func readGradient(value: String?) -> Gradient? { + guard let value = value else { return nil } + let mutableValue = NSMutableString(string: value) + seperatorRegex.replaceMatches(in: mutableValue, options: .init(rawValue: 0), range: NSMakeRange(0, mutableValue.length), withTemplate: "\n") + return Gradient(from: mutableValue as String) + } + ChineseCalendar.globalMonth = values["globalMonth"]?.boolValue ?? ChineseCalendar.globalMonth backAlpha = values["backAlpha"]?.floatValue ?? backAlpha - firstRing = Gradient(from: values["firstRing"]?.replacingOccurrences(of: "{}", with: "\n")) ?? firstRing - secondRing = Gradient(from: values["secondRing"]?.replacingOccurrences(of: "{}", with: "\n")) ?? secondRing - thirdRing = Gradient(from: values["thirdRing"]?.replacingOccurrences(of: "{}", with: "\n")) ?? thirdRing + firstRing = readGradient(value: values["firstRing"]) ?? firstRing + secondRing = readGradient(value: values["secondRing"]) ?? secondRing + thirdRing = readGradient(value: values["thirdRing"]) ?? thirdRing innerColor = values["innerColor"]?.colorValue ?? innerColor majorTickColor = values["majorTickColor"]?.colorValue ?? majorTickColor majorTickAlpha = values["majorTickAlpha"]?.floatValue ?? majorTickAlpha minorTickColor = values["minorTickColor"]?.colorValue ?? minorTickColor minorTickAlpha = values["minorTickAlpha"]?.floatValue ?? minorTickAlpha fontColor = values["fontColor"]?.colorValue ?? fontColor - centerFontColor = Gradient(from: values["centerFontColor"]?.replacingOccurrences(of: "{}", with: "\n")) ?? centerFontColor + centerFontColor = readGradient(value: values["centerFontColor"]) ?? centerFontColor evenSolarTermTickColor = values["evenSolarTermTickColor"]?.colorValue ?? evenSolarTermTickColor oddSolarTermTickColor = values["oddSolarTermTickColor"]?.colorValue ?? oddSolarTermTickColor innerColorDark = values["innerColorDark"]?.colorValue ?? innerColor diff --git a/ChineseTime/WatchFace.swift b/ChineseTime/WatchFace.swift index 20432f8..960016f 100644 --- a/ChineseTime/WatchFace.swift +++ b/ChineseTime/WatchFace.swift @@ -770,7 +770,6 @@ class WatchFaceView: NSView { subHourTextsPositions.append(subHourTick[i]) } } - drawRing(ringPath: fourthRingOuterPath, roundedRect: fourthRingOuter, gradient: fourthRingColor, angle: (currentHour - priorHour) / 2, minorTickPositions: subQuarterTick, majorTickPositions: subHourTick, textPositions: subHourTextsPositions, texts: subHourTexts, fontSize: fontSize, minorLineWidth: minorLineWidth, majorLineWidth: majorLineWidth) addMarks(position: eventInHour, on: fourthRingOuter, maskPath: fourthRingOuterPath, radius: 0.012 * shortEdge) @@ -834,6 +833,29 @@ class WatchFace: NSWindow { _visible } + var isLocked: Bool { + !self.isMovableByWindowBackground + } + var isTop: Bool { + self.level == NSWindow.Level.floating + } + + func locked(_ on: Bool) { + if on { + self.isMovableByWindowBackground = false + } else { + self.isMovableByWindowBackground = true + } + } + + func setTop(_ on: Bool) { + if on { + self.level = NSWindow.Level.floating + } else { + self.level = NSWindow.Level.normal + } + } + func getCurrentScreen() -> NSRect { var screenRect = NSScreen.main!.frame let screens = NSScreen.screens diff --git a/ChineseTime/en.lproj/Main.storyboard b/ChineseTime/en.lproj/Main.storyboard index 480e134..ed1b0d7 100644 --- a/ChineseTime/en.lproj/Main.storyboard +++ b/ChineseTime/en.lproj/Main.storyboard @@ -1,8 +1,8 @@ - + - + @@ -625,10 +625,14 @@ - - + + + + + + - + @@ -652,7 +656,12 @@ - + + + + + + @@ -682,7 +691,7 @@ - + @@ -1202,8 +1211,8 @@ - - + +