mirror of
https://github.com/FBukovina/Atoll.git
synced 2026-10-27 15:14:33 +00:00
Merge pull request #136 from Ebullioscopic/revamp/essentials
BugFixes and stuff
This commit is contained in:
commit
2f2397bc8e
11 changed files with 407 additions and 108 deletions
3
.github/assets/lockscreen-v1.2.gif
vendored
Normal file
3
.github/assets/lockscreen-v1.2.gif
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:cbbff3ac2fc835503542947eeef9b06fb09bfb5c02d1a76f2b02eee58eb2d781
|
||||||
|
size 63448889
|
||||||
|
|
@ -394,6 +394,10 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||||
self?.debouncedUpdateWindowSize()
|
self?.debouncedUpdateWindowSize()
|
||||||
}.store(in: &cancellables)
|
}.store(in: &cancellables)
|
||||||
|
|
||||||
|
Defaults.publisher(.openNotchWidth, options: []).sink { [weak self] _ in
|
||||||
|
self?.debouncedUpdateWindowSize()
|
||||||
|
}.store(in: &cancellables)
|
||||||
|
|
||||||
ReminderLiveActivityManager.shared.$activeWindowReminders
|
ReminderLiveActivityManager.shared.$activeWindowReminders
|
||||||
.receive(on: RunLoop.main)
|
.receive(on: RunLoop.main)
|
||||||
.sink { [weak self] _ in
|
.sink { [weak self] _ in
|
||||||
|
|
|
||||||
|
|
@ -894,6 +894,10 @@
|
||||||
"comment" : "A text label displaying the current value of the \"Notify before\" slider. The argument is the current value of the slider, expressed in minutes.",
|
"comment" : "A text label displaying the current value of the \"Notify before\" slider. The argument is the current value of the slider, expressed in minutes.",
|
||||||
"isCommentAutoGenerated" : true
|
"isCommentAutoGenerated" : true
|
||||||
},
|
},
|
||||||
|
"%lld px" : {
|
||||||
|
"comment" : "A label displaying the current expanded notch width value. The value is shown in pixels.",
|
||||||
|
"isCommentAutoGenerated" : true
|
||||||
|
},
|
||||||
"%lld s" : {
|
"%lld s" : {
|
||||||
"comment" : "A text view displaying the duration of the \"sneak peek\" feature in the reminder live activity section of the calendar settings view. The text is followed by a unit of measurement (\"s\").",
|
"comment" : "A text view displaying the duration of the \"sneak peek\" feature in the reminder live activity section of the calendar settings view. The text is followed by a unit of measurement (\"s\").",
|
||||||
"isCommentAutoGenerated" : true
|
"isCommentAutoGenerated" : true
|
||||||
|
|
@ -8567,6 +8571,10 @@
|
||||||
},
|
},
|
||||||
"Expand Notch with Animation" : {
|
"Expand Notch with Animation" : {
|
||||||
|
|
||||||
|
},
|
||||||
|
"Expanded notch width" : {
|
||||||
|
"comment" : "A label describing the expanded notch width setting.",
|
||||||
|
"isCommentAutoGenerated" : true
|
||||||
},
|
},
|
||||||
"Extensions" : {
|
"Extensions" : {
|
||||||
"localizations" : {
|
"localizations" : {
|
||||||
|
|
@ -14533,6 +14541,10 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"Notch Width" : {
|
||||||
|
"comment" : "A section header for adjusting the expanded notch width.",
|
||||||
|
"isCommentAutoGenerated" : true
|
||||||
|
},
|
||||||
"Notify before" : {
|
"Notify before" : {
|
||||||
"comment" : "A label describing the slider that allows the user to set a reminder lead time.",
|
"comment" : "A label describing the slider that allows the user to set a reminder lead time.",
|
||||||
"isCommentAutoGenerated" : true
|
"isCommentAutoGenerated" : true
|
||||||
|
|
@ -15692,6 +15704,10 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"Reset Width" : {
|
||||||
|
"comment" : "A button to reset the expanded notch width to its default value.",
|
||||||
|
"isCommentAutoGenerated" : true
|
||||||
|
},
|
||||||
"Restart" : {
|
"Restart" : {
|
||||||
"localizations" : {
|
"localizations" : {
|
||||||
"ar" : {
|
"ar" : {
|
||||||
|
|
|
||||||
|
|
@ -628,6 +628,7 @@ struct SettingsView: View {
|
||||||
SettingsSearchEntry(tab: .appearance, title: "Enable window shadow", keywords: ["shadow", "appearance"], highlightID: SettingsTab.appearance.highlightID(for: "Enable window shadow")),
|
SettingsSearchEntry(tab: .appearance, title: "Enable window shadow", keywords: ["shadow", "appearance"], highlightID: SettingsTab.appearance.highlightID(for: "Enable window shadow")),
|
||||||
SettingsSearchEntry(tab: .appearance, title: "Corner radius scaling", keywords: ["corner radius", "shape"], highlightID: SettingsTab.appearance.highlightID(for: "Corner radius scaling")),
|
SettingsSearchEntry(tab: .appearance, title: "Corner radius scaling", keywords: ["corner radius", "shape"], highlightID: SettingsTab.appearance.highlightID(for: "Corner radius scaling")),
|
||||||
SettingsSearchEntry(tab: .appearance, title: "Use simpler close animation", keywords: ["close animation", "notch"], highlightID: SettingsTab.appearance.highlightID(for: "Use simpler close animation")),
|
SettingsSearchEntry(tab: .appearance, title: "Use simpler close animation", keywords: ["close animation", "notch"], highlightID: SettingsTab.appearance.highlightID(for: "Use simpler close animation")),
|
||||||
|
SettingsSearchEntry(tab: .appearance, title: "Notch Width", keywords: ["expanded notch", "width", "resize"], highlightID: SettingsTab.appearance.highlightID(for: "Expanded notch width")),
|
||||||
SettingsSearchEntry(tab: .appearance, title: "Enable colored spectrograms", keywords: ["spectrogram", "audio"], highlightID: SettingsTab.appearance.highlightID(for: "Enable colored spectrograms")),
|
SettingsSearchEntry(tab: .appearance, title: "Enable colored spectrograms", keywords: ["spectrogram", "audio"], highlightID: SettingsTab.appearance.highlightID(for: "Enable colored spectrograms")),
|
||||||
SettingsSearchEntry(tab: .appearance, title: "Enable blur effect behind album art", keywords: ["blur", "album art"], highlightID: SettingsTab.appearance.highlightID(for: "Enable blur effect behind album art")),
|
SettingsSearchEntry(tab: .appearance, title: "Enable blur effect behind album art", keywords: ["blur", "album art"], highlightID: SettingsTab.appearance.highlightID(for: "Enable blur effect behind album art")),
|
||||||
SettingsSearchEntry(tab: .appearance, title: "Slider color", keywords: ["slider", "accent"], highlightID: SettingsTab.appearance.highlightID(for: "Slider color")),
|
SettingsSearchEntry(tab: .appearance, title: "Slider color", keywords: ["slider", "accent"], highlightID: SettingsTab.appearance.highlightID(for: "Slider color")),
|
||||||
|
|
@ -1783,8 +1784,8 @@ struct CalendarSettings: View {
|
||||||
HStack {
|
HStack {
|
||||||
Button("Request Access") {
|
Button("Request Access") {
|
||||||
Task {
|
Task {
|
||||||
await calendarManager.checkCalendarAuthorization(forceReload: true)
|
await calendarManager.checkCalendarAuthorization()
|
||||||
await calendarManager.checkReminderAuthorization(forceReload: true)
|
await calendarManager.checkReminderAuthorization()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.buttonStyle(.borderedProminent)
|
.buttonStyle(.borderedProminent)
|
||||||
|
|
@ -2173,6 +2174,8 @@ struct Appearance: View {
|
||||||
@Default(.useMusicVisualizer) var useMusicVisualizer
|
@Default(.useMusicVisualizer) var useMusicVisualizer
|
||||||
@Default(.customVisualizers) var customVisualizers
|
@Default(.customVisualizers) var customVisualizers
|
||||||
@Default(.selectedVisualizer) var selectedVisualizer
|
@Default(.selectedVisualizer) var selectedVisualizer
|
||||||
|
@Default(.openNotchWidth) var openNotchWidth
|
||||||
|
@Default(.enableMinimalisticUI) var enableMinimalisticUI
|
||||||
let icons: [String] = ["logo2"]
|
let icons: [String] = ["logo2"]
|
||||||
@State private var selectedIcon: String = "logo2"
|
@State private var selectedIcon: String = "logo2"
|
||||||
@State private var selectedListVisualizer: CustomVisualizer? = nil
|
@State private var selectedListVisualizer: CustomVisualizer? = nil
|
||||||
|
|
@ -2182,6 +2185,9 @@ struct Appearance: View {
|
||||||
@State private var url: String = ""
|
@State private var url: String = ""
|
||||||
@State private var speed: CGFloat = 1.0
|
@State private var speed: CGFloat = 1.0
|
||||||
|
|
||||||
|
private let notchWidthRange: ClosedRange<Double> = 640...900
|
||||||
|
private let defaultOpenNotchWidth: CGFloat = 640
|
||||||
|
|
||||||
private func highlightID(_ title: String) -> String {
|
private func highlightID(_ title: String) -> String {
|
||||||
SettingsTab.appearance.highlightID(for: title)
|
SettingsTab.appearance.highlightID(for: title)
|
||||||
}
|
}
|
||||||
|
|
@ -2202,6 +2208,8 @@ struct Appearance: View {
|
||||||
Text("General")
|
Text("General")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
notchWidthControls()
|
||||||
|
|
||||||
Section {
|
Section {
|
||||||
Defaults.Toggle("Enable colored spectrograms", key: .coloredSpectrogram)
|
Defaults.Toggle("Enable colored spectrograms", key: .coloredSpectrogram)
|
||||||
.settingsHighlight(id: highlightID("Enable colored spectrograms"))
|
.settingsHighlight(id: highlightID("Enable colored spectrograms"))
|
||||||
|
|
@ -2463,6 +2471,61 @@ struct Appearance: View {
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ViewBuilder
|
||||||
|
private func notchWidthControls() -> some View {
|
||||||
|
Section {
|
||||||
|
let widthBinding = Binding<Double>(
|
||||||
|
get: { Double(openNotchWidth) },
|
||||||
|
set: { newValue in
|
||||||
|
let clamped = min(max(newValue, notchWidthRange.lowerBound), notchWidthRange.upperBound)
|
||||||
|
let value = CGFloat(clamped)
|
||||||
|
if openNotchWidth != value {
|
||||||
|
openNotchWidth = value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
VStack(alignment: .leading, spacing: 10) {
|
||||||
|
Slider(
|
||||||
|
value: widthBinding,
|
||||||
|
in: notchWidthRange,
|
||||||
|
step: 10
|
||||||
|
) {
|
||||||
|
HStack {
|
||||||
|
Text("Expanded notch width")
|
||||||
|
Spacer()
|
||||||
|
Text("\(Int(openNotchWidth)) px")
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.disabled(enableMinimalisticUI)
|
||||||
|
.settingsHighlight(id: highlightID("Expanded notch width"))
|
||||||
|
|
||||||
|
HStack {
|
||||||
|
Spacer()
|
||||||
|
Button("Reset Width") {
|
||||||
|
openNotchWidth = defaultOpenNotchWidth
|
||||||
|
}
|
||||||
|
.disabled(abs(openNotchWidth - defaultOpenNotchWidth) < 0.5)
|
||||||
|
.buttonStyle(.bordered)
|
||||||
|
}
|
||||||
|
|
||||||
|
let description = enableMinimalisticUI
|
||||||
|
? "Width adjustments apply only to the standard notch layout. Disable Minimalistic UI to edit this value."
|
||||||
|
: "Extend the notch span so the clipboard, colour picker, and other trailing icons remain visible on scaled displays (e.g. More Space)."
|
||||||
|
|
||||||
|
Text(description)
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
}
|
||||||
|
} header: {
|
||||||
|
HStack {
|
||||||
|
Text("Notch Width")
|
||||||
|
customBadge(text: "Beta")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct LockScreenSettings: View {
|
struct LockScreenSettings: View {
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,9 @@ class BluetoothAudioManager: ObservableObject {
|
||||||
private var isPmsetRefreshInFlight = false
|
private var isPmsetRefreshInFlight = false
|
||||||
private var lastPmsetRefreshDate: Date?
|
private var lastPmsetRefreshDate: Date?
|
||||||
private let pmsetRefreshCooldown: TimeInterval = 5
|
private let pmsetRefreshCooldown: TimeInterval = 5
|
||||||
|
private var hudBatteryWaitTasks: [UUID: Task<Void, Never>] = [:]
|
||||||
|
private let hudBatteryWaitInterval: TimeInterval = 0.3
|
||||||
|
private let hudBatteryWaitTimeout: TimeInterval = 1.8
|
||||||
|
|
||||||
// MARK: - Initialization
|
// MARK: - Initialization
|
||||||
private init() {
|
private init() {
|
||||||
|
|
@ -244,13 +247,16 @@ class BluetoothAudioManager: ObservableObject {
|
||||||
.compactMap { $0.addressString }
|
.compactMap { $0.addressString }
|
||||||
|
|
||||||
// Remove disconnected devices
|
// Remove disconnected devices
|
||||||
let previousCount = connectedDevices.count
|
let removedDevices = connectedDevices.filter { device in
|
||||||
|
!currentlyConnectedAddresses.contains(device.address)
|
||||||
|
}
|
||||||
connectedDevices.removeAll { device in
|
connectedDevices.removeAll { device in
|
||||||
!currentlyConnectedAddresses.contains(device.address)
|
!currentlyConnectedAddresses.contains(device.address)
|
||||||
}
|
}
|
||||||
|
|
||||||
if connectedDevices.count < previousCount {
|
if !removedDevices.isEmpty {
|
||||||
print("🎧 [BluetoothAudioManager] 👋 Audio device(s) disconnected")
|
print("🎧 [BluetoothAudioManager] 👋 Audio device(s) disconnected")
|
||||||
|
removedDevices.forEach { cancelHUDBatteryWait(for: $0) }
|
||||||
}
|
}
|
||||||
|
|
||||||
isBluetoothAudioConnected = !connectedDevices.isEmpty
|
isBluetoothAudioConnected = !connectedDevices.isEmpty
|
||||||
|
|
@ -304,7 +310,9 @@ class BluetoothAudioManager: ObservableObject {
|
||||||
|
|
||||||
// Remove from connected devices
|
// Remove from connected devices
|
||||||
let address = device.addressString ?? "Unknown"
|
let address = device.addressString ?? "Unknown"
|
||||||
|
let removed = connectedDevices.filter { $0.address == address }
|
||||||
connectedDevices.removeAll { $0.address == address }
|
connectedDevices.removeAll { $0.address == address }
|
||||||
|
removed.forEach { cancelHUDBatteryWait(for: $0) }
|
||||||
isBluetoothAudioConnected = !connectedDevices.isEmpty
|
isBluetoothAudioConnected = !connectedDevices.isEmpty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1324,6 +1332,20 @@ class BluetoothAudioManager: ObservableObject {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func cancelHUDBatteryWait(for device: BluetoothAudioDevice) {
|
||||||
|
let cancelBlock = { [weak self] in
|
||||||
|
guard let self else { return }
|
||||||
|
self.hudBatteryWaitTasks[device.id]?.cancel()
|
||||||
|
self.hudBatteryWaitTasks.removeValue(forKey: device.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
if Thread.isMainThread {
|
||||||
|
cancelBlock()
|
||||||
|
} else {
|
||||||
|
DispatchQueue.main.async(execute: cancelBlock)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private func normalizeBluetoothIdentifier(_ value: String) -> String {
|
private func normalizeBluetoothIdentifier(_ value: String) -> String {
|
||||||
return value
|
return value
|
||||||
.lowercased()
|
.lowercased()
|
||||||
|
|
@ -1346,21 +1368,63 @@ class BluetoothAudioManager: ObservableObject {
|
||||||
/// Shows HUD notification for newly connected audio device
|
/// Shows HUD notification for newly connected audio device
|
||||||
private func showDeviceConnectedHUD(_ device: BluetoothAudioDevice) {
|
private func showDeviceConnectedHUD(_ device: BluetoothAudioDevice) {
|
||||||
guard Defaults[.showBluetoothDeviceConnections] else { return }
|
guard Defaults[.showBluetoothDeviceConnections] else { return }
|
||||||
|
|
||||||
print("🎧 [BluetoothAudioManager] 📱 Showing device connected HUD")
|
|
||||||
|
|
||||||
// Convert battery percentage to 0.0-1.0 value
|
|
||||||
let reportedBattery = bestBatteryLevel(for: device)
|
|
||||||
|
|
||||||
let batteryValue: CGFloat = if let battery = reportedBattery {
|
cancelHUDBatteryWait(for: device)
|
||||||
CGFloat(clampBatteryPercentage(battery)) / 100.0
|
|
||||||
|
if let battery = bestBatteryLevel(for: device) {
|
||||||
|
presentDeviceConnectedHUD(device: device, batteryLevel: battery)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
requestPmsetFallback(reason: "hud missing battery")
|
||||||
|
|
||||||
|
let task = Task.detached(priority: .utility) { [weak self] in
|
||||||
|
guard let self else { return }
|
||||||
|
let deadline = Date().addingTimeInterval(self.hudBatteryWaitTimeout)
|
||||||
|
while Date() < deadline {
|
||||||
|
try? await Task.sleep(nanoseconds: UInt64(self.hudBatteryWaitInterval * 1_000_000_000))
|
||||||
|
guard !Task.isCancelled else { return }
|
||||||
|
|
||||||
|
let batteryInfo = await MainActor.run { () -> (BluetoothAudioDevice, Int)? in
|
||||||
|
guard let refreshedDevice = self.connectedDevices.first(where: { $0.id == device.id }),
|
||||||
|
let battery = self.bestBatteryLevel(for: refreshedDevice) else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return (refreshedDevice, battery)
|
||||||
|
}
|
||||||
|
|
||||||
|
if let (refreshedDevice, battery) = batteryInfo {
|
||||||
|
await MainActor.run {
|
||||||
|
self.presentDeviceConnectedHUD(device: refreshedDevice, batteryLevel: battery)
|
||||||
|
}
|
||||||
|
self.cancelHUDBatteryWait(for: device)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
guard !Task.isCancelled else { return }
|
||||||
|
await MainActor.run {
|
||||||
|
self.presentDeviceConnectedHUD(device: device, batteryLevel: nil)
|
||||||
|
}
|
||||||
|
self.cancelHUDBatteryWait(for: device)
|
||||||
|
}
|
||||||
|
|
||||||
|
hudBatteryWaitTasks[device.id] = task
|
||||||
|
}
|
||||||
|
|
||||||
|
private func presentDeviceConnectedHUD(device: BluetoothAudioDevice, batteryLevel: Int?) {
|
||||||
|
guard Defaults[.showBluetoothDeviceConnections] else { return }
|
||||||
|
|
||||||
|
print("🎧 [BluetoothAudioManager] 📱 Showing device connected HUD")
|
||||||
|
|
||||||
|
let batteryValue: CGFloat = if let batteryLevel {
|
||||||
|
CGFloat(clampBatteryPercentage(batteryLevel)) / 100.0
|
||||||
} else {
|
} else {
|
||||||
0.0 // 0 means battery info not available
|
0.0
|
||||||
}
|
}
|
||||||
|
|
||||||
HUDSuppressionCoordinator.shared.suppressVolumeHUD(for: 1.5)
|
HUDSuppressionCoordinator.shared.suppressVolumeHUD(for: 1.5)
|
||||||
|
|
||||||
// Show HUD via coordinator
|
|
||||||
coordinator.toggleSneakPeek(
|
coordinator.toggleSneakPeek(
|
||||||
status: true,
|
status: true,
|
||||||
type: .bluetoothAudio,
|
type: .bluetoothAudio,
|
||||||
|
|
@ -1382,6 +1446,8 @@ class BluetoothAudioManager: ObservableObject {
|
||||||
dnc.removeObserver(self)
|
dnc.removeObserver(self)
|
||||||
observers.removeAll()
|
observers.removeAll()
|
||||||
cancellables.removeAll()
|
cancellables.removeAll()
|
||||||
|
hudBatteryWaitTasks.values.forEach { $0.cancel() }
|
||||||
|
hudBatteryWaitTasks.removeAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
|
|
|
||||||
|
|
@ -20,21 +20,24 @@ class CalendarManager: ObservableObject {
|
||||||
@Published var allCalendars: [CalendarModel] = []
|
@Published var allCalendars: [CalendarModel] = []
|
||||||
@Published var eventCalendars: [CalendarModel] = []
|
@Published var eventCalendars: [CalendarModel] = []
|
||||||
@Published var reminderLists: [CalendarModel] = []
|
@Published var reminderLists: [CalendarModel] = []
|
||||||
|
@Published var selectedCalendarIDs: Set<String> = []
|
||||||
@Published var calendarAuthorizationStatus: EKAuthorizationStatus = .notDetermined
|
@Published var calendarAuthorizationStatus: EKAuthorizationStatus = .notDetermined
|
||||||
@Published var reminderAuthorizationStatus: EKAuthorizationStatus = .notDetermined
|
@Published var reminderAuthorizationStatus: EKAuthorizationStatus = .notDetermined
|
||||||
|
|
||||||
private var selectedCalendars: [CalendarModel] = []
|
private var selectedCalendars: [CalendarModel] = []
|
||||||
private let calendarService = CalendarService()
|
private let calendarService = CalendarService()
|
||||||
|
private var lastEventsFetchDate: Date?
|
||||||
|
private let reloadRefreshInterval: TimeInterval = 15
|
||||||
private var eventStoreChangedObserver: NSObjectProtocol?
|
private var eventStoreChangedObserver: NSObjectProtocol?
|
||||||
|
|
||||||
var hasCalendarAccess: Bool { isAuthorized(calendarAuthorizationStatus) }
|
var hasCalendarAccess: Bool { isAuthorized(calendarAuthorizationStatus) }
|
||||||
var hasReminderAccess: Bool { isAuthorized(reminderAuthorizationStatus) }
|
var hasReminderAccess: Bool { isAuthorized(reminderAuthorizationStatus) }
|
||||||
|
|
||||||
private init() {
|
private init() {
|
||||||
self.currentWeekStartDate = CalendarManager.startOfDay(Date())
|
currentWeekStartDate = CalendarManager.startOfDay(Date())
|
||||||
setupEventStoreChangedObserver()
|
setupEventStoreChangedObserver()
|
||||||
Task {
|
Task {
|
||||||
await self.bootstrapAuthorizations()
|
await reloadCalendarAndReminderLists()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -51,111 +54,100 @@ class CalendarManager: ObservableObject {
|
||||||
queue: .main
|
queue: .main
|
||||||
) { [weak self] _ in
|
) { [weak self] _ in
|
||||||
Task {
|
Task {
|
||||||
await self?.reloadCalendarAndReminderLists()
|
guard let self else { return }
|
||||||
|
await self.reloadCalendarAndReminderLists()
|
||||||
|
await self.maybeRefreshEventsAfterReload()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
func reloadCalendarAndReminderLists() async {
|
func reloadCalendarAndReminderLists() async {
|
||||||
let all = await calendarService.calendars()
|
let allCalendars = await calendarService.calendars()
|
||||||
self.eventCalendars = all.filter { !$0.isReminder }
|
eventCalendars = allCalendars.filter { !$0.isReminder }
|
||||||
self.reminderLists = all.filter { $0.isReminder }
|
reminderLists = allCalendars.filter { $0.isReminder }
|
||||||
self.allCalendars = all // for legacy compatibility, can be removed if not needed
|
self.allCalendars = allCalendars
|
||||||
updateSelectedCalendars()
|
updateSelectedCalendars()
|
||||||
}
|
}
|
||||||
|
|
||||||
private func bootstrapAuthorizations() async {
|
@MainActor
|
||||||
await checkCalendarAuthorization(forceReload: true)
|
private func maybeRefreshEventsAfterReload() async {
|
||||||
await checkReminderAuthorization(forceReload: true)
|
guard hasCalendarAccess else { return }
|
||||||
}
|
let now = Date()
|
||||||
|
if let lastFetch = lastEventsFetchDate, now.timeIntervalSince(lastFetch) < reloadRefreshInterval {
|
||||||
private func refreshAuthorizationStatuses() {
|
return
|
||||||
calendarAuthorizationStatus = EKEventStore.authorizationStatus(for: .event)
|
}
|
||||||
reminderAuthorizationStatus = EKEventStore.authorizationStatus(for: .reminder)
|
await updateEvents()
|
||||||
}
|
}
|
||||||
|
|
||||||
private func isAuthorized(_ status: EKAuthorizationStatus) -> Bool {
|
private func isAuthorized(_ status: EKAuthorizationStatus) -> Bool {
|
||||||
switch status {
|
switch status {
|
||||||
case .fullAccess, .authorized:
|
case .authorized, .fullAccess:
|
||||||
return true
|
return true
|
||||||
default:
|
default:
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkCalendarAuthorization(forceReload: Bool = false) async {
|
func checkCalendarAuthorization() async {
|
||||||
refreshAuthorizationStatuses()
|
let status = EKEventStore.authorizationStatus(for: .event)
|
||||||
let status = calendarAuthorizationStatus
|
calendarAuthorizationStatus = status
|
||||||
print("📅 Current calendar authorization status: \(status.rawValue)")
|
|
||||||
|
|
||||||
switch status {
|
switch status {
|
||||||
case .notDetermined:
|
case .notDetermined:
|
||||||
let granted = await calendarService.requestAccess(to: .event)
|
let granted = await calendarService.requestAccess(to: .event)
|
||||||
refreshAuthorizationStatuses()
|
calendarAuthorizationStatus = granted ? .fullAccess : .denied
|
||||||
if granted || hasCalendarAccess {
|
if granted {
|
||||||
await reloadCalendarAndReminderLists()
|
await reloadCalendarAndReminderLists()
|
||||||
await updateEvents()
|
await updateEvents()
|
||||||
}
|
}
|
||||||
case .restricted, .denied:
|
case .restricted, .denied:
|
||||||
NSLog("Calendar access denied or restricted")
|
NSLog("Calendar access denied or restricted")
|
||||||
case .writeOnly:
|
case .authorized, .fullAccess:
|
||||||
NSLog("Calendar write-only access")
|
|
||||||
case .fullAccess:
|
|
||||||
guard forceReload else { return }
|
|
||||||
await reloadCalendarAndReminderLists()
|
await reloadCalendarAndReminderLists()
|
||||||
await updateEvents()
|
await updateEvents()
|
||||||
|
case .writeOnly:
|
||||||
|
NSLog("Calendar write only")
|
||||||
@unknown default:
|
@unknown default:
|
||||||
if isAuthorized(status) {
|
NSLog("Unknown calendar authorization status")
|
||||||
guard forceReload else { return }
|
|
||||||
await reloadCalendarAndReminderLists()
|
|
||||||
await updateEvents()
|
|
||||||
} else {
|
|
||||||
print("Unknown authorization status: \(status.rawValue)")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkReminderAuthorization(forceReload: Bool = false) async {
|
func checkReminderAuthorization() async {
|
||||||
refreshAuthorizationStatuses()
|
let status = EKEventStore.authorizationStatus(for: .reminder)
|
||||||
let status = reminderAuthorizationStatus
|
reminderAuthorizationStatus = status
|
||||||
print("📅 Current reminder authorization status: \(status.rawValue)")
|
|
||||||
|
|
||||||
switch status {
|
switch status {
|
||||||
case .notDetermined:
|
case .notDetermined:
|
||||||
let granted = await calendarService.requestAccess(to: .reminder)
|
let granted = await calendarService.requestAccess(to: .reminder)
|
||||||
refreshAuthorizationStatuses()
|
reminderAuthorizationStatus = granted ? .fullAccess : .denied
|
||||||
if granted || hasReminderAccess {
|
if granted {
|
||||||
await reloadCalendarAndReminderLists()
|
await reloadCalendarAndReminderLists()
|
||||||
}
|
}
|
||||||
case .restricted, .denied:
|
case .restricted, .denied:
|
||||||
NSLog("Reminder access denied or restricted")
|
NSLog("Reminder access denied or restricted")
|
||||||
case .writeOnly:
|
case .authorized, .fullAccess:
|
||||||
NSLog("Reminder write-only access")
|
|
||||||
case .fullAccess:
|
|
||||||
guard forceReload else { return }
|
|
||||||
await reloadCalendarAndReminderLists()
|
await reloadCalendarAndReminderLists()
|
||||||
|
case .writeOnly:
|
||||||
|
NSLog("Reminder write only")
|
||||||
@unknown default:
|
@unknown default:
|
||||||
if isAuthorized(status) {
|
NSLog("Unknown reminder authorization status")
|
||||||
guard forceReload else { return }
|
|
||||||
await reloadCalendarAndReminderLists()
|
|
||||||
} else {
|
|
||||||
print("Unknown reminder authorization status: \(status.rawValue)")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateSelectedCalendars() {
|
func updateSelectedCalendars() {
|
||||||
selectedCalendars = allCalendars.filter { getCalendarSelected($0) }
|
switch Defaults[.calendarSelectionState] {
|
||||||
|
case .all:
|
||||||
|
selectedCalendarIDs = Set(allCalendars.map { $0.id })
|
||||||
|
case .selected(let identifiers):
|
||||||
|
selectedCalendarIDs = identifiers
|
||||||
|
}
|
||||||
|
|
||||||
|
selectedCalendars = allCalendars.filter { selectedCalendarIDs.contains($0.id) }
|
||||||
}
|
}
|
||||||
|
|
||||||
func getCalendarSelected(_ calendar: CalendarModel) -> Bool {
|
func getCalendarSelected(_ calendar: CalendarModel) -> Bool {
|
||||||
switch Defaults[.calendarSelectionState] {
|
selectedCalendarIDs.contains(calendar.id)
|
||||||
case .all:
|
|
||||||
return true
|
|
||||||
case .selected(let identifiers):
|
|
||||||
return identifiers.contains(calendar.id)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func setCalendarSelected(_ calendar: CalendarModel, isSelected: Bool) async {
|
func setCalendarSelected(_ calendar: CalendarModel, isSelected: Bool) async {
|
||||||
|
|
@ -167,7 +159,6 @@ class CalendarManager: ObservableObject {
|
||||||
let identifiers = Set(allCalendars.map { $0.id }).subtracting([calendar.id])
|
let identifiers = Set(allCalendars.map { $0.id }).subtracting([calendar.id])
|
||||||
selectionState = .selected(identifiers)
|
selectionState = .selected(identifiers)
|
||||||
}
|
}
|
||||||
|
|
||||||
case .selected(var identifiers):
|
case .selected(var identifiers):
|
||||||
if isSelected {
|
if isSelected {
|
||||||
identifiers.insert(calendar.id)
|
identifiers.insert(calendar.id)
|
||||||
|
|
@ -175,9 +166,11 @@ class CalendarManager: ObservableObject {
|
||||||
identifiers.remove(calendar.id)
|
identifiers.remove(calendar.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
selectionState =
|
if identifiers.isEmpty || identifiers.count == allCalendars.count {
|
||||||
identifiers.isEmpty
|
selectionState = .all
|
||||||
? .all : identifiers.count == allCalendars.count ? .all : .selected(identifiers) // if empty, select all
|
} else {
|
||||||
|
selectionState = .selected(identifiers)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Defaults[.calendarSelectionState] = selectionState
|
Defaults[.calendarSelectionState] = selectionState
|
||||||
|
|
@ -186,7 +179,7 @@ class CalendarManager: ObservableObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
static func startOfDay(_ date: Date) -> Date {
|
static func startOfDay(_ date: Date) -> Date {
|
||||||
return Calendar.current.startOfDay(for: date)
|
Calendar.current.startOfDay(for: date)
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateCurrentDate(_ date: Date) async {
|
func updateCurrentDate(_ date: Date) async {
|
||||||
|
|
@ -196,12 +189,13 @@ class CalendarManager: ObservableObject {
|
||||||
|
|
||||||
private func updateEvents() async {
|
private func updateEvents() async {
|
||||||
let calendarIDs = selectedCalendars.map { $0.id }
|
let calendarIDs = selectedCalendars.map { $0.id }
|
||||||
let eventsResult = await calendarService.events(
|
let events = await calendarService.events(
|
||||||
from: currentWeekStartDate,
|
from: currentWeekStartDate,
|
||||||
to: Calendar.current.date(byAdding: .day, value: 1, to: currentWeekStartDate)!,
|
to: Calendar.current.date(byAdding: .day, value: 1, to: currentWeekStartDate)!,
|
||||||
calendars: calendarIDs
|
calendars: calendarIDs
|
||||||
)
|
)
|
||||||
self.events = eventsResult
|
self.events = events
|
||||||
|
lastEventsFetchDate = Date()
|
||||||
}
|
}
|
||||||
|
|
||||||
func setReminderCompleted(reminderID: String, completed: Bool) async {
|
func setReminderCompleted(reminderID: String, completed: Bool) async {
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,19 @@ final class ReminderLiveActivityManager: ObservableObject {
|
||||||
private var evaluationTask: Task<Void, Never>?
|
private var evaluationTask: Task<Void, Never>?
|
||||||
private var hasShownCriticalSneakPeek = false
|
private var hasShownCriticalSneakPeek = false
|
||||||
private var latestEvents: [EventModel] = []
|
private var latestEvents: [EventModel] = []
|
||||||
|
private var pendingEventsSnapshot: [EventModel]? = nil
|
||||||
|
private var eventsUpdateDebounceTask: Task<Void, Never>? { didSet { oldValue?.cancel() } }
|
||||||
|
private var upcomingComputationTask: Task<Void, Never>? { didSet { oldValue?.cancel() } }
|
||||||
|
private let eventsDebounceInterval: TimeInterval = 0.35
|
||||||
|
private var settingsUpdateTask: Task<Void, Never>? { didSet { oldValue?.cancel() } }
|
||||||
|
private var pendingSettingsAction: (() -> Void)?
|
||||||
|
private var pendingSettingsReason: String?
|
||||||
|
private let settingsUpdateDebounceInterval: TimeInterval = 0.2
|
||||||
|
private var suppressUpdatesForLock = false
|
||||||
|
|
||||||
|
private var lastAppliedLeadTime = Defaults[.reminderLeadTime]
|
||||||
|
private var lastAppliedHideAllDay = Defaults[.hideAllDayEvents]
|
||||||
|
private var lastAppliedHideCompleted = Defaults[.hideCompletedReminders]
|
||||||
|
|
||||||
private let calendarManager = CalendarManager.shared
|
private let calendarManager = CalendarManager.shared
|
||||||
|
|
||||||
|
|
@ -67,21 +80,35 @@ final class ReminderLiveActivityManager: ObservableObject {
|
||||||
.store(in: &cancellables)
|
.store(in: &cancellables)
|
||||||
|
|
||||||
Defaults.publisher(.reminderLeadTime, options: [])
|
Defaults.publisher(.reminderLeadTime, options: [])
|
||||||
.sink { [weak self] _ in
|
.map(\.newValue)
|
||||||
|
.sink { [weak self] newValue in
|
||||||
guard let self else { return }
|
guard let self else { return }
|
||||||
self.recalculateUpcomingEntries(reason: "lead-time")
|
guard newValue != self.lastAppliedLeadTime else { return }
|
||||||
|
self.scheduleSettingsRecalculation(reason: "lead-time") {
|
||||||
|
self.lastAppliedLeadTime = newValue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.store(in: &cancellables)
|
.store(in: &cancellables)
|
||||||
|
|
||||||
Defaults.publisher(.hideAllDayEvents, options: [])
|
Defaults.publisher(.hideAllDayEvents, options: [])
|
||||||
.sink { [weak self] _ in
|
.map(\.newValue)
|
||||||
self?.recalculateUpcomingEntries(reason: "hide-all-day")
|
.sink { [weak self] newValue in
|
||||||
|
guard let self else { return }
|
||||||
|
guard newValue != self.lastAppliedHideAllDay else { return }
|
||||||
|
self.scheduleSettingsRecalculation(reason: "hide-all-day") {
|
||||||
|
self.lastAppliedHideAllDay = newValue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.store(in: &cancellables)
|
.store(in: &cancellables)
|
||||||
|
|
||||||
Defaults.publisher(.hideCompletedReminders, options: [])
|
Defaults.publisher(.hideCompletedReminders, options: [])
|
||||||
.sink { [weak self] _ in
|
.map(\.newValue)
|
||||||
self?.recalculateUpcomingEntries(reason: "hide-completed")
|
.sink { [weak self] newValue in
|
||||||
|
guard let self else { return }
|
||||||
|
guard newValue != self.lastAppliedHideCompleted else { return }
|
||||||
|
self.scheduleSettingsRecalculation(reason: "hide-completed") {
|
||||||
|
self.lastAppliedHideCompleted = newValue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.store(in: &cancellables)
|
.store(in: &cancellables)
|
||||||
|
|
||||||
|
|
@ -96,12 +123,40 @@ final class ReminderLiveActivityManager: ObservableObject {
|
||||||
.store(in: &cancellables)
|
.store(in: &cancellables)
|
||||||
|
|
||||||
calendarManager.$events
|
calendarManager.$events
|
||||||
|
.removeDuplicates()
|
||||||
.receive(on: RunLoop.main)
|
.receive(on: RunLoop.main)
|
||||||
.sink { [weak self] events in
|
.sink { [weak self] events in
|
||||||
guard let self else { return }
|
self?.handleCalendarEventsUpdate(events)
|
||||||
self.handleCalendarEventsUpdate(events)
|
|
||||||
}
|
}
|
||||||
.store(in: &cancellables)
|
.store(in: &cancellables)
|
||||||
|
|
||||||
|
LockScreenManager.shared.$isLocked
|
||||||
|
.removeDuplicates()
|
||||||
|
.receive(on: RunLoop.main)
|
||||||
|
.sink { [weak self] locked in
|
||||||
|
self?.handleLockStateChange(isLocked: locked)
|
||||||
|
}
|
||||||
|
.store(in: &cancellables)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func scheduleSettingsRecalculation(reason: String, action: @escaping () -> Void) {
|
||||||
|
pendingSettingsAction = action
|
||||||
|
pendingSettingsReason = reason
|
||||||
|
settingsUpdateTask = Task { [weak self] in
|
||||||
|
guard let self else { return }
|
||||||
|
let delay = UInt64(settingsUpdateDebounceInterval * 1_000_000_000)
|
||||||
|
try? await Task.sleep(nanoseconds: delay)
|
||||||
|
await self.applyPendingSettingsRecalculation()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@MainActor
|
||||||
|
private func applyPendingSettingsRecalculation() {
|
||||||
|
guard let action = pendingSettingsAction, let reason = pendingSettingsReason else { return }
|
||||||
|
pendingSettingsAction = nil
|
||||||
|
pendingSettingsReason = nil
|
||||||
|
action()
|
||||||
|
recalculateUpcomingEntries(reason: reason)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func cancelAllTimers() {
|
private func cancelAllTimers() {
|
||||||
|
|
@ -120,28 +175,56 @@ final class ReminderLiveActivityManager: ObservableObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
private func handleCalendarEventsUpdate(_ events: [EventModel]) {
|
private func handleCalendarEventsUpdate(_ events: [EventModel]) {
|
||||||
latestEvents = events
|
pendingEventsSnapshot = events
|
||||||
|
guard !suppressUpdatesForLock else { return }
|
||||||
|
schedulePendingEventsSnapshotApplication()
|
||||||
|
}
|
||||||
|
|
||||||
|
private func schedulePendingEventsSnapshotApplication() {
|
||||||
|
eventsUpdateDebounceTask = Task { [weak self] in
|
||||||
|
guard let self else { return }
|
||||||
|
let delay = UInt64(eventsDebounceInterval * 1_000_000_000)
|
||||||
|
try? await Task.sleep(nanoseconds: delay)
|
||||||
|
guard !Task.isCancelled else { return }
|
||||||
|
await self.applyPendingEventsSnapshot()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@MainActor
|
||||||
|
private func applyPendingEventsSnapshot() {
|
||||||
|
guard !suppressUpdatesForLock else { return }
|
||||||
|
guard let snapshot = pendingEventsSnapshot else { return }
|
||||||
|
pendingEventsSnapshot = nil
|
||||||
|
guard snapshot != latestEvents else { return }
|
||||||
|
|
||||||
|
latestEvents = snapshot
|
||||||
guard Defaults[.enableReminderLiveActivity] else { return }
|
guard Defaults[.enableReminderLiveActivity] else { return }
|
||||||
logger.debug("[Reminder] Applying calendar snapshot update (events=\(events.count, privacy: .public))")
|
logger.debug("[Reminder] Applying calendar snapshot update (events=\(snapshot.count, privacy: .public))")
|
||||||
recalculateUpcomingEntries(reason: "calendar-events")
|
recalculateUpcomingEntries(reason: "calendar-events")
|
||||||
}
|
}
|
||||||
|
|
||||||
private func shouldHide(_ event: EventModel) -> Bool {
|
private func handleLockStateChange(isLocked: Bool) {
|
||||||
if event.isAllDay && Defaults[.hideAllDayEvents] {
|
suppressUpdatesForLock = isLocked
|
||||||
return true
|
if isLocked {
|
||||||
|
eventsUpdateDebounceTask = nil
|
||||||
|
upcomingComputationTask = nil
|
||||||
|
settingsUpdateTask = nil
|
||||||
|
pendingSettingsAction = nil
|
||||||
|
pendingSettingsReason = nil
|
||||||
|
pauseReminderActivityForLock()
|
||||||
|
} else {
|
||||||
|
if pendingEventsSnapshot != nil {
|
||||||
|
schedulePendingEventsSnapshotApplication()
|
||||||
|
} else {
|
||||||
|
recalculateUpcomingEntries(reason: "lock-resume")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if case let .reminder(completed) = event.type,
|
|
||||||
completed && Defaults[.hideCompletedReminders] {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private func makeEntry(from event: EventModel, leadMinutes: Int, referenceDate: Date) -> ReminderEntry? {
|
private func pauseReminderActivityForLock() {
|
||||||
guard event.start > referenceDate else { return nil }
|
tickerTask = nil
|
||||||
let leadSeconds = max(1, leadMinutes) * 60
|
evaluationTask?.cancel()
|
||||||
let trigger = event.start.addingTimeInterval(TimeInterval(-leadSeconds))
|
evaluationTask = nil
|
||||||
return ReminderEntry(event: event, triggerDate: trigger, leadTime: TimeInterval(leadSeconds))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private func recalculateUpcomingEntries(referenceDate: Date = Date(), reason: String) {
|
private func recalculateUpcomingEntries(referenceDate: Date = Date(), reason: String) {
|
||||||
|
|
@ -149,18 +232,33 @@ final class ReminderLiveActivityManager: ObservableObject {
|
||||||
deactivateReminder()
|
deactivateReminder()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
let snapshot = latestEvents
|
||||||
|
let leadMinutes = Defaults[.reminderLeadTime]
|
||||||
|
let hideAllDay = Defaults[.hideAllDayEvents]
|
||||||
|
let hideCompleted = Defaults[.hideCompletedReminders]
|
||||||
|
|
||||||
guard calendarManager.hasReminderAccess else {
|
upcomingComputationTask = Task.detached(priority: .utility) { [weak self] in
|
||||||
|
guard let self else { return }
|
||||||
|
guard !Task.isCancelled else { return }
|
||||||
|
let upcoming = Self.buildUpcomingEntries(
|
||||||
|
events: snapshot,
|
||||||
|
leadMinutes: leadMinutes,
|
||||||
|
referenceDate: referenceDate,
|
||||||
|
hideAllDayEvents: hideAllDay,
|
||||||
|
hideCompletedReminders: hideCompleted
|
||||||
|
)
|
||||||
|
guard !Task.isCancelled else { return }
|
||||||
|
await self.publishUpcomingEntries(upcoming, referenceDate: referenceDate, reason: reason)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@MainActor
|
||||||
|
private func publishUpcomingEntries(_ upcoming: [ReminderEntry], referenceDate: Date, reason: String) {
|
||||||
|
guard Defaults[.enableReminderLiveActivity] else {
|
||||||
deactivateReminder()
|
deactivateReminder()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let leadMinutes = Defaults[.reminderLeadTime]
|
|
||||||
let upcoming = latestEvents
|
|
||||||
.filter { !shouldHide($0) }
|
|
||||||
.compactMap { makeEntry(from: $0, leadMinutes: leadMinutes, referenceDate: referenceDate) }
|
|
||||||
.sorted { $0.triggerDate < $1.triggerDate }
|
|
||||||
|
|
||||||
upcomingEntries = upcoming
|
upcomingEntries = upcoming
|
||||||
updateActiveWindowReminders(for: referenceDate)
|
updateActiveWindowReminders(for: referenceDate)
|
||||||
|
|
||||||
|
|
@ -174,6 +272,34 @@ final class ReminderLiveActivityManager: ObservableObject {
|
||||||
handleEntrySelection(first, referenceDate: referenceDate)
|
handleEntrySelection(first, referenceDate: referenceDate)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nonisolated private static func buildUpcomingEntries(
|
||||||
|
events: [EventModel],
|
||||||
|
leadMinutes: Int,
|
||||||
|
referenceDate: Date,
|
||||||
|
hideAllDayEvents: Bool,
|
||||||
|
hideCompletedReminders: Bool
|
||||||
|
) -> [ReminderEntry] {
|
||||||
|
guard !Task.isCancelled else { return [] }
|
||||||
|
let leadSeconds = max(1, leadMinutes) * 60
|
||||||
|
var entries: [ReminderEntry] = []
|
||||||
|
entries.reserveCapacity(events.count)
|
||||||
|
for event in events {
|
||||||
|
if Task.isCancelled { return [] }
|
||||||
|
if hideAllDayEvents && event.isAllDay {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if hideCompletedReminders,
|
||||||
|
case let .reminder(completed) = event.type,
|
||||||
|
completed {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
guard event.start > referenceDate else { continue }
|
||||||
|
let trigger = event.start.addingTimeInterval(TimeInterval(-leadSeconds))
|
||||||
|
entries.append(.init(event: event, triggerDate: trigger, leadTime: TimeInterval(leadSeconds)))
|
||||||
|
}
|
||||||
|
return entries.sorted { $0.triggerDate < $1.triggerDate }
|
||||||
|
}
|
||||||
|
|
||||||
private func clearActiveReminderState() {
|
private func clearActiveReminderState() {
|
||||||
nextReminder = nil
|
nextReminder = nil
|
||||||
if activeReminder != nil {
|
if activeReminder != nil {
|
||||||
|
|
|
||||||
|
|
@ -400,6 +400,7 @@ extension Defaults.Keys {
|
||||||
)
|
)
|
||||||
static let nonNotchHeight = Key<CGFloat>("nonNotchHeight", default: 32)
|
static let nonNotchHeight = Key<CGFloat>("nonNotchHeight", default: 32)
|
||||||
static let notchHeight = Key<CGFloat>("notchHeight", default: 32)
|
static let notchHeight = Key<CGFloat>("notchHeight", default: 32)
|
||||||
|
static let openNotchWidth = Key<CGFloat>("openNotchWidth", default: 640)
|
||||||
//static let openLastTabByDefault = Key<Bool>("openLastTabByDefault", default: false)
|
//static let openLastTabByDefault = Key<Bool>("openLastTabByDefault", default: false)
|
||||||
|
|
||||||
// MARK: Appearance
|
// MARK: Appearance
|
||||||
|
|
|
||||||
|
|
@ -147,6 +147,29 @@ class DynamicIslandViewModel: NSObject, ObservableObject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.store(in: &cancellables)
|
.store(in: &cancellables)
|
||||||
|
|
||||||
|
Defaults.publisher(.openNotchWidth, options: [])
|
||||||
|
.map { $0.newValue }
|
||||||
|
.removeDuplicates()
|
||||||
|
.receive(on: RunLoop.main)
|
||||||
|
.sink { [weak self] _ in
|
||||||
|
guard let self else { return }
|
||||||
|
guard self.notchState == .open else { return }
|
||||||
|
guard !Defaults[.enableMinimalisticUI] else { return }
|
||||||
|
let updatedTarget = self.calculateDynamicNotchSize()
|
||||||
|
guard self.notchSize != updatedTarget else { return }
|
||||||
|
withAnimation(.smooth) {
|
||||||
|
self.notchSize = updatedTarget
|
||||||
|
}
|
||||||
|
if let delegate = AppDelegate.shared {
|
||||||
|
delegate.ensureWindowSize(
|
||||||
|
addShadowPadding(to: updatedTarget, isMinimalistic: false),
|
||||||
|
animated: true,
|
||||||
|
force: false
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.store(in: &cancellables)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func handleMinimalisticTimerHeightChange() {
|
private func handleMinimalisticTimerHeightChange() {
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,10 @@ import SwiftUI
|
||||||
let downloadSneakSize: CGSize = .init(width: 65, height: 1)
|
let downloadSneakSize: CGSize = .init(width: 65, height: 1)
|
||||||
let batterySneakSize: CGSize = .init(width: 160, height: 1)
|
let batterySneakSize: CGSize = .init(width: 160, height: 1)
|
||||||
|
|
||||||
let openNotchSize: CGSize = .init(width: 640, height: 190)
|
var openNotchSize: CGSize {
|
||||||
|
let width = Defaults[.openNotchWidth]
|
||||||
|
return .init(width: width, height: 190)
|
||||||
|
}
|
||||||
private let minimalisticBaseOpenNotchSize: CGSize = .init(width: 420, height: 180)
|
private let minimalisticBaseOpenNotchSize: CGSize = .init(width: 420, height: 180)
|
||||||
private let minimalisticLyricsExtraHeight: CGFloat = 40
|
private let minimalisticLyricsExtraHeight: CGFloat = 40
|
||||||
let minimalisticTimerCountdownTopPadding: CGFloat = 12
|
let minimalisticTimerCountdownTopPadding: CGFloat = 12
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,7 @@ Atoll turns the MacBook notch into a focused command surface for media, system i
|
||||||
- Current weather conditions and forecast.
|
- Current weather conditions and forecast.
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<video src=".github/assets/Lockscreen-v1.2.mp4" alt="Lock screen widgets" width="520" autoplay loop muted></video>
|
<img src=".github/assets/lockscreen-v1.2.gif" alt="Do Not Disturb" width="520">
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
## Overview
|
## Overview
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue