Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,8 @@
"notifications" = "Benachrichtigungen";
"notificationsAreHere" = "Sichere Benachrichtigungen sind da";
"notificationsDescription" = "Erhalten Sie Benachrichtigungen, wenn ein anderes Gerät Ihrem Tresor beitreten möchte oder wenn Ihre Signatur erforderlich ist.";
"notificationsDisabledMessage" = "Benachrichtigungen sind für Vultisig deaktiviert. Bitte aktivieren Sie diese in den Einstellungen.";
"notificationsDisabledTitle" = "Benachrichtigungen deaktiviert";
"notificationSentSuccessfully" = "Benachrichtigung wurde erfolgreich gesendet!";
"notNow" = "Nicht jetzt";
"noTokensFound" = "Keine Token gefunden";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,8 @@
"notifications" = "Notifications";
"notificationsAreHere" = "Secure Notifications are here";
"notificationsDescription" = "Receive alerts when another device requests to join your vault or when your signature is required.";
"notificationsDisabledMessage" = "Notifications are disabled for Vultisig. Please enable them in Settings.";
"notificationsDisabledTitle" = "Notifications Disabled";
"notificationSentSuccessfully" = "Notification was successfully sent!";
"notNow" = "Not now";
"noTokensFound" = "No tokens selected";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,8 @@
"notifications" = "Notificaciones";
"notificationsAreHere" = "Las notificaciones seguras están aquí";
"notificationsDescription" = "Recibe alertas cuando otro dispositivo solicite unirse a tu bóveda o cuando se requiera tu firma.";
"notificationsDisabledMessage" = "Las notificaciones están desactivadas para Vultisig. Por favor, actívalas en Ajustes.";
"notificationsDisabledTitle" = "Notificaciones desactivadas";
"notificationSentSuccessfully" = "¡Notificación enviada con éxito!";
"notNow" = "Ahora no";
"noTokensFound" = "No se encontraron tokens";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,8 @@
"notifications" = "Obavijesti";
"notificationsAreHere" = "Sigurne obavijesti su stigle";
"notificationsDescription" = "Primajte obavijesti kada drugi uređaj zatraži pridruživanje vašem trezoru ili kada je potreban vaš potpis.";
"notificationsDisabledMessage" = "Obavijesti su onemogućene za Vultisig. Molimo omogućite ih u Postavkama.";
"notificationsDisabledTitle" = "Obavijesti onemogućene";
"notificationSentSuccessfully" = "Obavijest je uspješno poslana!";
"notNow" = "Ne sada";
"noTokensFound" = "Nema pronađenih tokena";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,8 @@
"notifications" = "Notifiche";
"notificationsAreHere" = "Le notifiche sicure sono arrivate";
"notificationsDescription" = "Ricevi avvisi quando un altro dispositivo richiede di unirsi al tuo vault o quando è richiesta la tua firma.";
"notificationsDisabledMessage" = "Le notifiche sono disabilitate per Vultisig. Abilitale nelle Impostazioni.";
"notificationsDisabledTitle" = "Notifiche disabilitate";
"notificationSentSuccessfully" = "Notifica inviata con successo!";
"notNow" = "Non ora";
"noTokensFound" = "Nessun token trovato";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,8 @@
"notifications" = "Notificações";
"notificationsAreHere" = "As notificações seguras chegaram";
"notificationsDescription" = "Receba alertas quando outro dispositivo solicitar ingresso no seu cofre ou quando sua assinatura for necessária.";
"notificationsDisabledMessage" = "As notificações estão desativadas para o Vultisig. Por favor, ative-as nas Configurações.";
"notificationsDisabledTitle" = "Notificações desativadas";
"notificationSentSuccessfully" = "Notificação enviada com sucesso!";
"notNow" = "Agora não";
"noTokensFound" = "Nenhum token encontrado";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,8 @@
"notifications" = "通知";
"notificationsAreHere" = "安全通知功能已上线";
"notificationsDescription" = "当其他设备请求加入您的保险库或需要您的签名时,接收提醒通知。";
"notificationsDisabledMessage" = "Vultisig 的通知已被禁用。请在设置中启用。";
"notificationsDisabledTitle" = "通知已禁用";
"notificationSentSuccessfully" = "通知已成功发送!";
"notNow" = "暂时不用";
"noTokensFound" = "未选择代币";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ class PushNotificationManager: ObservableObject, PushNotificationManaging {
}
}

func authorizationStatus() async -> UNAuthorizationStatus {
let settings = await UNUserNotificationCenter.current().notificationSettings()
return settings.authorizationStatus
}

func checkPermissionStatus() async {
let settings = await UNUserNotificationCenter.current().notificationSettings()
isPermissionGranted = settings.authorizationStatus == .authorized
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ struct NotificationsSettingsScreen: View {
@Query var vaults: [Vault]
@EnvironmentObject var pushNotificationManager: PushNotificationManager

@Environment(\.scenePhase) private var scenePhase

@State private var notificationsEnabled: Bool = false
@State private var showSettingsAlert: Bool = false

var allVaultsEnabled: Bool {
!vaults.isEmpty && vaults.allSatisfy { pushNotificationManager.isVaultOptedIn($0) }
Expand All @@ -22,12 +25,28 @@ struct NotificationsSettingsScreen: View {
LazyVStack(spacing: 14) {
mainToggleSection
vaultListSection
.transition(.verticalGrowAndFade)
.animation(.interpolatingSpring, value: notificationsEnabled && !vaults.isEmpty)
.showIf(notificationsEnabled && !vaults.isEmpty)
}
}
}
.onAppear {
notificationsEnabled = pushNotificationManager.isPermissionGranted
.onLoad { Task { await checkForPermissions() } }
.onChange(of: scenePhase) { _, newPhase in
if newPhase == .active {
Task { await checkForPermissions() }
}
}
.alert(
"notificationsDisabledTitle".localized,
isPresented: $showSettingsAlert
) {
Button("openSettings".localized) {
openSettings()
}
Button("cancel".localized, role: .cancel) {}
} message: {
Text("notificationsDisabledMessage".localized)
}
}

Expand Down Expand Up @@ -88,21 +107,46 @@ struct NotificationsSettingsScreen: View {
}

func onNotificationsEnabled(_ enabled: Bool) {
notificationsEnabled = enabled
if enabled {
Task {
let status = await pushNotificationManager.authorizationStatus()
if status == .denied {
notificationsEnabled = false
showSettingsAlert = true
return
}

let granted = await pushNotificationManager.requestPermission()
if granted {
notificationsEnabled = true
pushNotificationManager.setAllVaultsOptIn(vaults, enabled: true)
} else {
notificationsEnabled = false
}
}
} else {
notificationsEnabled = enabled
pushNotificationManager.setAllVaultsOptIn(vaults, enabled: false)
pushNotificationManager.unregisterForRemoteNotifications()
}
}

private func openSettings() {
#if os(iOS)
UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!)
#elseif os(macOS)
if let url = URL(string: "x-apple.systempreferences:com.apple.preference.notifications") {
NSWorkspace.shared.open(url)
}
#endif
}

@MainActor
func checkForPermissions() async {
await pushNotificationManager.checkPermissionStatus()
let isEnabled = pushNotificationManager.isPermissionGranted
onNotificationsEnabled(isEnabled)
}
}

#if DEBUG
Expand Down