Skip to content

Commit 1230993

Browse files
committed
Request notification permission when its actually needed so people don't reject accidentally
1 parent 739bb32 commit 1230993

3 files changed

Lines changed: 10 additions & 5 deletions

File tree

src/chat/interface/notify.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
var notify = {};
22

3-
(async function () {
4-
notify.permission = await Notification.requestPermission();
5-
})();
6-
73
var lastNotifcation = null;
84

5+
notify.requestPermission = async function () {
6+
try{
7+
notify.permission = await Notification.requestPermission();
8+
}catch(e){}
9+
};
10+
911
notify.sendIfNotOnScreen = function (tag, message, title = "Random Rants +") {
1012
if (document.visibilityState !== "visible") {
1113
if (lastNotifcation) {

src/chat/interface/sw.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
var elements = require("../../gp2/elements.js");
33
var accountHelper = require("../../accounthelper/index.js");
44
var dialogs = require("../../dialogs.js");
5+
var notify = require("./notify.js");
56
var session = accountHelper.getCurrentValidationState();
67
var ASK_STORAGE_ID = "pushNotificationsDialogNoShow";
78

@@ -32,6 +33,7 @@ var pushPromptCloseButtonNoShow = elements.getGPId("pushPromptCloseButtonNoShow"
3233
subscribing = true;
3334
activatePushButton.textContent = "Now click the *real* allow button!";
3435
try{
36+
await notify.requestPermission();
3537
await accountHelper.pushNotificationHelper.subscribe(true);
3638
activatePushDialog.hidden = true;
3739
dialogs.alert("Registered push notification subscription successfully!");
@@ -56,6 +58,7 @@ var pushPromptCloseButtonNoShow = elements.getGPId("pushPromptCloseButtonNoShow"
5658
}
5759
} else {
5860
localStorage.removeItem(ASK_STORAGE_ID);
61+
await notify.requestPermission();
5962
}
6063

6164
}

wpstatic/version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"timestamp":"1770737002846"}
1+
{"timestamp":"1770737157769"}

0 commit comments

Comments
 (0)