mirror of
https://github.com/neon443/NearFuture.git
synced 2026-03-11 14:56:15 +00:00
changes to pending notif checker
add migration, if events dont have notifs fix runtime error about bg threads by using await MainActor.run add cancelallnotifs bump version
This commit is contained in:
@@ -12,6 +12,6 @@ TEAM_ID = 8JGND254B7
|
|||||||
BUNDLE_ID = com.neon443.NearFuture
|
BUNDLE_ID = com.neon443.NearFuture
|
||||||
BUNDLE_ID_WIDGETS = com.neon443.NearFuture.widgets
|
BUNDLE_ID_WIDGETS = com.neon443.NearFuture.widgets
|
||||||
GROUP_ID = group.NearFuture
|
GROUP_ID = group.NearFuture
|
||||||
VERSION = 3.3.1
|
VERSION = 4.0.0
|
||||||
NAME = Near Future
|
NAME = Near Future
|
||||||
BUILD_NUMBER = 0
|
BUILD_NUMBER = 0
|
||||||
|
|||||||
@@ -129,13 +129,10 @@ class SettingsViewModel: ObservableObject {
|
|||||||
init(load: Bool = true) {
|
init(load: Bool = true) {
|
||||||
if load {
|
if load {
|
||||||
loadSettings()
|
loadSettings()
|
||||||
UNUserNotificationCenter.current().getNotificationSettings { settings in
|
|
||||||
if settings.authorizationStatus == .authorized {
|
|
||||||
self.notifsGranted = true
|
|
||||||
} else {
|
|
||||||
Task {
|
Task {
|
||||||
self.notifsGranted = await requestNotifs()
|
let requestResult = await requestNotifs()
|
||||||
}
|
await MainActor.run {
|
||||||
|
self.notifsGranted = requestResult
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -237,30 +234,35 @@ class EventViewModel: ObservableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func checkPendingNotifs(_ pending: [UNNotificationRequest]) {
|
func checkPendingNotifs(_ pending: [UNNotificationRequest]) {
|
||||||
|
var eventUUIDs = events.map({$0.id.uuidString})
|
||||||
for req in pending {
|
for req in pending {
|
||||||
checkNotif(notif: req)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func checkNotif(notif: UNNotificationRequest) {
|
|
||||||
//match the notif to an event
|
//match the notif to an event
|
||||||
if let index = events.firstIndex(where: {$0.id.uuidString == notif.identifier}) {
|
if let index = events.firstIndex(where: {$0.id.uuidString == req.identifier}) {
|
||||||
|
if let remove = eventUUIDs.firstIndex(where: {$0 == req.identifier}) {
|
||||||
|
eventUUIDs.remove(at: remove)
|
||||||
|
}
|
||||||
let components = getDateComponents(events[index].date)
|
let components = getDateComponents(events[index].date)
|
||||||
//check the notif matches event details
|
//check the notif matches event details
|
||||||
if notif.content.title == events[index].name,
|
if req.content.title == events[index].name,
|
||||||
notif.content.subtitle == events[index].notes,
|
req.content.subtitle == events[index].notes,
|
||||||
notif.trigger == UNCalendarNotificationTrigger(dateMatching: components, repeats: false) {
|
req.trigger == UNCalendarNotificationTrigger(dateMatching: components, repeats: false) {
|
||||||
//if it does, make sure the notif delets if u complete the veent
|
//if it does, make sure the notif delets if u complete the veent
|
||||||
if events[index].complete {
|
if events[index].complete {
|
||||||
cancelNotif(notif.identifier)
|
cancelNotif(req.identifier)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
cancelNotif(notif.identifier)
|
cancelNotif(req.identifier)
|
||||||
scheduleEventNotif(events[index])
|
scheduleEventNotif(events[index])
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//cancel if the event is deleted
|
//cancel if the event is deleted
|
||||||
cancelNotif(notif.identifier)
|
cancelNotif(req.identifier)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for uuid in eventUUIDs {
|
||||||
|
if let event = events.first(where: {$0.id.uuidString == uuid}) {
|
||||||
|
scheduleEventNotif(event)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -275,10 +277,10 @@ class EventViewModel: ObservableObject {
|
|||||||
icloudStore.synchronize()
|
icloudStore.synchronize()
|
||||||
|
|
||||||
updateSyncStatus()
|
updateSyncStatus()
|
||||||
|
loadEvents()
|
||||||
Task {
|
Task {
|
||||||
await checkPendingNotifs(getNotifs())
|
await checkPendingNotifs(getNotifs())
|
||||||
}
|
}
|
||||||
loadEvents()
|
|
||||||
WidgetCenter.shared.reloadAllTimelines()//reload all widgets when saving events
|
WidgetCenter.shared.reloadAllTimelines()//reload all widgets when saving events
|
||||||
objectWillChange.send()
|
objectWillChange.send()
|
||||||
}
|
}
|
||||||
@@ -372,6 +374,7 @@ class EventViewModel: ObservableObject {
|
|||||||
UserDefaults.standard.removeObject(forKey: "events")
|
UserDefaults.standard.removeObject(forKey: "events")
|
||||||
appGroupUserDefaults.removeObject(forKey: "events")
|
appGroupUserDefaults.removeObject(forKey: "events")
|
||||||
events.removeAll()
|
events.removeAll()
|
||||||
|
cancelAllNotifs()
|
||||||
updateSyncStatus()
|
updateSyncStatus()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -379,6 +382,7 @@ class EventViewModel: ObservableObject {
|
|||||||
icloudStore.removeObject(forKey: "events")
|
icloudStore.removeObject(forKey: "events")
|
||||||
icloudStore.synchronize()
|
icloudStore.synchronize()
|
||||||
icloudData.removeAll()
|
icloudData.removeAll()
|
||||||
|
cancelAllNotifs()
|
||||||
updateSyncStatus()
|
updateSyncStatus()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -394,6 +398,7 @@ class EventViewModel: ObservableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
events.removeAll()
|
events.removeAll()
|
||||||
|
cancelAllNotifs()
|
||||||
updateSyncStatus()
|
updateSyncStatus()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -404,6 +409,7 @@ class EventViewModel: ObservableObject {
|
|||||||
}
|
}
|
||||||
icloudStore.synchronize()
|
icloudStore.synchronize()
|
||||||
icloudData.removeAll()
|
icloudData.removeAll()
|
||||||
|
cancelAllNotifs()
|
||||||
updateSyncStatus()
|
updateSyncStatus()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -506,3 +512,7 @@ func getDateComponents(_ date: Date) -> DateComponents {
|
|||||||
func cancelNotif(_ id: String) {
|
func cancelNotif(_ id: String) {
|
||||||
UNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers: [id])
|
UNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers: [id])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func cancelAllNotifs() {
|
||||||
|
UNUserNotificationCenter.current().removeAllPendingNotificationRequests()
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user