Skip to content

Commit

Permalink
Add options to lock position and release floating state, change save …
Browse files Browse the repository at this point in the history
…format
  • Loading branch information
LEOYoon-Tsaw committed Oct 30, 2021
1 parent d2aa714 commit 87be943
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 22 deletions.
8 changes: 4 additions & 4 deletions ChineseTime.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
16 changes: 16 additions & 0 deletions ChineseTime/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")!)
Expand Down
24 changes: 16 additions & 8 deletions ChineseTime/Layout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
24 changes: 23 additions & 1 deletion ChineseTime/WatchFace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
27 changes: 18 additions & 9 deletions ChineseTime/en.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="19162" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="19455" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="19162"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="19455"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand Down Expand Up @@ -625,10 +625,14 @@
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="eu3-7i-yIM"/>
<menuItem title="Bring All to Front" id="LE2-aR-0XJ">
<modifierMask key="keyEquivalentModifierMask"/>
<menuItem title="Lock" keyEquivalent="l" id="PEQ-kQ-g5U">
<connections>
<action selector="toggleLocked:" target="Voe-Tx-rLC" id="6wE-3s-Heu"/>
</connections>
</menuItem>
<menuItem title="Keep top" state="on" keyEquivalent="T" id="4Vr-av-PsQ">
<connections>
<action selector="arrangeInFront:" target="Ady-hI-5gd" id="DRN-fu-gQh"/>
<action selector="togglekeepTop:" target="Voe-Tx-rLC" id="a87-bM-KBc"/>
</connections>
</menuItem>
</items>
Expand All @@ -652,7 +656,12 @@
<outlet property="delegate" destination="Voe-Tx-rLC" id="PrD-fu-P6m"/>
</connections>
</application>
<customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModule="ChineseTime" customModuleProvider="target"/>
<customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModule="ChineseTime" customModuleProvider="target">
<connections>
<outlet property="keepTopMenuItem" destination="4Vr-av-PsQ" id="3BB-qy-pdp"/>
<outlet property="lockedMenuItem" destination="PEQ-kQ-g5U" id="l1s-l4-35J"/>
</connections>
</customObject>
<customObject id="YLy-65-1bz" customClass="NSFontManager"/>
<customObject id="Ady-hI-5gd" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
Expand Down Expand Up @@ -682,7 +691,7 @@
</windowController>
<customObject id="yq9-x3-Csw" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="95" y="270"/>
<point key="canvasLocation" x="95" y="269.5"/>
</scene>
<!--Configuration View Controller-->
<scene sceneID="ECC-jw-GxU">
Expand Down Expand Up @@ -1202,8 +1211,8 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
<datePickerCell key="cell" enabled="NO" borderStyle="bezel" alignment="left" drawsBackground="NO" useCurrentDate="YES" id="O3W-Rm-xGz">
<font key="font" metaFont="system"/>
<date key="date" timeIntervalSinceReferenceDate="656032504.52173197">
<!--2021-10-15 23:15:04 +0000-->
<date key="date" timeIntervalSinceReferenceDate="657300683.91364801">
<!--2021-10-30 15:31:23 +0000-->
</date>
<date key="minDate" timeIntervalSinceReferenceDate="-3124983600">
<!--1901-12-23 05:00:00 +0000-->
Expand Down

0 comments on commit 87be943

Please sign in to comment.