Skip to content

Commit

Permalink
Merge pull request #116 from mendix/release/7.4.0
Browse files Browse the repository at this point in the history
[UIA-15] Add support for web push
  • Loading branch information
ozgeMendix authored Jul 26, 2024
2 parents cf8e116 + 2606a27 commit 37b8b94
Show file tree
Hide file tree
Showing 27 changed files with 118 additions and 3,565 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ apply plugin: 'org.owasp.dependencycheck'
apply plugin: 'com.github.ben-manes.versions'

project.ext {
PNC_VERSION = '7.3.0'
PNC_VERSION = '7.4.0'
MXBUILD_VERSION = '9.24.0.2965'
MODULE_NAME = 'PushNotifications'
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "MxPushNotifications",
"version": "7.3.0",
"version": "7.4.0",
"description": "Phonegap widget for notifications",
"license": "Apache 2.0",
"author": "Mendix Technology B.V.",
Expand Down
Binary file modified test/PushNotfications.mpr
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// This file was generated by Mendix Studio Pro.
//
// WARNING: Only the following code will be retained when actions are regenerated:
// - the import list
// - the code between BEGIN USER CODE and END USER CODE
// - the code between BEGIN EXTRA CODE and END EXTRA CODE
// Other code you write will be lost the next time you deploy the project.
import "mx-global";
import { Big } from "big.js";

// BEGIN EXTRA CODE
async function wait(timeout) {
return new Promise(resolve => setTimeout(resolve, timeout))
}

async function attemptWithRetries(retries, timeout, action) {
for (let trial = 0; trial < retries; trial++) {
try {
return await action();
} catch (err) {
await wait(timeout);
}
}
return await action();
}
// END EXTRA CODE

/**
* @param {string} vapidKey
* @returns {Promise.<string>}
*/
export async function RegisterForPushNotificationsWeb(vapidKey) {
// BEGIN USER CODE
if ("Notification" in window !== true)
throw new Error("Notification API not available.");

if ("firebase" in window !== true)
throw new Error("Firebase API not available.");

if (vapidKey === undefined || vapidKey === "")
throw new Error("VAPID (Voluntary Application Server Identification) key not available.")

// Request permission
const permission = await Notification.requestPermission();
if (permission !== "granted")
throw new Error("Permission to receive push notifications not granted.")

// Get token
const messaging = firebase.messaging();
const token = await attemptWithRetries(3, 1000, async () => await messaging.getToken({ vapidKey }));

console.info("Registered for push notifications with token: " + token);
return token;
// END USER CODE
}

This file was deleted.

Loading

0 comments on commit 37b8b94

Please sign in to comment.