forked from coracle/flotilla
Clean up and fix push notifications implementation
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<script lang="ts">
|
||||
import "@src/app.css"
|
||||
import "@capacitor-community/safe-area"
|
||||
import {PushNotifications} from "@capacitor/push-notifications"
|
||||
import * as nip19 from "nostr-tools/nip19"
|
||||
import type {Unsubscriber} from "svelte/store"
|
||||
import {get} from "svelte/store"
|
||||
@@ -43,6 +44,17 @@
|
||||
|
||||
const policies = [authPolicy, blockPolicy, trustPolicy, mostlyRestrictedPolicy]
|
||||
|
||||
PushNotifications.addListener(
|
||||
"pushNotificationActionPerformed",
|
||||
async (action: ActionPerformed) => {
|
||||
console.log('====== action', JSON.stringify(action))
|
||||
const event = parseJson(action.notification.data.event)
|
||||
const relays = [action.notification.data.relay]
|
||||
|
||||
goto(await getEventPath(event, relays))
|
||||
},
|
||||
)
|
||||
|
||||
// Add stuff to window for convenience
|
||||
Object.assign(window, {
|
||||
get,
|
||||
@@ -129,7 +141,7 @@
|
||||
unsubscribers.push(syncKeyboard())
|
||||
|
||||
// Initialize background notifications
|
||||
unsubscribers.push(notifications.Push.resume())
|
||||
unsubscribers.push(notifications.Push.start())
|
||||
|
||||
// Listen for signer errors, report to user via toast
|
||||
unsubscribers.push(
|
||||
|
||||
@@ -48,6 +48,12 @@
|
||||
const onsubmit = preventDefault(async () => {
|
||||
await publishSettings($state.snapshot(settings))
|
||||
|
||||
if (settings.alerts_push) {
|
||||
await Alerts.start()
|
||||
} else {
|
||||
await Alerts.cancel()
|
||||
}
|
||||
|
||||
pushToast({message: "Your settings have been saved!"})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user