From 45d65b198847855d24ef0c304cec56ba7f4604a7 Mon Sep 17 00:00:00 2001 From: seamlink-aalves <49952868+seamlink-aalves@users.noreply.github.com> Date: Sun, 1 Oct 2023 02:35:46 +0100 Subject: [PATCH] fix(windows)!: remove deprecated platform (#245) Co-authored-by: Alexandre Alves --- .eslintrc.yml | 4 -- bower.json | 1 - docs/API.md | 16 +++-- docs/EXAMPLES.md | 3 +- docs/PAYLOAD.md | 54 +---------------- docs/PLATFORM_SUPPORT.md | 1 - docs/TYPESCRIPT.md | 3 +- hooks/windows/setToastCapable.js | 18 ------ package.json | 2 - plugin.xml | 13 +--- spec/index.spec.js | 2 +- src/windows/PushPluginProxy.js | 101 ------------------------------- types/index.d.ts | 8 --- 13 files changed, 13 insertions(+), 213 deletions(-) delete mode 100644 hooks/windows/setToastCapable.js delete mode 100644 src/windows/PushPluginProxy.js diff --git a/.eslintrc.yml b/.eslintrc.yml index f0cfe4762..b756b8323 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -12,7 +12,3 @@ overrides: extends: '@cordova/eslint-config/node-tests' rules: indent: ["error", 2] - - - files: [src/windows/**/*.js] - globals: - Windows: true diff --git a/bower.json b/bower.json index 2fad4178c..af6608d2f 100644 --- a/bower.json +++ b/bower.json @@ -11,7 +11,6 @@ "ecosystem:phonegap", "cordova-ios", "cordova-android", - "cordova-windows", "cordova-browser" ], "homepage": "https://github.com/phonegap/phonegap-plugin-push", diff --git a/docs/API.md b/docs/API.md index e56e89cac..17cd98334 100644 --- a/docs/API.md +++ b/docs/API.md @@ -53,10 +53,10 @@ - [push.unsubscribe(topic, successHandler, errorHandler)](#pushunsubscribetopic-successhandler-errorhandler) - [Parameters](#parameters-9) - [Example](#example-11) - - [push.setApplicationIconBadgeNumber(successHandler, errorHandler, count) - iOS & Android only](#pushsetapplicationiconbadgenumbersuccesshandler-errorhandler-count---ios--android-only) + - [push.setApplicationIconBadgeNumber(successHandler, errorHandler, count) - iOS \& Android only](#pushsetapplicationiconbadgenumbersuccesshandler-errorhandler-count---ios--android-only) - [Parameters](#parameters-10) - [Example](#example-12) - - [push.getApplicationIconBadgeNumber(successHandler, errorHandler) - iOS & Android only](#pushgetapplicationiconbadgenumbersuccesshandler-errorhandler---ios--android-only) + - [push.getApplicationIconBadgeNumber(successHandler, errorHandler) - iOS \& Android only](#pushgetapplicationiconbadgenumbersuccesshandler-errorhandler---ios--android-only) - [Parameters](#parameters-11) - [Callback parameters](#callback-parameters-5) - [`successHandler`](#successhandler-2) @@ -64,10 +64,10 @@ - [push.finish(successHandler, errorHandler, id) - iOS only](#pushfinishsuccesshandler-errorhandler-id---ios-only) - [Parameters](#parameters-12) - [Example](#example-14) - - [push.clearAllNotifications(successHandler, errorHandler) - iOS & Android only](#pushclearallnotificationssuccesshandler-errorhandler---ios--android-only) + - [push.clearAllNotifications(successHandler, errorHandler) - iOS \& Android only](#pushclearallnotificationssuccesshandler-errorhandler---ios--android-only) - [Parameters](#parameters-13) - [Example](#example-15) - - [push.clearNotification(id, successHandler, errorHandler) - iOS & Android only](#pushclearnotificationid-successhandler-errorhandler---ios--android-only) + - [push.clearNotification(id, successHandler, errorHandler) - iOS \& Android only](#pushclearnotificationid-successhandler-errorhandler---ios--android-only) - [Parameters](#parameters-14) - [Example](#example-16) @@ -89,7 +89,7 @@ Initializes the plugin on the native side. | --------- | -------- | ------- | ------------------------------------------------------------------------ | | `options` | `Object` | `{}` | An object describing relevant specific options for all target platforms. | -All available option attributes are described bellow. Currently, there are no Windows specific options. +All available option attributes are described bellow. #### Android @@ -199,8 +199,7 @@ const push = PushNotification.init({ alert: 'true', badge: true, sound: 'false' - }, - windows: {} + } }); ``` @@ -388,10 +387,9 @@ The event `notification` will be triggered each time a push notification is rece | -------------------------------- | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `data.message` | `string` | The text of the push message sent from the 3rd party service. | | `data.title` | `string` | The optional title of the push message sent from the 3rd party service. | -| `data.count` | `string` | The number of messages to be displayed in the badge in iOS/Android or message count in the notification shade in Android. For windows, it represents the value in the badge notification which could be a number or a status glyph. | +| `data.count` | `string` | The number of messages to be displayed in the badge in iOS/Android or message count in the notification shade in Android. | | `data.sound` | `string` | The name of the sound file to be played upon receipt of the notification. | | `data.image` | `string` | The path of the image file to be displayed in the notification. | -| `data.launchArgs` | `string` | The args to be passed to the application on launch from push notification. This works when notification is received in background. (Windows Only) | | `data.additionalData` | `Object` | An optional collection of data sent by the 3rd party push service that does not fit in the above properties. | | `data.additionalData.foreground` | `boolean` | Whether the notification was received while the app was in the foreground | | `data.additionalData.coldstart` | `boolean` | Will be `true` if the application is started by clicking on the push notification, `false` if the app is already started. | diff --git a/docs/EXAMPLES.md b/docs/EXAMPLES.md index 54d311590..77e9af7aa 100644 --- a/docs/EXAMPLES.md +++ b/docs/EXAMPLES.md @@ -19,8 +19,7 @@ const push = PushNotification.init({ alert: "true", badge: "true", sound: "true" - }, - windows: {} + } }); push.on('registration', (data) => { diff --git a/docs/PAYLOAD.md b/docs/PAYLOAD.md index a0417a36b..6ef194de7 100644 --- a/docs/PAYLOAD.md +++ b/docs/PAYLOAD.md @@ -45,11 +45,6 @@ - [FCM and Additional Data](#fcm-and-additional-data) - [FCM Messages Not Arriving](#fcm-messages-not-arriving) - [FCM Payload Details](#fcm-payload-details) -- [Windows Behaviour](#windows-behaviour) - - [Notifications](#notifications) - - [Setting Toast Capable Option for Windows](#setting-toast-capable-option-for-windows) - - [Disabling the default processing of notifications by Windows](#disabling-the-default-processing-of-notifications-by-windows) - - [Background Notifications](#background-notifications-2) # Overview @@ -412,8 +407,7 @@ const push = PushNotification.init({ alert: 'true', badge: 'true', sound: 'true' - }, - windows: {} + } }); ``` @@ -453,8 +447,7 @@ const push = PushNotification.init({ alert: 'true', badge: 'true', sound: 'true' - }, - windows: {} + } }); ``` @@ -2198,46 +2191,3 @@ More information on how to send push notifications using the FCM HTTP protocol a - [Send messages using the legacy app server protocols](https://firebase.google.com/docs/cloud-messaging/send-message#send_messages_using_the_legacy_app_server_protocols 'Send messages using the legacy app server protocols') - [Firebase Cloud Messaging HTTP Protocol](https://firebase.google.com/docs/cloud-messaging/http-server-ref 'Firebase Cloud Messaging HTTP Protocol') - -# Windows Behaviour - -## Notifications - -The plugin supports all types of windows platform notifications namely [Tile, Toast, Badge and Raw](https://msdn.microsoft.com/en-us/library/windows/apps/Hh779725.aspx). The API supports the basic cases of the notification templates with title corresponding to the first text element and message corresponding to the second if title is present else the first one. The image corresponds to the first image element of the notification xml. - -The count is present only for the badge notification in which it represent the value of the notification which could be a number from 0-99 or a status glyph. - -For advanced templates and usage, the notification object is included in [`data.additionalData.pushNotificationReceivedEventArgs`](https://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.pushnotifications.pushnotificationreceivedeventargs). - -## Setting Toast Capable Option for Windows - -This plugin automatically sets the toast capable flag to be true for Cordova 5.1.1+. For lower versions, you must declare that it is Toast Capable in your app's manifest file. - -## Disabling the default processing of notifications by Windows - -The default handling can be disabled by setting the 'cancel' property in the notification object. - -```javascript -data.additionalData.pushNotificationReceivedEventArgs.cancel = true; -``` - -## Background Notifications - -On Windows, to trigger the on('notification') event handler when your app is in the background and it is launched through the push notification, you will have to include `activation` data in the payload of the notification. This is done by using the `launch` attribute, which can be any string that can be understood by the app. However it should not cause the XML payload to become invalid. - -If you do not include a launch attribute string, your app will be launched normally, as though the user had launched it from the Start screen, and the notification event handler won't be called. - -Here is an example of a sample toast notification payload containing the launch attribute: - -```xml - - - - red graphic - Hello World! - - - -``` - -This launch attribute string is passed on to the app as data.launchArgs through the on('notification') handler. It's important to note that due to the Windows platform design, the other visual payload is not available to the handler on cold start. Notification attributes like message, title, etc., are available through the on('notification') handler when the app is running, and won't be available for background notifications. diff --git a/docs/PLATFORM_SUPPORT.md b/docs/PLATFORM_SUPPORT.md index 9510cf81c..a5a4bd921 100644 --- a/docs/PLATFORM_SUPPORT.md +++ b/docs/PLATFORM_SUPPORT.md @@ -6,7 +6,6 @@ - Android (`cordova-android` 12.0.0 or higher) - Browser - iOS (`cordova-ios` 6.0.0 or higher) -- Windows Universal (not Windows Phone 8) ### Version 3.x.x diff --git a/docs/TYPESCRIPT.md b/docs/TYPESCRIPT.md index 093cc4e4b..70fc03256 100644 --- a/docs/TYPESCRIPT.md +++ b/docs/TYPESCRIPT.md @@ -17,8 +17,7 @@ const push = PushNotification.init({ alert: "true", badge: true, sound: 'false' - }, - windows: {} + } }); push.on('registration', (data) => { diff --git a/hooks/windows/setToastCapable.js b/hooks/windows/setToastCapable.js deleted file mode 100644 index ade622fe2..000000000 --- a/hooks/windows/setToastCapable.js +++ /dev/null @@ -1,18 +0,0 @@ -module.exports = function (context) { - console.log('Updating appxmanifests with ToastCapable=true ...'); - var path = require('path'); - var fs = require('fs'); - - var platformProjPath = path.join(context.opts.projectRoot, 'platforms/windows'); - if (!fs.existsSync(platformProjPath)) { - platformProjPath = context.opts.projectRoot; - } - - var AppxManifest = require(path.join(platformProjPath, 'cordova/lib/AppxManifest')); - - ['package.phone.appxmanifest', 'package.windows.appxmanifest'].forEach(function (manifestPath) { - var manifest = AppxManifest.get(path.join(platformProjPath, manifestPath)); - manifest.getVisualElements().setToastCapable(true); - manifest.write(); - }); -}; diff --git a/package.json b/package.json index cbc57a47b..534981ebe 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,6 @@ "ecosystem:cordova", "cordova-ios", "cordova-android", - "cordova-windows", "cordova-browser" ], "author": "Erisu", @@ -66,7 +65,6 @@ "platforms": [ "ios", "android", - "windows", "browser" ] } diff --git a/plugin.xml b/plugin.xml index ff9eb674f..143e8ca50 100755 --- a/plugin.xml +++ b/plugin.xml @@ -4,7 +4,7 @@ id="@havesource/cordova-plugin-push" version="4.0.0-dev.0"> Cordova Push Plugin - Enable receiving push notifications on Android, iOS and Windows devices. Android uses Firebase Cloud Messaging. iOS uses Apple APNS Notifications. Windows uses Microsoft WNS Notifications. + Enable receiving push notifications on Android and iOS devices. Android uses Firebase Cloud Messaging. iOS uses Apple APNS Notifications. MIT @@ -132,15 +132,4 @@ - - - - - - - - - - - diff --git a/spec/index.spec.js b/spec/index.spec.js index 6074cf2f1..233af4bab 100644 --- a/spec/index.spec.js +++ b/spec/index.spec.js @@ -16,7 +16,7 @@ let options; describe('phonegap-plugin-push', () => { beforeEach(() => { - options = { android: {}, ios: {}, windows: {} }; + options = { android: {}, ios: {} }; execWin = jasmine.createSpy(); execSpy = spyOn(cordova.required, 'cordova/exec').and.callFake(execWin); }); diff --git a/src/windows/PushPluginProxy.js b/src/windows/PushPluginProxy.js deleted file mode 100644 index bc922790b..000000000 --- a/src/windows/PushPluginProxy.js +++ /dev/null @@ -1,101 +0,0 @@ -var myApp = {}; -var pushNotifications = Windows.Networking.PushNotifications; - -var createNotificationJSON = function (e) { - var result = { message: '' }; // Added to identify callback as notification type in the API in case where notification has no message - var notificationPayload; - - switch (e.notificationType) { - case pushNotifications.PushNotificationType.toast: - case pushNotifications.PushNotificationType.tile: - if (e.notificationType === pushNotifications.PushNotificationType.toast) { - notificationPayload = e.toastNotification.content; - } else { - notificationPayload = e.tileNotification.content; - } - var texts = notificationPayload.getElementsByTagName('text'); - if (texts.length > 1) { - result.title = texts[0].innerText; - result.message = texts[1].innerText; - } else if (texts.length === 1) { - result.message = texts[0].innerText; - } - var images = notificationPayload.getElementsByTagName('image'); - if (images.length > 0) { - result.image = images[0].getAttribute('src'); - } - var soundFile = notificationPayload.getElementsByTagName('audio'); - if (soundFile.length > 0) { - result.sound = soundFile[0].getAttribute('src'); - } - break; - - case pushNotifications.PushNotificationType.badge: - notificationPayload = e.badgeNotification.content; - result.count = notificationPayload.getElementsByTagName('badge')[0].getAttribute('value'); - break; - - case pushNotifications.PushNotificationType.raw: - result.message = e.rawNotification.content; - break; - } - - result.additionalData = { coldstart: false }; // this gets called only when the app is running - result.additionalData.pushNotificationReceivedEventArgs = e; - return result; -}; - -module.exports = { - init: function (onSuccess, onFail, args) { - var onNotificationReceived = function (e) { - var result = createNotificationJSON(e); - onSuccess(result, { keepCallback: true }); - }; - - try { - pushNotifications.PushNotificationChannelManager.createPushNotificationChannelForApplicationAsync().done( - function (channel) { - var result = {}; - result.registrationId = channel.uri; - myApp.channel = channel; - channel.addEventListener('pushnotificationreceived', onNotificationReceived); - myApp.notificationEvent = onNotificationReceived; - onSuccess(result, { keepCallback: true }); - - var context = cordova.require('cordova/platform').activationContext; - var launchArgs = context ? (context.argument || context.args) : null; - if (launchArgs) { // If present, app launched through push notification - result = { message: '' }; // Added to identify callback as notification type in the API - result.launchArgs = launchArgs; - result.additionalData = { coldstart: true }; - onSuccess(result, { keepCallback: true }); - } - }, function (error) { - onFail(error); - }); - } catch (ex) { - onFail(ex); - } - }, - unregister: function (onSuccess, onFail, args) { - try { - myApp.channel.removeEventListener('pushnotificationreceived', myApp.notificationEvent); - myApp.channel.close(); - onSuccess(); - } catch (ex) { - onFail(ex); - } - }, - hasPermission: function (onSuccess) { - var notifier = Windows.UI.Notifications.ToastNotificationManager.createToastNotifier(); - - onSuccess({ isEnabled: !notifier.setting }); - }, - subscribe: function () { - console.log('Subscribe is unsupported'); - }, - unsubscribe: function () { - console.log('Subscribe is unsupported'); - } -}; -require('cordova/exec/proxy').add('PushNotification', module.exports); diff --git a/types/index.d.ts b/types/index.d.ts index 0c93dffcc..77c2b8484 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -229,13 +229,6 @@ declare namespace PhonegapPluginPush { */ topics?: string[] } - - /** - * Windows specific initialization options. - */ - windows?: { - - } } interface CategoryArray { @@ -273,7 +266,6 @@ declare namespace PhonegapPluginPush { title?: string /** * The number of messages to be displayed in the badge iOS or message count in the notification shade in Android. - * For windows, it represents the value in the badge notification which could be a number or a status glyph. */ count: string /**