push notifications working

This commit is contained in:
metacryst
2026-03-26 05:56:14 -05:00
parent d107d68bcc
commit 06e2fabe81
2 changed files with 5 additions and 6 deletions

View File

@@ -1,3 +0,0 @@
class env {
BASE_URL = "https://parchment.page"
}

View File

@@ -4,6 +4,7 @@ import "./Home/Home.js"
import "./Home/AuthPage/AuthPage.js"
import "./Home/ConnectionError.js"
import util from "./util.js"
const env = import.meta.env
let Global = class {
Socket = new Socket()
@@ -158,13 +159,14 @@ let Global = class {
}
async setupPushNotifications() {
if (!Capacitor.isNativePlatform()) return;
PushNotifications.addListener('registration', async (token) => {
console.log('Device token:', token.value)
const stored = localStorage.getItem('deviceToken')
if (stored === token.value) return;
console.log("new push token")
await server.updatePushToken(token.value)
await server.updatePushToken(token.value, global.profile.id, env.MODE)
localStorage.setItem('deviceToken', token.value)
});
@@ -184,7 +186,7 @@ let Global = class {
const permission = await PushNotifications.requestPermissions();
if (permission.receive === 'granted') {
await PushNotifications.register();
console.log('after registter:')
console.log('after register:')
}
}
@@ -196,7 +198,6 @@ let Global = class {
console.error(E)
}
this.setupPushNotifications()
window.addEventListener("navigate", this.onNavigate)
this.getProfile().then(async (status) => {
@@ -207,6 +208,7 @@ let Global = class {
ConnectionError()
} else {
await this.Socket.init()
await this.setupPushNotifications()
await this.onNavigate()
Home()
}