Skip to content

Commit 7a2cceb

Browse files
committed
Strip day/night brightness schedule for separate PR, hide clock options when unused
- Remove TimeOfDay struct, brightnessScheduleEnabled, dayBrightness, nightBrightness, dayStartTime, nightStartTime settings - Remove isNightTime(), scheduleBrightnessUpdate(), brightnessTimer from KioskModeManager - Remove TimeOfDayPicker and schedule UI from KioskSettingsView - Remove scheduleCheckInterval from KioskConstants - Remove related L10n keys and tests - Simplify brightness to manual-only (applyBrightness) - Clock options section now only shows when screensaver is enabled and mode is clock
1 parent 69b0743 commit 7a2cceb

File tree

7 files changed

+15
-247
lines changed

7 files changed

+15
-247
lines changed

Sources/App/Kiosk/KioskConstants.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,6 @@ public enum KioskConstants {
1919
public static let pixelShift: TimeInterval = 1.0
2020
}
2121

22-
// MARK: - Timing Intervals
23-
24-
public enum Timing {
25-
/// Schedule check interval for brightness changes
26-
public static let scheduleCheckInterval: TimeInterval = 60
27-
}
28-
2922
// MARK: - UI Dimensions
3023

3124
public enum UI {

Sources/App/Kiosk/KioskModeManager.swift

Lines changed: 11 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ public final class KioskModeManager: ObservableObject {
7777

7878
private var cancellables = Set<AnyCancellable>()
7979
private var idleTimer: Timer?
80-
private var brightnessTimer: Timer?
8180
private var pixelShiftTimer: Timer?
8281
private var originalBrightness: Float?
8382
private var preScreensaverBrightness: CGFloat?
@@ -167,7 +166,6 @@ public final class KioskModeManager: ObservableObject {
167166

168167
deinit {
169168
idleTimer?.invalidate()
170-
brightnessTimer?.invalidate()
171169
pixelShiftTimer?.invalidate()
172170
saveDebounceTimer?.invalidate()
173171
cancellables.forEach { $0.cancel() }
@@ -200,8 +198,8 @@ public final class KioskModeManager: ObservableObject {
200198
Current.Log.info("Screen auto-lock disabled")
201199
}
202200

203-
// Apply settings
204-
applyBrightnessSchedule()
201+
// Apply brightness
202+
applyBrightness()
205203
startIdleTimer()
206204

207205
onKioskModeChange?(true)
@@ -233,7 +231,6 @@ public final class KioskModeManager: ObservableObject {
233231

234232
// Stop timers
235233
stopIdleTimer()
236-
stopBrightnessTimer()
237234
stopPixelShiftTimer()
238235

239236
// Hide screensaver if active
@@ -299,9 +296,9 @@ public final class KioskModeManager: ObservableObject {
299296

300297
hideScreensaver(source: source)
301298

302-
// Restore brightness: use schedule if enabled, otherwise restore pre-screensaver level
299+
// Restore brightness: use managed level if enabled, otherwise restore pre-screensaver level
303300
if settings.brightnessControlEnabled {
304-
applyBrightnessSchedule()
301+
applyBrightness()
305302
} else if let savedBrightness = preScreensaverBrightness {
306303
UIScreen.main.brightness = savedBrightness
307304
}
@@ -422,44 +419,13 @@ public final class KioskModeManager: ObservableObject {
422419
sleepScreen()
423420
}
424421

425-
// MARK: - Brightness Schedule
422+
// MARK: - Brightness
426423

427-
private func applyBrightnessSchedule() {
424+
private func applyBrightness() {
428425
guard settings.brightnessControlEnabled else { return }
429426

430-
let brightness: Float
431-
if settings.brightnessScheduleEnabled {
432-
brightness = isNightTime() ? settings.nightBrightness : settings.dayBrightness
433-
} else {
434-
brightness = settings.manualBrightness
435-
}
436-
437-
currentBrightness = brightness
438-
UIScreen.main.brightness = CGFloat(brightness)
439-
440-
// Schedule next brightness change if schedule is enabled
441-
if settings.brightnessScheduleEnabled {
442-
scheduleBrightnessUpdate()
443-
}
444-
}
445-
446-
private func scheduleBrightnessUpdate() {
447-
stopBrightnessTimer()
448-
449-
// Check every minute for schedule changes
450-
brightnessTimer = Timer.scheduledTimer(
451-
withTimeInterval: KioskConstants.Timing.scheduleCheckInterval,
452-
repeats: true
453-
) { [weak self] _ in
454-
Task { @MainActor [weak self] in
455-
self?.applyBrightnessSchedule()
456-
}
457-
}
458-
}
459-
460-
private func stopBrightnessTimer() {
461-
brightnessTimer?.invalidate()
462-
brightnessTimer = nil
427+
currentBrightness = settings.manualBrightness
428+
UIScreen.main.brightness = CGFloat(settings.manualBrightness)
463429
}
464430

465431
// MARK: - Pixel Shift Timer
@@ -487,25 +453,6 @@ public final class KioskModeManager: ObservableObject {
487453
notifyObserversOfPixelShift()
488454
}
489455

490-
// MARK: - Time Utilities
491-
492-
private func isNightTime() -> Bool {
493-
let now = Calendar.current.dateComponents([.hour, .minute], from: Current.date())
494-
let currentTime = TimeOfDay(hour: now.hour ?? 0, minute: now.minute ?? 0)
495-
496-
let dayStart = settings.dayStartTime
497-
let nightStart = settings.nightStartTime
498-
499-
// If day starts before night in 24h time (normal case: day 07:00, night 22:00)
500-
if dayStart.isBefore(nightStart) {
501-
// Night time is: before day start OR at/after night start
502-
return currentTime.isBefore(dayStart) || !currentTime.isBefore(nightStart)
503-
} else {
504-
// If night starts before day in 24h time (e.g., night 02:00, day 06:00)
505-
return !currentTime.isBefore(nightStart) && currentTime.isBefore(dayStart)
506-
}
507-
}
508-
509456
// MARK: - Settings Persistence
510457

511458
private static func loadSettings() -> KioskSettings {
@@ -524,13 +471,10 @@ public final class KioskModeManager: ObservableObject {
524471
}
525472

526473
private func settingsDidChange(from oldValue: KioskSettings, to newValue: KioskSettings) {
527-
// Reapply brightness if schedule settings changed
528-
if oldValue.brightnessScheduleEnabled != newValue.brightnessScheduleEnabled ||
529-
oldValue.dayBrightness != newValue.dayBrightness ||
530-
oldValue.nightBrightness != newValue.nightBrightness ||
531-
oldValue.manualBrightness != newValue.manualBrightness {
474+
// Reapply brightness if setting changed
475+
if oldValue.manualBrightness != newValue.manualBrightness {
532476
if isKioskModeActive {
533-
applyBrightnessSchedule()
477+
applyBrightness()
534478
}
535479
}
536480

Sources/App/Kiosk/KioskSettings.swift

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -73,21 +73,6 @@ public struct KioskSettings: Codable, Equatable {
7373
/// Manual brightness level (0.0 - 1.0)
7474
public var manualBrightness: Float = 0.8
7575

76-
/// Enable day/night brightness schedule
77-
public var brightnessScheduleEnabled: Bool = false
78-
79-
/// Daytime brightness level (0.0 - 1.0)
80-
public var dayBrightness: Float = 0.8
81-
82-
/// Nighttime brightness level (0.0 - 1.0)
83-
public var nightBrightness: Float = 0.3
84-
85-
/// Time when day brightness starts (hour, minute)
86-
public var dayStartTime: TimeOfDay = .init(hour: 7, minute: 0)
87-
88-
/// Time when night brightness starts (hour, minute)
89-
public var nightStartTime: TimeOfDay = .init(hour: 22, minute: 0)
90-
9176
// MARK: - Screensaver
9277

9378
/// Enable screensaver
@@ -142,29 +127,6 @@ public struct KioskSettings: Codable, Equatable {
142127
public var secretExitGestureTaps: Int = 3
143128
}
144129

145-
// MARK: - Supporting Types
146-
147-
public struct TimeOfDay: Codable, Equatable {
148-
public var hour: Int
149-
public var minute: Int
150-
151-
public init(hour: Int, minute: Int) {
152-
self.hour = hour
153-
self.minute = minute
154-
}
155-
156-
public var asDateComponents: DateComponents {
157-
DateComponents(hour: hour, minute: minute)
158-
}
159-
160-
public func isBefore(_ other: TimeOfDay) -> Bool {
161-
if hour != other.hour {
162-
return hour < other.hour
163-
}
164-
return minute < other.minute
165-
}
166-
}
167-
168130
// MARK: - Enums
169131

170132
public enum ScreensaverMode: String, Codable, CaseIterable {

Sources/App/Kiosk/Settings/KioskSettingsView.swift

Lines changed: 3 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ public struct KioskSettingsView: View {
5050
coreSettingsSection
5151
brightnessSection
5252
screensaverSection
53-
clockOptionsSection
53+
if settings.screensaverEnabled, settings.screensaverMode == .clock {
54+
clockOptionsSection
55+
}
5456
}
5557
.navigationTitle(L10n.Kiosk.title)
5658
.toolbar {
@@ -262,36 +264,6 @@ public struct KioskSettingsView: View {
262264
.font(.caption)
263265
Slider(value: $settings.manualBrightness, in: 0.1 ... 1.0, step: 0.05)
264266
}
265-
266-
Toggle(isOn: $settings.brightnessScheduleEnabled) {
267-
Label(L10n.Kiosk.Brightness.schedule, systemSymbol: .clock)
268-
}
269-
270-
if settings.brightnessScheduleEnabled {
271-
VStack(alignment: .leading) {
272-
Text(L10n.Kiosk.Brightness.day(Int(settings.dayBrightness * 100)))
273-
.font(.caption)
274-
Slider(value: $settings.dayBrightness, in: 0.1 ... 1.0, step: 0.05)
275-
}
276-
277-
VStack(alignment: .leading) {
278-
Text(L10n.Kiosk.Brightness.night(Int(settings.nightBrightness * 100)))
279-
.font(.caption)
280-
Slider(value: $settings.nightBrightness, in: 0.05 ... 1.0, step: 0.05)
281-
}
282-
283-
HStack {
284-
Text(L10n.Kiosk.Brightness.dayStarts)
285-
Spacer()
286-
TimeOfDayPicker(time: $settings.dayStartTime)
287-
}
288-
289-
HStack {
290-
Text(L10n.Kiosk.Brightness.nightStarts)
291-
Spacer()
292-
TimeOfDayPicker(time: $settings.nightStartTime)
293-
}
294-
}
295267
}
296268
} header: {
297269
Text(L10n.Kiosk.Brightness.section)
@@ -414,37 +386,6 @@ public struct KioskSettingsView: View {
414386
}
415387
}
416388

417-
// MARK: - Time of Day Picker
418-
419-
struct TimeOfDayPicker: View {
420-
@Binding var time: TimeOfDay
421-
422-
var body: some View {
423-
HStack {
424-
Picker(L10n.Kiosk.Time.hour, selection: $time.hour) {
425-
ForEach(0 ..< 24, id: \.self) { hour in
426-
Text(String(format: "%02d", hour)).tag(hour)
427-
}
428-
}
429-
.pickerStyle(.wheel)
430-
.frame(width: 60)
431-
.clipped()
432-
433-
Text(":")
434-
435-
Picker(L10n.Kiosk.Time.minute, selection: $time.minute) {
436-
ForEach([0, 15, 30, 45], id: \.self) { minute in
437-
Text(String(format: "%02d", minute)).tag(minute)
438-
}
439-
}
440-
.pickerStyle(.wheel)
441-
.frame(width: 60)
442-
.clipped()
443-
}
444-
.frame(height: 100)
445-
}
446-
}
447-
448389
// MARK: - Preview
449390

450391
#Preview {

Sources/App/Resources/en.lproj/Localizable.strings

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,11 +1566,6 @@ Home Assistant is open source, advocates for privacy and runs locally in your ho
15661566
"kiosk.brightness.section" = "Brightness";
15671567
"kiosk.brightness.control" = "Brightness Control";
15681568
"kiosk.brightness.manual" = "Manual Brightness: %d%%";
1569-
"kiosk.brightness.schedule" = "Day/Night Schedule";
1570-
"kiosk.brightness.day" = "Day Brightness: %d%%";
1571-
"kiosk.brightness.night" = "Night Brightness: %d%%";
1572-
"kiosk.brightness.day_starts" = "Day starts";
1573-
"kiosk.brightness.night_starts" = "Night starts";
15741569

15751570
"kiosk.screensaver.section" = "Screensaver";
15761571
"kiosk.screensaver.toggle" = "Screensaver";
@@ -1608,5 +1603,3 @@ Home Assistant is open source, advocates for privacy and runs locally in your ho
16081603
"kiosk.corner.bottom_left" = "Bottom Left";
16091604
"kiosk.corner.bottom_right" = "Bottom Right";
16101605

1611-
"kiosk.time.hour" = "Hour";
1612-
"kiosk.time.minute" = "Minute";

Sources/Shared/Resources/Swiftgen/Strings.swift

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,24 +1712,10 @@ public enum L10n {
17121712
public enum Brightness {
17131713
/// Brightness Control
17141714
public static var control: String { return L10n.tr("Localizable", "kiosk.brightness.control") }
1715-
/// Day Brightness: %d%%
1716-
public static func day(_ p1: Int) -> String {
1717-
return L10n.tr("Localizable", "kiosk.brightness.day", p1)
1718-
}
1719-
/// Day starts
1720-
public static var dayStarts: String { return L10n.tr("Localizable", "kiosk.brightness.day_starts") }
17211715
/// Manual Brightness: %d%%
17221716
public static func manual(_ p1: Int) -> String {
17231717
return L10n.tr("Localizable", "kiosk.brightness.manual", p1)
17241718
}
1725-
/// Night Brightness: %d%%
1726-
public static func night(_ p1: Int) -> String {
1727-
return L10n.tr("Localizable", "kiosk.brightness.night", p1)
1728-
}
1729-
/// Night starts
1730-
public static var nightStarts: String { return L10n.tr("Localizable", "kiosk.brightness.night_starts") }
1731-
/// Day/Night Schedule
1732-
public static var schedule: String { return L10n.tr("Localizable", "kiosk.brightness.schedule") }
17331719
/// Brightness
17341720
public static var section: String { return L10n.tr("Localizable", "kiosk.brightness.section") }
17351721
}
@@ -1853,12 +1839,6 @@ public enum L10n {
18531839
/// Wake on Touch
18541840
public static var wakeOnTouch: String { return L10n.tr("Localizable", "kiosk.security.wake_on_touch") }
18551841
}
1856-
public enum Time {
1857-
/// Hour
1858-
public static var hour: String { return L10n.tr("Localizable", "kiosk.time.hour") }
1859-
/// Minute
1860-
public static var minute: String { return L10n.tr("Localizable", "kiosk.time.minute") }
1861-
}
18621842
}
18631843

18641844
public enum LegacyActions {

0 commit comments

Comments
 (0)