Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

Commit

Permalink
Add user defaults setting for format style
Browse files Browse the repository at this point in the history
Closes #71
  • Loading branch information
josh committed Apr 23, 2024
1 parent 5ea5482 commit 8d9e3eb
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
9 changes: 5 additions & 4 deletions Aware/macOS/MenuBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct MenuBar: Scene {
// User configurable idle time in seconds (defaults to 2 minutes)
@AppStorage("userIdleSeconds") private var userIdleSeconds: Int = 120

@AppStorage("formatStyle") private var timerFormatStyle: TimerFormatStyle.Style = .condensedAbbreviated
@AppStorage("showSeconds") private var showSeconds: Bool = false

var userIdle: Duration {
Expand All @@ -30,21 +31,21 @@ struct MenuBar: Scene {
MenuBarExtra {
MenuBarContentView()
} label: {
TimerMenuBarLabel(userIdle: userIdle, showSeconds: showSeconds)
TimerMenuBarLabel(userIdle: userIdle, timerFormatStyle: timerFormatStyle, showSeconds: showSeconds)
}
}
}

struct TimerMenuBarLabel: View {
let userIdle: Duration

var showSeconds: Bool = false
var timerFormatStyle: TimerFormatStyle.Style
var showSeconds: Bool

/// Set text refresh rate to 60 seconds, when minutes are shown
private var textRefreshRate: TimeInterval { showSeconds ? 1.0 : 60.0 }

private var timerFormat: TimerFormatStyle {
TimerFormatStyle(style: .condensedAbbreviated, includeSeconds: showSeconds)
TimerFormatStyle(style: timerFormatStyle, includeSeconds: showSeconds)
}

@State private var timerState = TimerState()
Expand Down
28 changes: 28 additions & 0 deletions Aware/visionOS/Settings.bundle/Root.plist
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,34 @@
<dict>
<key>PreferenceSpecifiers</key>
<array>
<dict>
<key>Type</key>
<string>PSMultiValueSpecifier</string>
<key>Title</key>
<string>Format Style</string>
<key>Key</key>
<string>formatStyle</string>
<key>DefaultValue</key>
<string>condensedAbbreviated</string>
<key>Values</key>
<array>
<string>abbreviated</string>
<string>condensedAbbreviated</string>
<string>narrow</string>
<string>wide</string>
<string>spellOut</string>
<string>digits</string>
</array>
<key>Titles</key>
<array>
<string>1 hr, 15 min</string>
<string>1h 15m</string>
<string>1hr 15min</string>
<string>1 hour, 15 minutes</string>
<string>one hour, fifteen minutes</string>
<string>1:15</string>
</array>
</dict>
<dict>
<key>Type</key>
<string>PSToggleSwitchSpecifier</string>
Expand Down
3 changes: 2 additions & 1 deletion Aware/visionOS/TimerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct TimerView: View {
@State private var timerState = TimerState()

@AppStorage("showSeconds") private var showSeconds: Bool = false
@AppStorage("formatStyle") private var timerFormatStyle: TimerFormatStyle.Style = .condensedAbbreviated
@AppStorage("glassBackground") private var glassBackground: Bool = true

@AppStorage("backgroundTaskInterval") private var backgroundTaskInterval: Int = 300
Expand All @@ -24,7 +25,7 @@ struct TimerView: View {
private var textRefreshRate: TimeInterval { showSeconds ? 1.0 : 60.0 }

private var timerFormat: TimerFormatStyle {
TimerFormatStyle(style: .condensedAbbreviated, includeSeconds: showSeconds)
TimerFormatStyle(style: timerFormatStyle, includeSeconds: showSeconds)
}

private var activityMonitor: ActivityMonitor {
Expand Down

0 comments on commit 8d9e3eb

Please sign in to comment.