forked from trent_larson/crowd-funder-for-time-pwa
enhance service-worker logging, allow for filtered-push test
This commit is contained in:
@@ -21,11 +21,14 @@ tasks:
|
|||||||
https://web.dev/articles/get-installed-related-apps
|
https://web.dev/articles/get-installed-related-apps
|
||||||
- fix maskable icon
|
- fix maskable icon
|
||||||
|
|
||||||
|
- .1 fix ability to record a give on the contacts page without a number of hours
|
||||||
|
|
||||||
- .2 fix the projects on /discover to show the issuer (currently all "Someone Anonymous")
|
- .2 fix the projects on /discover to show the issuer (currently all "Someone Anonymous")
|
||||||
|
|
||||||
- .3 bug - make or edit a project, choose "Include location", and see the map display shows on top of the bottom icons assignee-group:ui
|
- .3 bug - make or edit a project, choose "Include location", and see the map display shows on top of the bottom icons assignee-group:ui
|
||||||
|
|
||||||
- .5 If notifications are not enabled, add message to front page with link/button to enable
|
- .5 If notifications are not enabled, add message to front page with link/button to enable
|
||||||
|
- bug - totals on contact page are not correct
|
||||||
|
|
||||||
- show VC details... somehow:
|
- show VC details... somehow:
|
||||||
- 01 show my VCs - most interesting, or via search
|
- 01 show my VCs - most interesting, or via search
|
||||||
@@ -50,7 +53,9 @@ tasks:
|
|||||||
- 02 watch for the service worker activation before showing the button to turn on notifications
|
- 02 watch for the service worker activation before showing the button to turn on notifications
|
||||||
- 01 server - show all claim details when issued by the issuer
|
- 01 server - show all claim details when issued by the issuer
|
||||||
- bug - got error adding on Firefox user #0 as contact for themselves
|
- bug - got error adding on Firefox user #0 as contact for themselves
|
||||||
- bug - back-and-forth on discovery & project pages led to "You need an identity to load your projects." error on product page when I had an identity
|
- bug (that is hard to reproduce) - back-and-forth on discovery & project pages led to "You need an identity to load your projects." error on product page when I had an identity
|
||||||
|
- bug (that is hard to reproduce) - in Chrome, install app then delete app and try from Chrome browser and see log errors "Uncaught TypeError: self.appendDailyLog is not a function"
|
||||||
|
- bug (that is hard to reproduce) - on the second 'give' recorded on prod it showed me as the agent
|
||||||
- 01 send visibility signal as a VC and store it
|
- 01 send visibility signal as a VC and store it
|
||||||
- 04 remove 'rowid' references (that are sqlite-specific); may involve server
|
- 04 remove 'rowid' references (that are sqlite-specific); may involve server
|
||||||
- 04 look at other examples for better UI friend.tech
|
- 04 look at other examples for better UI friend.tech
|
||||||
@@ -64,7 +69,6 @@ tasks:
|
|||||||
- .5 Display a more appealing confirmation on the map when erasing the marker
|
- .5 Display a more appealing confirmation on the map when erasing the marker
|
||||||
- .5 include the hash of the latest commit on help page next to version (maybe Trent's git-hash branch)
|
- .5 include the hash of the latest commit on help page next to version (maybe Trent's git-hash branch)
|
||||||
- .5 remove references to localStorage for projectId (now that it's pulling from the path)
|
- .5 remove references to localStorage for projectId (now that it's pulling from the path)
|
||||||
- bug (that is hard to reproduce) - on the second 'give' recorded on prod it showed me as the agent
|
|
||||||
- switch some checks for activeDid to check for isRegistered
|
- switch some checks for activeDid to check for isRegistered
|
||||||
- .2 in SeedBackupView, don't load the mnemonic and keep it in memory; only load it when they click "show"
|
- .2 in SeedBackupView, don't load the mnemonic and keep it in memory; only load it when they click "show"
|
||||||
- .5 fix cert generation on server (since it didn't happen automatically for Nov 30)
|
- .5 fix cert generation on server (since it didn't happen automatically for Nov 30)
|
||||||
|
|||||||
@@ -534,7 +534,7 @@ export default class App extends Vue {
|
|||||||
private sendSubscriptionToServer(
|
private sendSubscriptionToServer(
|
||||||
subscription: PushSubscription,
|
subscription: PushSubscription,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
console.log("About to send subscription", subscription);
|
console.log("About to send subscription...", subscription);
|
||||||
return fetch("/web-push/subscribe", {
|
return fetch("/web-push/subscribe", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
|
|||||||
@@ -134,7 +134,7 @@
|
|||||||
latest setting.
|
latest setting.
|
||||||
</div>
|
</div>
|
||||||
<router-link class="px-4 text-sm text-blue-500" to="/help-notifications">
|
<router-link class="px-4 text-sm text-blue-500" to="/help-notifications">
|
||||||
Troubleshoot notifications here.
|
Test your notification setup.
|
||||||
</router-link>
|
</router-link>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -297,7 +297,7 @@
|
|||||||
:to="{ name: 'statistics' }"
|
:to="{ name: 'statistics' }"
|
||||||
class="block w-full text-center text-md uppercase bg-slate-500 text-white px-1.5 py-2 rounded-md mb-2"
|
class="block w-full text-center text-md uppercase bg-slate-500 text-white px-1.5 py-2 rounded-md mb-2"
|
||||||
>
|
>
|
||||||
See Global Animated History of Giving
|
See Animated Global History of Giving
|
||||||
</router-link>
|
</router-link>
|
||||||
|
|
||||||
<!-- id used by puppeteer test script -->
|
<!-- id used by puppeteer test script -->
|
||||||
|
|||||||
@@ -29,10 +29,11 @@
|
|||||||
<p>
|
<p>
|
||||||
If this works then you're all set.
|
If this works then you're all set.
|
||||||
<button
|
<button
|
||||||
@click="sendTestWebPushMessage()"
|
@click="sendTestWebPushMessage(true)"
|
||||||
class="block w-full text-center text-md uppercase bg-slate-500 text-white px-1.5 py-2 rounded-md mb-2"
|
class="block w-full text-center text-md bg-slate-500 text-white px-1.5 py-2 rounded-md mb-2"
|
||||||
>
|
>
|
||||||
Send Yourself a Test Web Push Message
|
Send Yourself a Test Web Push Message (Through Push Server but
|
||||||
|
Skipping Client Filter)
|
||||||
</button>
|
</button>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
@@ -40,10 +41,10 @@
|
|||||||
<h2 class="text-xl font-semibold">If this app is not installed...</h2>
|
<h2 class="text-xl font-semibold">If this app is not installed...</h2>
|
||||||
<div>
|
<div>
|
||||||
<p>
|
<p>
|
||||||
For best results, install this app on your device. In Chrome, it may
|
For best results on mobile, install this app on your device (as
|
||||||
prompt you, and you can also look for the "Install" command in the
|
opposed to using it inside the broser app). In Chrome, it may prompt
|
||||||
browser settings (as opposed to using it inside the broser app); on
|
you, and you can also look for the "Install" command in the browser
|
||||||
the deskop, look for this icon in the address bar:
|
settings; on the the deskop, look for this icon in the address bar:
|
||||||
<img
|
<img
|
||||||
src="../assets/help/chrome-install-pwa.png"
|
src="../assets/help/chrome-install-pwa.png"
|
||||||
alt="Chrome 'install' icon"
|
alt="Chrome 'install' icon"
|
||||||
@@ -192,23 +193,32 @@
|
|||||||
|
|
||||||
<button
|
<button
|
||||||
@click="showTestNotification()"
|
@click="showTestNotification()"
|
||||||
class="block w-full text-center text-md uppercase bg-slate-500 text-white px-1.5 py-2 rounded-md mb-2"
|
class="block w-full text-center text-md bg-slate-500 text-white px-1.5 py-2 rounded-md mb-2"
|
||||||
>
|
>
|
||||||
Send Test Notification Directly to Device
|
Send Test Notification Directly to Device (Not Through Push Server)
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
@click="alertWebPushSubscription()"
|
@click="alertWebPushSubscription()"
|
||||||
class="block w-full text-center text-md uppercase bg-slate-500 text-white px-1.5 py-2 rounded-md mb-2"
|
class="block w-full text-center text-md bg-slate-500 text-white px-1.5 py-2 rounded-md mb-2"
|
||||||
>
|
>
|
||||||
Show Web Push Subscription Info
|
Show Web Push Subscription Info
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
@click="sendTestWebPushMessage()"
|
@click="sendTestWebPushMessage(true)"
|
||||||
class="block w-full text-center text-md uppercase bg-slate-500 text-white px-1.5 py-2 rounded-md mb-2"
|
class="block w-full text-center text-md bg-slate-500 text-white px-1.5 py-2 rounded-md mb-2"
|
||||||
>
|
>
|
||||||
Send Yourself a Test Web Push Message
|
Send Yourself a Test Web Push Message (Through Push Server but Skipping
|
||||||
|
Client Filter)
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button
|
||||||
|
@click="sendTestWebPushMessage()"
|
||||||
|
class="block w-full text-center text-md bg-slate-500 text-white px-1.5 py-2 rounded-md mb-2"
|
||||||
|
>
|
||||||
|
Send Yourself a Test Web Push Message (Through Push Server and Client
|
||||||
|
Filter)
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
@@ -255,7 +265,7 @@ export default class HelpNotificationsView extends Vue {
|
|||||||
alert(JSON.stringify(this.subscription));
|
alert(JSON.stringify(this.subscription));
|
||||||
}
|
}
|
||||||
|
|
||||||
async sendTestWebPushMessage() {
|
async sendTestWebPushMessage(skipFilter: boolean = false) {
|
||||||
if (!this.subscription) {
|
if (!this.subscription) {
|
||||||
this.$notify(
|
this.$notify(
|
||||||
{
|
{
|
||||||
@@ -277,6 +287,7 @@ export default class HelpNotificationsView extends Vue {
|
|||||||
pushUrl = settings.webPushServer;
|
pushUrl = settings.webPushServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is a special value that tells the service worker to send a direct notification to the device, skipping filters.
|
||||||
// This is shared with the service worker and should be a constant. Look for the same name in additional-scripts.js
|
// This is shared with the service worker and should be a constant. Look for the same name in additional-scripts.js
|
||||||
// Use something other than "Daily Update" https://gitea.anomalistdesign.com/trent_larson/py-push-server/src/commit/3c0e196c11bc98060ec5934e99e7dbd591b5da4d/app.py#L213
|
// Use something other than "Daily Update" https://gitea.anomalistdesign.com/trent_larson/py-push-server/src/commit/3c0e196c11bc98060ec5934e99e7dbd591b5da4d/app.py#L213
|
||||||
const DIRECT_PUSH_TITLE = "DIRECT_NOTIFICATION";
|
const DIRECT_PUSH_TITLE = "DIRECT_NOTIFICATION";
|
||||||
@@ -299,8 +310,10 @@ export default class HelpNotificationsView extends Vue {
|
|||||||
auth: authB64,
|
auth: authB64,
|
||||||
p256dh: p256dhB64,
|
p256dh: p256dhB64,
|
||||||
},
|
},
|
||||||
message: "This is a test message, triggered by you.",
|
message: `Test, where you will see this message ${
|
||||||
title: DIRECT_PUSH_TITLE,
|
skipFilter ? "un" : ""
|
||||||
|
}filtered.`,
|
||||||
|
title: skipFilter ? DIRECT_PUSH_TITLE : "Your Web Push",
|
||||||
};
|
};
|
||||||
console.log("Sending a test web push message:", newPayload);
|
console.log("Sending a test web push message:", newPayload);
|
||||||
const payloadStr = JSON.stringify(newPayload);
|
const payloadStr = JSON.stringify(newPayload);
|
||||||
@@ -321,7 +334,7 @@ export default class HelpNotificationsView extends Vue {
|
|||||||
group: "alert",
|
group: "alert",
|
||||||
type: "success",
|
type: "success",
|
||||||
title: "Test Web Push Sent",
|
title: "Test Web Push Sent",
|
||||||
text: "Check your device for the test web push message.",
|
text: "Check your device for the test web push message, depending on the filtering you chose.",
|
||||||
},
|
},
|
||||||
-1,
|
-1,
|
||||||
);
|
);
|
||||||
@@ -340,9 +353,10 @@ export default class HelpNotificationsView extends Vue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
showTestNotification() {
|
showTestNotification() {
|
||||||
|
const TEST_NOTIFICATION_TITLE = "It Worked";
|
||||||
navigator.serviceWorker.ready
|
navigator.serviceWorker.ready
|
||||||
.then((registration) => {
|
.then((registration) => {
|
||||||
return registration.showNotification("It Worked", {
|
return registration.showNotification(TEST_NOTIFICATION_TITLE, {
|
||||||
body: "This is your test notification.",
|
body: "This is your test notification.",
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
@@ -352,7 +366,7 @@ export default class HelpNotificationsView extends Vue {
|
|||||||
group: "alert",
|
group: "alert",
|
||||||
type: "success",
|
type: "success",
|
||||||
title: "Sent",
|
title: "Sent",
|
||||||
text: "A notification was triggered, so one should show on your device soon.",
|
text: `A notification was triggered, so one should show on your device entitled '${TEST_NOTIFICATION_TITLE}'.`,
|
||||||
},
|
},
|
||||||
5000,
|
5000,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -4,28 +4,43 @@ importScripts(
|
|||||||
"https://storage.googleapis.com/workbox-cdn/releases/6.4.1/workbox-sw.js",
|
"https://storage.googleapis.com/workbox-cdn/releases/6.4.1/workbox-sw.js",
|
||||||
);
|
);
|
||||||
|
|
||||||
self.addEventListener("install", (event) => {
|
function logConsoleAndDb(message, arg1, arg2) {
|
||||||
console.log("Service worker got install. Importing scripts...", event);
|
// in chrome://serviceworker-internals note that the arg1 and arg2 here will show as "[object Object]" in that page but will show as expandable objects in the console
|
||||||
importScripts(
|
console.log(`${new Date().toISOString()} ${message}`, arg1, arg2);
|
||||||
|
if (self.appendDailyLog) {
|
||||||
|
let fullMessage = `${new Date().toISOString()} ${message}`;
|
||||||
|
if (arg1) {
|
||||||
|
fullMessage += `\n${JSON.stringify(arg1)}`;
|
||||||
|
}
|
||||||
|
if (arg2) {
|
||||||
|
fullMessage += `\n${JSON.stringify(arg2)}`;
|
||||||
|
}
|
||||||
|
self.appendDailyLog(fullMessage);
|
||||||
|
} else {
|
||||||
|
// sometimes we get the error: "Uncaught TypeError: self.appendDailyLog is not a function"
|
||||||
|
console.log("Not logging to DB because self.appendDailyLog doesn't exist.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self.addEventListener("install", async (event) => {
|
||||||
|
console.log("Service worker got install event. Importing scripts...", event);
|
||||||
|
await importScripts(
|
||||||
"safari-notifications.js",
|
"safari-notifications.js",
|
||||||
"nacl.js",
|
"nacl.js",
|
||||||
"noble-curves.js",
|
"noble-curves.js",
|
||||||
"noble-hashes.js",
|
"noble-hashes.js",
|
||||||
);
|
);
|
||||||
console.log("Service worker imported scripts.");
|
// this should now be available
|
||||||
|
logConsoleAndDb("Service worker imported all scripts.");
|
||||||
});
|
});
|
||||||
|
|
||||||
function logConsoleAndDb(message, arg1, arg2) {
|
self.addEventListener("activate", (event) => {
|
||||||
console.log(`${new Date().toISOString()} ${message}`, arg1, arg2);
|
logConsoleAndDb("Service worker is activating...", event);
|
||||||
let fullMessage = `${new Date().toISOString()} ${message}`;
|
// see https://developer.mozilla.org/en-US/docs/Web/API/Clients/claim
|
||||||
if (arg1) {
|
// and https://web.dev/articles/service-worker-lifecycle#clientsclaim
|
||||||
fullMessage += `\n${JSON.stringify(arg1)}`;
|
event.waitUntil(clients.claim());
|
||||||
}
|
logConsoleAndDb("Service worker is activated.");
|
||||||
if (arg2) {
|
});
|
||||||
fullMessage += `\n${JSON.stringify(arg2)}`;
|
|
||||||
}
|
|
||||||
self.appendDailyLog(fullMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
self.addEventListener("push", function (event) {
|
self.addEventListener("push", function (event) {
|
||||||
let text = null;
|
let text = null;
|
||||||
@@ -45,18 +60,27 @@ self.addEventListener("push", function (event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is a special value that tells the service worker that it's a daily update.
|
||||||
|
const DAILY_UPDATE_TITLE = "DAILY_UPDATE";
|
||||||
|
|
||||||
|
// This is a special value that tells the service worker to send a direct notification to the device, skipping filters.
|
||||||
// This is shared with the notification-test code and should be a constant. Look for the same name in HelpNotificationsView.vue
|
// This is shared with the notification-test code and should be a constant. Look for the same name in HelpNotificationsView.vue
|
||||||
// Use something other than "Daily Update" https://gitea.anomalistdesign.com/trent_larson/py-push-server/src/commit/3c0e196c11bc98060ec5934e99e7dbd591b5da4d/app.py#L213
|
// Use something other than "Daily Update" https://gitea.anomalistdesign.com/trent_larson/py-push-server/src/commit/3c0e196c11bc98060ec5934e99e7dbd591b5da4d/app.py#L213
|
||||||
const DIRECT_PUSH_TITLE = "DIRECT_NOTIFICATION";
|
const DIRECT_PUSH_TITLE = "DIRECT_NOTIFICATION";
|
||||||
|
|
||||||
let title = "Generic Notification";
|
let title;
|
||||||
let message = "Got some empty message.";
|
let message = "Got some empty message.";
|
||||||
if (payload && payload.title == DIRECT_PUSH_TITLE) {
|
if (payload && payload.title == DIRECT_PUSH_TITLE) {
|
||||||
// skip any search logic and show the message directly
|
// skip any search logic and show the message directly
|
||||||
title = "Direct Message";
|
title = "Direct Notification";
|
||||||
message = payload.message || "No details were provided.";
|
message = payload.message || "No details were provided.";
|
||||||
} else {
|
} else {
|
||||||
title = payload && payload.title ? payload.title : "Note";
|
// any other title will run through regular filtering logic
|
||||||
|
if (payload && payload.title === DAILY_UPDATE_TITLE) {
|
||||||
|
title = "Daily Update";
|
||||||
|
} else {
|
||||||
|
title = payload.title || "Update";
|
||||||
|
}
|
||||||
message = await self.getNotificationCount();
|
message = await self.getNotificationCount();
|
||||||
}
|
}
|
||||||
if (message) {
|
if (message) {
|
||||||
@@ -86,14 +110,6 @@ self.addEventListener("message", (event) => {
|
|||||||
logConsoleAndDb("Service worker posted a message.");
|
logConsoleAndDb("Service worker posted a message.");
|
||||||
});
|
});
|
||||||
|
|
||||||
self.addEventListener("activate", (event) => {
|
|
||||||
logConsoleAndDb("Service worker activating...", event);
|
|
||||||
// see https://developer.mozilla.org/en-US/docs/Web/API/Clients/claim
|
|
||||||
// and https://web.dev/articles/service-worker-lifecycle#clientsclaim
|
|
||||||
event.waitUntil(clients.claim());
|
|
||||||
logConsoleAndDb("Service worker is activated.");
|
|
||||||
});
|
|
||||||
|
|
||||||
self.addEventListener("fetch", (event) => {
|
self.addEventListener("fetch", (event) => {
|
||||||
logConsoleAndDb("Service worker got fetch event.", event);
|
logConsoleAndDb("Service worker got fetch event.", event);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -565,5 +565,6 @@ async function getNotificationCount() {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.appendDailyLog = appendDailyLog;
|
||||||
self.getNotificationCount = getNotificationCount;
|
self.getNotificationCount = getNotificationCount;
|
||||||
self.decodeBase64 = decodeBase64;
|
self.decodeBase64 = decodeBase64;
|
||||||
|
|||||||
Reference in New Issue
Block a user