From 7ef6e5751a403972de855f840a9c118d732f75bd Mon Sep 17 00:00:00 2001 From: mplorentz Date: Fri, 6 Sep 2024 12:04:52 -0400 Subject: [PATCH] Fixed a crash in PushNotificationService.listen --- CHANGELOG.md | 1 + Nos/Service/PushNotificationService.swift | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 849402062..18ac8fd57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Release Notes +- Fixed a crash that could occur while Nos was in the background. - Added nos.lol to the default relay list for new accounts and removed relay.snort.social. - Show quoted notes in note cards. - Added quote-reposting. diff --git a/Nos/Service/PushNotificationService.swift b/Nos/Service/PushNotificationService.swift index a7bfcca49..28ed2aa15 100644 --- a/Nos/Service/PushNotificationService.swift +++ b/Nos/Service/PushNotificationService.swift @@ -51,6 +51,7 @@ import Combine @Dependency(\.persistenceController) private var persistenceController @Dependency(\.router) private var router @Dependency(\.analytics) private var analytics + @Dependency(\.crashReporting) private var crashReporting @Dependency(\.userDefaults) private var userDefaults @Dependency(\.currentUser) private var currentUser @@ -91,8 +92,13 @@ import Combine cacheName: nil ) notificationWatcher?.delegate = self - try? await modelContext.perform { - try self.notificationWatcher?.performFetch() + await modelContext.perform { [weak self] in + do { + try self?.notificationWatcher?.performFetch() + } catch { + Log.error("Error watching notifications:") + self?.crashReporting.report(error) + } } let userMentionsFilter = Filter(