|
1 | 1 | // LoopFollow |
2 | 2 | // LiveActivitySettingsView.swift |
3 | 3 |
|
4 | | -import SwiftUI |
| 4 | +#if !targetEnvironment(macCatalyst) |
5 | 5 |
|
6 | | -struct LiveActivitySettingsView: View { |
7 | | - @State private var laEnabled: Bool = Storage.shared.laEnabled.value |
8 | | - @State private var restartConfirmed = false |
9 | | - @State private var slots: [LiveActivitySlotOption] = LAAppGroupSettings.slots() |
10 | | - @State private var smallWidgetSlot: LiveActivitySlotOption = LAAppGroupSettings.smallWidgetSlot() |
| 6 | + import SwiftUI |
11 | 7 |
|
12 | | - private let slotLabels = ["Top left", "Top right", "Bottom left", "Bottom right"] |
| 8 | + struct LiveActivitySettingsView: View { |
| 9 | + @State private var laEnabled: Bool = Storage.shared.laEnabled.value |
| 10 | + @State private var restartConfirmed = false |
| 11 | + @State private var slots: [LiveActivitySlotOption] = LAAppGroupSettings.slots() |
| 12 | + @State private var smallWidgetSlot: LiveActivitySlotOption = LAAppGroupSettings.smallWidgetSlot() |
13 | 13 |
|
14 | | - var body: some View { |
15 | | - Form { |
16 | | - Section(header: Text("Live Activity")) { |
17 | | - Toggle("Enable Live Activity", isOn: $laEnabled) |
18 | | - } |
| 14 | + private let slotLabels = ["Top left", "Top right", "Bottom left", "Bottom right"] |
| 15 | + |
| 16 | + var body: some View { |
| 17 | + Form { |
| 18 | + Section(header: Text("Live Activity")) { |
| 19 | + Toggle("Enable Live Activity", isOn: $laEnabled) |
| 20 | + } |
19 | 21 |
|
20 | | - if laEnabled { |
21 | | - Section { |
22 | | - Button(restartConfirmed ? "Live Activity Restarted" : "Restart Live Activity") { |
23 | | - LiveActivityManager.shared.forceRestart() |
24 | | - restartConfirmed = true |
25 | | - DispatchQueue.main.asyncAfter(deadline: .now() + 2) { |
26 | | - restartConfirmed = false |
| 22 | + if laEnabled { |
| 23 | + Section { |
| 24 | + Button(restartConfirmed ? "Live Activity Restarted" : "Restart Live Activity") { |
| 25 | + LiveActivityManager.shared.forceRestart() |
| 26 | + restartConfirmed = true |
| 27 | + DispatchQueue.main.asyncAfter(deadline: .now() + 2) { |
| 28 | + restartConfirmed = false |
| 29 | + } |
27 | 30 | } |
| 31 | + .disabled(restartConfirmed) |
28 | 32 | } |
29 | | - .disabled(restartConfirmed) |
30 | 33 | } |
31 | | - } |
32 | 34 |
|
33 | | - Section(header: Text("Grid Slots - Live Activity")) { |
34 | | - ForEach(0 ..< 4, id: \.self) { index in |
35 | | - Picker(slotLabels[index], selection: Binding( |
36 | | - get: { slots[index] }, |
37 | | - set: { selectSlot($0, at: index) } |
| 35 | + Section(header: Text("Grid Slots - Live Activity")) { |
| 36 | + ForEach(0 ..< 4, id: \.self) { index in |
| 37 | + Picker(slotLabels[index], selection: Binding( |
| 38 | + get: { slots[index] }, |
| 39 | + set: { selectSlot($0, at: index) } |
| 40 | + )) { |
| 41 | + ForEach(LiveActivitySlotOption.allCases, id: \.self) { option in |
| 42 | + Text(option.displayName).tag(option) |
| 43 | + } |
| 44 | + } |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + Section(header: Text("Grid Slot - CarPlay / Watch")) { |
| 49 | + Picker("Right slot", selection: Binding( |
| 50 | + get: { smallWidgetSlot }, |
| 51 | + set: { newValue in |
| 52 | + smallWidgetSlot = newValue |
| 53 | + LAAppGroupSettings.setSmallWidgetSlot(newValue) |
| 54 | + LiveActivityManager.shared.refreshFromCurrentState(reason: "small widget slot changed") |
| 55 | + } |
38 | 56 | )) { |
39 | 57 | ForEach(LiveActivitySlotOption.allCases, id: \.self) { option in |
40 | 58 | Text(option.displayName).tag(option) |
41 | 59 | } |
42 | 60 | } |
43 | 61 | } |
44 | 62 | } |
45 | | - |
46 | | - Section(header: Text("Grid Slot - CarPlay / Watch")) { |
47 | | - Picker("Right slot", selection: Binding( |
48 | | - get: { smallWidgetSlot }, |
49 | | - set: { newValue in |
50 | | - smallWidgetSlot = newValue |
51 | | - LAAppGroupSettings.setSmallWidgetSlot(newValue) |
52 | | - LiveActivityManager.shared.refreshFromCurrentState(reason: "small widget slot changed") |
53 | | - } |
54 | | - )) { |
55 | | - ForEach(LiveActivitySlotOption.allCases, id: \.self) { option in |
56 | | - Text(option.displayName).tag(option) |
57 | | - } |
58 | | - } |
| 63 | + .onReceive(Storage.shared.laEnabled.$value) { newValue in |
| 64 | + if newValue != laEnabled { laEnabled = newValue } |
59 | 65 | } |
60 | | - } |
61 | | - .onReceive(Storage.shared.laEnabled.$value) { newValue in |
62 | | - if newValue != laEnabled { laEnabled = newValue } |
63 | | - } |
64 | | - .onChange(of: laEnabled) { newValue in |
65 | | - Storage.shared.laEnabled.value = newValue |
66 | | - if newValue { |
67 | | - LiveActivityManager.shared.forceRestart() |
68 | | - } else { |
69 | | - LiveActivityManager.shared.end(dismissalPolicy: .immediate) |
| 66 | + .onChange(of: laEnabled) { newValue in |
| 67 | + Storage.shared.laEnabled.value = newValue |
| 68 | + if newValue { |
| 69 | + LiveActivityManager.shared.forceRestart() |
| 70 | + } else { |
| 71 | + LiveActivityManager.shared.end(dismissalPolicy: .immediate) |
| 72 | + } |
70 | 73 | } |
| 74 | + .preferredColorScheme(Storage.shared.appearanceMode.value.colorScheme) |
| 75 | + .navigationTitle("Live Activity") |
| 76 | + .navigationBarTitleDisplayMode(.inline) |
71 | 77 | } |
72 | | - .preferredColorScheme(Storage.shared.appearanceMode.value.colorScheme) |
73 | | - .navigationTitle("Live Activity") |
74 | | - .navigationBarTitleDisplayMode(.inline) |
75 | | - } |
76 | 78 |
|
77 | | - /// Selects an option for the given slot index, enforcing uniqueness: |
78 | | - /// if the chosen option is already in another slot, that slot is cleared to `.none`. |
79 | | - private func selectSlot(_ option: LiveActivitySlotOption, at index: Int) { |
80 | | - if option != .none { |
81 | | - for i in 0 ..< slots.count where i != index && slots[i] == option { |
82 | | - slots[i] = .none |
| 79 | + /// Selects an option for the given slot index, enforcing uniqueness: |
| 80 | + /// if the chosen option is already in another slot, that slot is cleared to `.none`. |
| 81 | + private func selectSlot(_ option: LiveActivitySlotOption, at index: Int) { |
| 82 | + if option != .none { |
| 83 | + for i in 0 ..< slots.count where i != index && slots[i] == option { |
| 84 | + slots[i] = .none |
| 85 | + } |
83 | 86 | } |
| 87 | + slots[index] = option |
| 88 | + LAAppGroupSettings.setSlots(slots) |
| 89 | + LiveActivityManager.shared.refreshFromCurrentState(reason: "slot config changed") |
84 | 90 | } |
85 | | - slots[index] = option |
86 | | - LAAppGroupSettings.setSlots(slots) |
87 | | - LiveActivityManager.shared.refreshFromCurrentState(reason: "slot config changed") |
88 | 91 | } |
89 | | -} |
| 92 | +#endif |
0 commit comments