push notifications working
This commit is contained in:
@@ -1,3 +0,0 @@
|
|||||||
class env {
|
|
||||||
BASE_URL = "https://parchment.page"
|
|
||||||
}
|
|
||||||
@@ -4,6 +4,7 @@ import "./Home/Home.js"
|
|||||||
import "./Home/AuthPage/AuthPage.js"
|
import "./Home/AuthPage/AuthPage.js"
|
||||||
import "./Home/ConnectionError.js"
|
import "./Home/ConnectionError.js"
|
||||||
import util from "./util.js"
|
import util from "./util.js"
|
||||||
|
const env = import.meta.env
|
||||||
|
|
||||||
let Global = class {
|
let Global = class {
|
||||||
Socket = new Socket()
|
Socket = new Socket()
|
||||||
@@ -158,13 +159,14 @@ let Global = class {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async setupPushNotifications() {
|
async setupPushNotifications() {
|
||||||
|
if (!Capacitor.isNativePlatform()) return;
|
||||||
PushNotifications.addListener('registration', async (token) => {
|
PushNotifications.addListener('registration', async (token) => {
|
||||||
console.log('Device token:', token.value)
|
console.log('Device token:', token.value)
|
||||||
const stored = localStorage.getItem('deviceToken')
|
const stored = localStorage.getItem('deviceToken')
|
||||||
if (stored === token.value) return;
|
if (stored === token.value) return;
|
||||||
console.log("new push token")
|
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)
|
localStorage.setItem('deviceToken', token.value)
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -184,7 +186,7 @@ let Global = class {
|
|||||||
const permission = await PushNotifications.requestPermissions();
|
const permission = await PushNotifications.requestPermissions();
|
||||||
if (permission.receive === 'granted') {
|
if (permission.receive === 'granted') {
|
||||||
await PushNotifications.register();
|
await PushNotifications.register();
|
||||||
console.log('after registter:')
|
console.log('after register:')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,7 +198,6 @@ let Global = class {
|
|||||||
console.error(E)
|
console.error(E)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setupPushNotifications()
|
|
||||||
window.addEventListener("navigate", this.onNavigate)
|
window.addEventListener("navigate", this.onNavigate)
|
||||||
|
|
||||||
this.getProfile().then(async (status) => {
|
this.getProfile().then(async (status) => {
|
||||||
@@ -207,6 +208,7 @@ let Global = class {
|
|||||||
ConnectionError()
|
ConnectionError()
|
||||||
} else {
|
} else {
|
||||||
await this.Socket.init()
|
await this.Socket.init()
|
||||||
|
await this.setupPushNotifications()
|
||||||
await this.onNavigate()
|
await this.onNavigate()
|
||||||
Home()
|
Home()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user