forked from jsnbuchanan/crowd-funder-for-time-pwa
Selected active account and did a little decoding an extraction before building JWT
This commit is contained in:
50
src/App.vue
50
src/App.vue
@@ -431,34 +431,38 @@ export default class App extends Vue {
|
|||||||
return outputArray;
|
return outputArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The subscribeToPush method
|
|
||||||
private subscribeToPush(): Promise<void> {
|
private subscribeToPush(): Promise<void> {
|
||||||
return new Promise<void>((resolve, reject) => {
|
return new Promise<void>((resolve, reject) => {
|
||||||
if ("serviceWorker" in navigator && "PushManager" in window) {
|
if (!("serviceWorker" in navigator && "PushManager" in window)) {
|
||||||
const applicationServerKey = this.urlBase64ToUint8Array(this.b64);
|
|
||||||
const options: PushSubscriptionOptions = {
|
|
||||||
userVisibleOnly: true,
|
|
||||||
applicationServerKey: applicationServerKey,
|
|
||||||
};
|
|
||||||
console.log(options);
|
|
||||||
|
|
||||||
navigator.serviceWorker.ready
|
|
||||||
.then((registration) => {
|
|
||||||
return registration.pushManager.subscribe(options);
|
|
||||||
})
|
|
||||||
.then((subscription) => {
|
|
||||||
console.log("Push subscription successful:", subscription);
|
|
||||||
resolve();
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
console.error("Push subscription failed:", error, options);
|
|
||||||
reject(error);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
const errorMsg = "Push messaging is not supported";
|
const errorMsg = "Push messaging is not supported";
|
||||||
console.warn(errorMsg);
|
console.warn(errorMsg);
|
||||||
reject(new Error(errorMsg));
|
return reject(new Error(errorMsg));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Notification.permission !== "granted") {
|
||||||
|
const errorMsg = "Notification permission not granted";
|
||||||
|
console.warn(errorMsg);
|
||||||
|
return reject(new Error(errorMsg));
|
||||||
|
}
|
||||||
|
|
||||||
|
const applicationServerKey = this.urlBase64ToUint8Array(this.b64);
|
||||||
|
const options: PushSubscriptionOptions = {
|
||||||
|
userVisibleOnly: true,
|
||||||
|
applicationServerKey: applicationServerKey,
|
||||||
|
};
|
||||||
|
|
||||||
|
navigator.serviceWorker.ready
|
||||||
|
.then((registration) => {
|
||||||
|
return registration.pushManager.subscribe(options);
|
||||||
|
})
|
||||||
|
.then((subscription) => {
|
||||||
|
console.log("Push subscription successful:", subscription);
|
||||||
|
resolve();
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error("Push subscription failed:", error, options);
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,11 +5,9 @@ importScripts(
|
|||||||
);
|
);
|
||||||
|
|
||||||
self.addEventListener("install", (event) => {
|
self.addEventListener("install", (event) => {
|
||||||
event.waitUntil(
|
console.log("Install event fired.");
|
||||||
(async () => {
|
importScripts("safari-notifications.js");
|
||||||
importScripts("safari-notifications.js");
|
console.log("scripts imported", event);
|
||||||
})(),
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
self.addEventListener("push", function (event) {
|
self.addEventListener("push", function (event) {
|
||||||
|
|||||||
@@ -87,6 +87,7 @@ async function fetchAllAccounts() {
|
|||||||
async function getNotificationCount() {
|
async function getNotificationCount() {
|
||||||
let secret = null;
|
let secret = null;
|
||||||
let accounts = [];
|
let accounts = [];
|
||||||
|
let result = null;
|
||||||
if ("secret" in self) {
|
if ("secret" in self) {
|
||||||
secret = self.secret;
|
secret = self.secret;
|
||||||
const secretUint8Array = self.decodeBase64(secret);
|
const secretUint8Array = self.decodeBase64(secret);
|
||||||
@@ -94,22 +95,21 @@ async function getNotificationCount() {
|
|||||||
const activeDid = settings["activeDid"];
|
const activeDid = settings["activeDid"];
|
||||||
accounts = await fetchAllAccounts();
|
accounts = await fetchAllAccounts();
|
||||||
let did = null;
|
let did = null;
|
||||||
let result = null;
|
for (var i = 0; i < accounts.length; i++) {
|
||||||
/**
|
let account = accounts[i];
|
||||||
for (var i = 0; i < accounts.length; i++) {
|
let did = account["did"];
|
||||||
let account = accounts[i];
|
if (did == activeDid) {
|
||||||
let did = account['did'];
|
let publicKeyHex = account["publicKeyHex"];
|
||||||
if (did == activeDid) {
|
let identity = account["identity"];
|
||||||
let publicKeyHex = account['publicKeyHex'];
|
result = publicKeyHex;
|
||||||
let identity = account['identity'];
|
const messageWithNonceAsUint8Array = self.decodeBase64(identity);
|
||||||
|
const nonce = messageWithNonceAsUint8Array.slice(0, 24);
|
||||||
const messageWithNonceAsUint8Array = decodeBase64(identity);
|
const message = messageWithNonceAsUint8Array.slice(24, identity.length);
|
||||||
const nonce = messageWithNonceAsUint8Array.slice(0, 24);
|
break;
|
||||||
const message = messageWithNonceAsUint8Array.slice(24, identity.length);
|
}
|
||||||
}
|
}
|
||||||
**/
|
return result;
|
||||||
}
|
}
|
||||||
return accounts.length;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.getNotificationCount = getNotificationCount;
|
self.getNotificationCount = getNotificationCount;
|
||||||
|
|||||||
Reference in New Issue
Block a user