push notifications working, server functions coming from backend

This commit is contained in:
metacryst
2026-03-26 02:32:59 -05:00
parent 472e69d3c0
commit d107d68bcc
9 changed files with 60 additions and 208 deletions

View File

@@ -1,6 +1,4 @@
import { PushNotifications } from '@capacitor/push-notifications';
import server from './_/code/bridge/server.js'
import Socket from "/_/code/ws/Socket.js"
import "./Home/Home.js"
import "./Home/AuthPage/AuthPage.js"
@@ -160,31 +158,44 @@ let Global = class {
}
async setupPushNotifications() {
const permission = await PushNotifications.requestPermissions();
if (permission.receive === 'granted') {
await PushNotifications.register();
}
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)
localStorage.setItem('deviceToken', token.value)
});
PushNotifications.addListener('registrationError', (error) => {
console.error('Registration error:', error)
console.error('Registration error:', JSON.stringify(error))
});
PushNotifications.addListener('pushNotificationReceived', (notification) => {
console.log('Notification received:', notification)
});
PushNotifications.addListener('pushNotificationActionPerformed', (action) => {
console.log('Notification tapped:', action.notification)
// navigate somewhere based on action.notification.data
});
const permission = await PushNotifications.requestPermissions();
if (permission.receive === 'granted') {
await PushNotifications.register();
console.log('after registter:')
}
}
constructor() {
async init() {
try {
const module = await import(`${util.HOST}/@server/server.js`);
window.server = module.default;
} catch(E) {
console.error(E)
}
this.setupPushNotifications()
window.addEventListener("navigate", this.onNavigate)
@@ -201,6 +212,10 @@ let Global = class {
}
})
}
constructor() {
this.init()
}
}
window.global = new Global()