diff --git a/package-lock.json b/package-lock.json index 71595c964..f51d59e82 100644 --- a/package-lock.json +++ b/package-lock.json @@ -35,6 +35,7 @@ "@awesome-cordova-plugins/local-notifications": "^6.3.0", "@awesome-cordova-plugins/media-capture": "^6.3.0", "@awesome-cordova-plugins/network": "^6.3.0", + "@awesome-cordova-plugins/push": "^6.3.0", "@awesome-cordova-plugins/splash-screen": "^6.3.0", "@awesome-cordova-plugins/sqlite": "^6.3.0", "@awesome-cordova-plugins/status-bar": "^6.3.0", @@ -51,7 +52,6 @@ "@moodlehq/cordova-plugin-qrscanner": "3.0.1-moodle.5", "@moodlehq/cordova-plugin-statusbar": "4.0.0-moodle.2", "@moodlehq/cordova-plugin-zip": "3.1.0-moodle.1", - "@moodlehq/ionic-native-push": "5.36.0-moodle.2", "@moodlehq/phonegap-plugin-push": "4.0.0-moodle.7", "@ngx-translate/core": "^15.0.0", "@ngx-translate/http-loader": "^8.0.0", @@ -985,6 +985,18 @@ "rxjs": "^5.5.0 || ^6.5.0 || ^7.3.0" } }, + "node_modules/@awesome-cordova-plugins/push": { + "version": "6.4.0", + "resolved": "https://registry.npmjs.org/@awesome-cordova-plugins/push/-/push-6.4.0.tgz", + "integrity": "sha512-9bKKtEbKOh0kOrmofB8ofuy0LKTjtAYvOZ/UzpIJ5luc7KEKxxELxWvHK24uhBXU64VZpZpHbMWOJWNOCEyrpg==", + "dependencies": { + "@types/cordova": "latest" + }, + "peerDependencies": { + "@awesome-cordova-plugins/core": "^6.0.1", + "rxjs": "^5.5.0 || ^6.5.0 || ^7.3.0" + } + }, "node_modules/@awesome-cordova-plugins/splash-screen": { "version": "6.4.0", "resolved": "https://registry.npmjs.org/@awesome-cordova-plugins/splash-screen/-/splash-screen-6.4.0.tgz", @@ -5198,60 +5210,6 @@ } ] }, - "node_modules/@moodlehq/ionic-native-push": { - "version": "5.36.0-moodle.2", - "resolved": "https://registry.npmjs.org/@moodlehq/ionic-native-push/-/ionic-native-push-5.36.0-moodle.2.tgz", - "integrity": "sha512-UWT4WaoTEEqGQ5pu+CyakXCOhiXsQSb8mD8j89jDqV0hJyrIQ8zA2ciGW9Y/vd55NuqjCu1tNJcWEJ4WcRVv0Q==", - "dependencies": { - "@angular/core": "^9.1.12", - "@ionic-native/core": "^5.1.0", - "@types/cordova": "latest", - "rxjs": "^5.5.0 || ^6.5.0" - } - }, - "node_modules/@moodlehq/ionic-native-push/node_modules/@angular/core": { - "version": "9.1.13", - "resolved": "https://registry.npmjs.org/@angular/core/-/core-9.1.13.tgz", - "integrity": "sha512-mBm24Q9GjkAsxMAzqQ86U1078+yTEpr0+syMEruUtJ0HUH6Fzn3J+6xTLb+BVcGb9RkCkFaV9T5mcn6ZM0f++g==", - "peerDependencies": { - "rxjs": "^6.5.3", - "tslib": "^1.10.0", - "zone.js": "~0.10.3" - } - }, - "node_modules/@moodlehq/ionic-native-push/node_modules/@ionic-native/core": { - "version": "5.36.0", - "resolved": "https://registry.npmjs.org/@ionic-native/core/-/core-5.36.0.tgz", - "integrity": "sha512-lOrkktadlKYbYf1LrDyAtsu1JnQ0oCCdkOU7iHQ8oXnNOkMwobFfD2m62F1CoOr0u9LIkpYnZSPjng8lZbmbNw==", - "dependencies": { - "@types/cordova": "latest" - }, - "peerDependencies": { - "rxjs": "^5.5.0 || ^6.5.0" - } - }, - "node_modules/@moodlehq/ionic-native-push/node_modules/rxjs": { - "version": "6.6.7", - "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.6.7.tgz", - "integrity": "sha512-hTdwr+7yYNIT5n4AMYp85KA6yw2Va0FLa3Rguvbpa4W3I5xynaBZo41cM3XM+4Q6fRMj3sBYIR1VAmZMXYJvRQ==", - "dependencies": { - "tslib": "^1.9.0" - }, - "engines": { - "npm": ">=2.0.0" - } - }, - "node_modules/@moodlehq/ionic-native-push/node_modules/tslib": { - "version": "1.14.1", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", - "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==" - }, - "node_modules/@moodlehq/ionic-native-push/node_modules/zone.js": { - "version": "0.10.3", - "resolved": "https://registry.npmjs.org/zone.js/-/zone.js-0.10.3.tgz", - "integrity": "sha512-LXVLVEq0NNOqK/fLJo3d0kfzd4sxwn2/h67/02pjCjfKDxgx1i9QqpvtHD8CrBnSSwMw5+dy11O7FRX5mkO7Cg==", - "peer": true - }, "node_modules/@moodlehq/phonegap-plugin-push": { "version": "4.0.0-moodle.7", "resolved": "https://registry.npmjs.org/@moodlehq/phonegap-plugin-push/-/phonegap-plugin-push-4.0.0-moodle.7.tgz", diff --git a/package.json b/package.json index cdf914c8b..db5e4aec4 100644 --- a/package.json +++ b/package.json @@ -70,6 +70,7 @@ "@awesome-cordova-plugins/local-notifications": "^6.3.0", "@awesome-cordova-plugins/media-capture": "^6.3.0", "@awesome-cordova-plugins/network": "^6.3.0", + "@awesome-cordova-plugins/push": "^6.3.0", "@awesome-cordova-plugins/splash-screen": "^6.3.0", "@awesome-cordova-plugins/sqlite": "^6.3.0", "@awesome-cordova-plugins/status-bar": "^6.3.0", @@ -86,7 +87,6 @@ "@moodlehq/cordova-plugin-qrscanner": "3.0.1-moodle.5", "@moodlehq/cordova-plugin-statusbar": "4.0.0-moodle.2", "@moodlehq/cordova-plugin-zip": "3.1.0-moodle.1", - "@moodlehq/ionic-native-push": "5.36.0-moodle.2", "@moodlehq/phonegap-plugin-push": "4.0.0-moodle.7", "@ngx-translate/core": "^15.0.0", "@ngx-translate/http-loader": "^8.0.0", diff --git a/src/core/features/native/native.module.ts b/src/core/features/native/native.module.ts index 18449e534..dce3324fc 100644 --- a/src/core/features/native/native.module.ts +++ b/src/core/features/native/native.module.ts @@ -30,7 +30,7 @@ import { WebView } from '@awesome-cordova-plugins/ionic-webview/ngx'; import { Keyboard } from '@awesome-cordova-plugins/keyboard/ngx'; import { LocalNotifications } from '@awesome-cordova-plugins/local-notifications/ngx'; import { MediaCapture } from '@awesome-cordova-plugins/media-capture/ngx'; -import { Push } from '@moodlehq/ionic-native-push/ngx'; +import { Push } from '@features/native/plugins/push'; import { QRScanner } from '@ionic-native/qr-scanner/ngx'; import { SplashScreen } from '@awesome-cordova-plugins/splash-screen/ngx'; import { SQLite } from '@awesome-cordova-plugins/sqlite/ngx'; @@ -80,7 +80,6 @@ export const CORE_NATIVE_SERVICES = [ Keyboard, LocalNotifications, MediaCapture, - Push, QRScanner, SplashScreen, SQLite, diff --git a/src/core/features/native/plugins/index.ts b/src/core/features/native/plugins/index.ts index ee50e1680..539ad0901 100644 --- a/src/core/features/native/plugins/index.ts +++ b/src/core/features/native/plugins/index.ts @@ -14,7 +14,9 @@ import { makeSingleton } from '@singletons'; import { Chooser as ChooserService } from './chooser'; +import { Push as PushService } from './push'; import { Zip as ZipService } from './zip'; export const Chooser = makeSingleton(ChooserService); +export const Push = makeSingleton(PushService); export const Zip = makeSingleton(ZipService); diff --git a/src/core/features/native/plugins/push.ts b/src/core/features/native/plugins/push.ts new file mode 100644 index 000000000..f0cc9a20a --- /dev/null +++ b/src/core/features/native/plugins/push.ts @@ -0,0 +1,34 @@ +// (C) Copyright 2015 Moodle Pty Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import { Injectable } from '@angular/core'; +import { Push as IonicPush } from '@awesome-cordova-plugins/push/ngx'; + +/** + * Push plugin wrapper. + */ +@Injectable({ providedIn: 'root' }) +export class Push extends IonicPush { + + /** + * The getPublicKey method is used to retrieve x.509 public key from the device keychain. + * Returns null if the device doesn't support the encryption methods. + * + * @returns Public key or null. + */ + getPublicKey(): Promise { + return new Promise((resolve, reject) => PushNotification.getPublicKey(resolve, reject)); + } + +} diff --git a/src/core/features/pushnotifications/services/pushnotifications.ts b/src/core/features/pushnotifications/services/pushnotifications.ts index aec8d807c..4413f8d33 100644 --- a/src/core/features/pushnotifications/services/pushnotifications.ts +++ b/src/core/features/pushnotifications/services/pushnotifications.ts @@ -14,7 +14,7 @@ import { Injectable } from '@angular/core'; import { ILocalNotification } from '@awesome-cordova-plugins/local-notifications'; -import { NotificationEventResponse, PushOptions, RegistrationEventResponse } from '@moodlehq/ionic-native-push/ngx'; +import { NotificationEventResponse, PushOptions, RegistrationEventResponse } from '@awesome-cordova-plugins/push/ngx'; import { CoreApp } from '@services/app'; import { CoreSites } from '@services/sites'; @@ -25,7 +25,7 @@ import { CoreTextUtils } from '@services/utils/text'; import { CoreConfig } from '@services/config'; import { CoreConstants } from '@/core/constants'; import { CoreSite } from '@classes/sites/site'; -import { makeSingleton, Badge, Push, Device, Translate, ApplicationInit, NgZone } from '@singletons'; +import { makeSingleton, Badge, Device, Translate, ApplicationInit, NgZone } from '@singletons'; import { CoreLogger } from '@singletons/logger'; import { CoreEvents } from '@singletons/events'; import { @@ -49,6 +49,7 @@ import { lazyMap, LazyMap } from '@/core/utils/lazy-map'; import { CorePlatform } from '@services/platform'; import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics'; import { CoreSiteInfo } from '@classes/sites/unauthenticated-site'; +import { Push } from '@features/native/plugins'; /** * Service to handle push notifications. diff --git a/src/core/services/local-notifications.ts b/src/core/services/local-notifications.ts index 87fa6ff1e..f7cc1b4ba 100644 --- a/src/core/services/local-notifications.ts +++ b/src/core/services/local-notifications.ts @@ -24,7 +24,7 @@ import { SQLiteDB } from '@classes/sqlitedb'; import { CoreQueueRunner } from '@classes/queue-runner'; import { CoreError } from '@classes/errors/error'; import { CoreConstants } from '@/core/constants'; -import { makeSingleton, NgZone, Translate, LocalNotifications, Push } from '@singletons'; +import { makeSingleton, NgZone, Translate, LocalNotifications } from '@singletons'; import { CoreLogger } from '@singletons/logger'; import { APP_SCHEMA, @@ -35,6 +35,7 @@ import { } from '@services/database/local-notifications'; import { CorePromisedValue } from '@classes/promised-value'; import { CorePlatform } from '@services/platform'; +import { Push } from '@features/native/plugins'; /** * Service to handle local notifications. diff --git a/src/core/singletons/index.ts b/src/core/singletons/index.ts index 8059bd553..e14c219f4 100644 --- a/src/core/singletons/index.ts +++ b/src/core/singletons/index.ts @@ -52,7 +52,6 @@ import { WebView as WebViewService } from '@awesome-cordova-plugins/ionic-webvie import { Keyboard as KeyboardService } from '@awesome-cordova-plugins/keyboard/ngx'; import { LocalNotifications as LocalNotificationsService } from '@awesome-cordova-plugins/local-notifications/ngx'; import { MediaCapture as MediaCaptureService } from '@awesome-cordova-plugins/media-capture/ngx'; -import { Push as PushService } from '@moodlehq/ionic-native-push/ngx'; import { QRScanner as QRScannerService } from '@ionic-native/qr-scanner/ngx'; import { StatusBar as StatusBarService } from '@awesome-cordova-plugins/status-bar/ngx'; import { SplashScreen as SplashScreenService } from '@awesome-cordova-plugins/splash-screen/ngx'; @@ -184,7 +183,6 @@ export const Keyboard = makeSingleton(KeyboardService); export const LocalNotifications = makeSingleton(LocalNotificationsService); export const MediaCapture = makeSingleton(MediaCaptureService); export const NativeHttp = makeSingleton(HTTP); -export const Push = makeSingleton(PushService); export const QRScanner = makeSingleton(QRScannerService); export const StatusBar = makeSingleton(StatusBarService); export const SplashScreen = makeSingleton(SplashScreenService); diff --git a/tsconfig.app.json b/tsconfig.app.json index ed7c3da76..addf75e8c 100644 --- a/tsconfig.app.json +++ b/tsconfig.app.json @@ -5,6 +5,7 @@ "types": [ "@moodlehq/cordova-plugin-file-transfer", "@moodlehq/cordova-plugin-inappbrowser", + "@moodlehq/phonegap-plugin-push", "cordova-plugin-moodleapp", "cordova", "dom-mediacapture-record", diff --git a/tsconfig.json b/tsconfig.json index d0bde2143..5d9f61597 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -25,6 +25,7 @@ "types": [ "@moodlehq/cordova-plugin-file-transfer", "@moodlehq/cordova-plugin-inappbrowser", + "@moodlehq/phonegap-plugin-push", "cordova-plugin-moodleapp", "cordova", "dom-mediacapture-record", diff --git a/tsconfig.spec.json b/tsconfig.spec.json index b4c9aede2..737aed334 100644 --- a/tsconfig.spec.json +++ b/tsconfig.spec.json @@ -9,6 +9,7 @@ "types": [ "@moodlehq/cordova-plugin-file-transfer", "@moodlehq/cordova-plugin-inappbrowser", + "@moodlehq/phonegap-plugin-push", "cordova-plugin-moodleapp", "cordova", "dom-mediacapture-record",