diff --git a/config.xml b/config.xml index 819ed63e5..486b7deb8 100644 --- a/config.xml +++ b/config.xml @@ -114,6 +114,9 @@ + + We need your location so you can attach it as part of your submissions. + @@ -129,6 +132,9 @@ + + + diff --git a/package-lock.json b/package-lock.json index 4088d7a77..e67d1a2b2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -145,6 +145,11 @@ "resolved": "https://registry.npmjs.org/@ionic-native/file-transfer/-/file-transfer-4.17.0.tgz", "integrity": "sha512-GtCnjCMH02r5BLONYkPjcYDAXSHmrO9t8jPY5LoI29bx2B6vwX+NFBARHPNSFPEwRi1zZKs/J0uJ1hkhDzOvxg==" }, + "@ionic-native/geolocation": { + "version": "4.17.0", + "resolved": "https://registry.npmjs.org/@ionic-native/geolocation/-/geolocation-4.17.0.tgz", + "integrity": "sha512-VgMOAP/Kjnpx4cwufFbx/DeoSoERfHt7X+I5aiOVo3J9w2rICUK3jyEccWVP0FPAfcIMrJoofpFK88TeY7O+tg==" + }, "@ionic-native/globalization": { "version": "4.17.0", "resolved": "https://registry.npmjs.org/@ionic-native/globalization/-/globalization-4.17.0.tgz", @@ -498,7 +503,8 @@ "ansi-regex": { "version": "2.1.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "aproba": { "version": "1.2.0", @@ -519,12 +525,14 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -539,17 +547,20 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -666,7 +677,8 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -678,6 +690,7 @@ "version": "1.0.0", "bundled": true, "dev": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -692,6 +705,7 @@ "version": "3.0.4", "bundled": true, "dev": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -699,12 +713,14 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "minipass": { "version": "2.3.5", "bundled": true, "dev": true, + "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -723,6 +739,7 @@ "version": "0.5.1", "bundled": true, "dev": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -803,7 +820,8 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -815,6 +833,7 @@ "version": "1.4.0", "bundled": true, "dev": true, + "optional": true, "requires": { "wrappy": "1" } @@ -900,7 +919,8 @@ "safe-buffer": { "version": "5.1.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "safer-buffer": { "version": "2.1.2", @@ -936,6 +956,7 @@ "version": "1.0.2", "bundled": true, "dev": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -955,6 +976,7 @@ "version": "3.0.1", "bundled": true, "dev": true, + "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -998,12 +1020,14 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "yallist": { "version": "3.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true } } }, @@ -7453,6 +7477,11 @@ "resolved": "https://registry.npmjs.org/cordova-plugin-file-transfer/-/cordova-plugin-file-transfer-1.7.1.tgz", "integrity": "sha1-p12L4uvDu5sjxbG70ZkhTsJnWGs=" }, + "cordova-plugin-geolocation": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/cordova-plugin-geolocation/-/cordova-plugin-geolocation-4.0.2.tgz", + "integrity": "sha512-QGThnPKzPxESHkruZlpE0+5aFBVOet8al0vIJ7laSUOQHIC1dd/JY6peVIbtLboKi5Dap1wCKRubOqPqH8xcQA==" + }, "cordova-plugin-globalization": { "version": "1.11.0", "resolved": "https://registry.npmjs.org/cordova-plugin-globalization/-/cordova-plugin-globalization-1.11.0.tgz", @@ -7469,7 +7498,7 @@ "integrity": "sha512-6ucQ6FdlLdBm8kJfFnzozmBTjru/0xekHP/dAhjoCZggkGRlgs8TsUJFkxa/bV+qi7Dlo50JjmpE4UMWAO+aOQ==" }, "cordova-plugin-local-notification": { - "version": "git+https://github.com/moodlemobile/cordova-plugin-local-notification.git#5b2f3073a1c1fb39cad3566be792445c343db2c6", + "version": "git+https://github.com/moodlemobile/cordova-plugin-local-notification.git#c7430c4f4f8b8c82d051aea49d87da0b4f6a8b1e", "from": "git+https://github.com/moodlemobile/cordova-plugin-local-notification.git#moodle" }, "cordova-plugin-media-capture": { @@ -9152,7 +9181,8 @@ }, "ansi-regex": { "version": "2.1.1", - "bundled": true + "bundled": true, + "optional": true }, "aproba": { "version": "1.2.0", @@ -9170,11 +9200,13 @@ }, "balanced-match": { "version": "1.0.0", - "bundled": true + "bundled": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -9187,15 +9219,18 @@ }, "code-point-at": { "version": "1.1.0", - "bundled": true + "bundled": true, + "optional": true }, "concat-map": { "version": "0.0.1", - "bundled": true + "bundled": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", - "bundled": true + "bundled": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -9298,7 +9333,8 @@ }, "inherits": { "version": "2.0.3", - "bundled": true + "bundled": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -9308,6 +9344,7 @@ "is-fullwidth-code-point": { "version": "1.0.0", "bundled": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -9320,17 +9357,20 @@ "minimatch": { "version": "3.0.4", "bundled": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } }, "minimist": { "version": "0.0.8", - "bundled": true + "bundled": true, + "optional": true }, "minipass": { "version": "2.3.5", "bundled": true, + "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -9347,6 +9387,7 @@ "mkdirp": { "version": "0.5.1", "bundled": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -9425,7 +9466,8 @@ }, "number-is-nan": { "version": "1.0.1", - "bundled": true + "bundled": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -9435,6 +9477,7 @@ "once": { "version": "1.4.0", "bundled": true, + "optional": true, "requires": { "wrappy": "1" } @@ -9510,7 +9553,8 @@ }, "safe-buffer": { "version": "5.1.2", - "bundled": true + "bundled": true, + "optional": true }, "safer-buffer": { "version": "2.1.2", @@ -9540,6 +9584,7 @@ "string-width": { "version": "1.0.2", "bundled": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -9557,6 +9602,7 @@ "strip-ansi": { "version": "3.0.1", "bundled": true, + "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -9595,11 +9641,13 @@ }, "wrappy": { "version": "1.0.2", - "bundled": true + "bundled": true, + "optional": true }, "yallist": { "version": "3.0.3", - "bundled": true + "bundled": true, + "optional": true } } }, @@ -10025,7 +10073,8 @@ "ansi-regex": { "version": "2.1.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "aproba": { "version": "1.2.0", @@ -10046,12 +10095,14 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -10066,17 +10117,20 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -10193,7 +10247,8 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -10205,6 +10260,7 @@ "version": "1.0.0", "bundled": true, "dev": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -10219,6 +10275,7 @@ "version": "3.0.4", "bundled": true, "dev": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -10226,12 +10283,14 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "minipass": { "version": "2.3.5", "bundled": true, "dev": true, + "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -10250,6 +10309,7 @@ "version": "0.5.1", "bundled": true, "dev": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -10330,7 +10390,8 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -10342,6 +10403,7 @@ "version": "1.4.0", "bundled": true, "dev": true, + "optional": true, "requires": { "wrappy": "1" } @@ -10427,7 +10489,8 @@ "safe-buffer": { "version": "5.1.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "safer-buffer": { "version": "2.1.2", @@ -10463,6 +10526,7 @@ "version": "1.0.2", "bundled": true, "dev": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -10482,6 +10546,7 @@ "version": "3.0.1", "bundled": true, "dev": true, + "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -10525,12 +10590,14 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "yallist": { "version": "3.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true } } }, @@ -13567,7 +13634,7 @@ "integrity": "sha512-1wvc3iQOQpEBaQbXgLxA2JUiLSQ2azdF/bF29ghXDiQJWSpQ1BF8gSuqttM8WZoj081Ps8OKL0gYxdDBkFNPqA==" }, "phonegap-plugin-push": { - "version": "git+https://github.com/moodlemobile/phonegap-plugin-push.git#cf8101e86adb774ae1d7ad6b65fb9d8802673f4b", + "version": "git+https://github.com/moodlemobile/phonegap-plugin-push.git#cb332d5ec8a1a0d43916fc6d35455fe6bea7a7f9", "from": "git+https://github.com/moodlemobile/phonegap-plugin-push.git#moodle-v3", "requires": { "babel-plugin-add-header-comment": "^1.0.3", @@ -16303,7 +16370,8 @@ "ansi-regex": { "version": "2.1.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "aproba": { "version": "1.2.0", @@ -16324,12 +16392,14 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -16344,17 +16414,20 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -16471,7 +16544,8 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -16483,6 +16557,7 @@ "version": "1.0.0", "bundled": true, "dev": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -16497,6 +16572,7 @@ "version": "3.0.4", "bundled": true, "dev": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -16504,12 +16580,14 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "minipass": { "version": "2.3.5", "bundled": true, "dev": true, + "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -16528,6 +16606,7 @@ "version": "0.5.1", "bundled": true, "dev": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -16608,7 +16687,8 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -16620,6 +16700,7 @@ "version": "1.4.0", "bundled": true, "dev": true, + "optional": true, "requires": { "wrappy": "1" } @@ -16705,7 +16786,8 @@ "safe-buffer": { "version": "5.1.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "safer-buffer": { "version": "2.1.2", @@ -16741,6 +16823,7 @@ "version": "1.0.2", "bundled": true, "dev": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -16760,6 +16843,7 @@ "version": "3.0.1", "bundled": true, "dev": true, + "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -16803,12 +16887,14 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "yallist": { "version": "3.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true } } }, diff --git a/package.json b/package.json index 8f366c35e..9e7dedecd 100644 --- a/package.json +++ b/package.json @@ -57,6 +57,7 @@ "@ionic-native/file": "^4.17.0", "@ionic-native/file-opener": "^4.17.0", "@ionic-native/file-transfer": "^4.17.0", + "@ionic-native/geolocation": "4.17.0", "@ionic-native/globalization": "^4.17.0", "@ionic-native/in-app-browser": "^4.17.0", "@ionic-native/keyboard": "^4.17.0", @@ -93,6 +94,7 @@ "cordova-plugin-file": "^6.0.2", "cordova-plugin-file-opener2": "2.0.19", "cordova-plugin-file-transfer": "^1.7.1", + "cordova-plugin-geolocation": "^4.0.2", "cordova-plugin-globalization": "^1.11.0", "cordova-plugin-inappbrowser": "^3.1.0", "cordova-plugin-ionic-keyboard": "^2.1.3", @@ -177,6 +179,9 @@ "phonegap-plugin-push": { "ANDROID_SUPPORT_V13_VERSION": "27.+", "FCM_VERSION": "17.0.+" + }, + "cordova-plugin-geolocation": { + "GEOLOCATION_USAGE_DESCRIPTION": "To locate you" } } }, diff --git a/src/core/emulator/emulator.module.ts b/src/core/emulator/emulator.module.ts index b6307b4e1..a24a2b08e 100644 --- a/src/core/emulator/emulator.module.ts +++ b/src/core/emulator/emulator.module.ts @@ -23,6 +23,7 @@ import { Device } from '@ionic-native/device'; import { File } from '@ionic-native/file'; import { FileOpener } from '@ionic-native/file-opener'; import { FileTransfer } from '@ionic-native/file-transfer'; +import { Geolocation } from '@ionic-native/geolocation'; import { Globalization } from '@ionic-native/globalization'; import { InAppBrowser } from '@ionic-native/in-app-browser'; import { Keyboard } from '@ionic-native/keyboard'; @@ -43,6 +44,7 @@ import { ClipboardMock } from './providers/clipboard'; import { FileMock } from './providers/file'; import { FileOpenerMock } from './providers/file-opener'; import { FileTransferMock } from './providers/file-transfer'; +import { GeolocationMock } from './providers/geolocation'; import { GlobalizationMock } from './providers/globalization'; import { InAppBrowserMock } from './providers/inappbrowser'; import { LocalNotificationsMock } from './providers/local-notifications'; @@ -70,6 +72,7 @@ export const IONIC_NATIVE_PROVIDERS = [ File, FileOpener, FileTransfer, + Geolocation, Globalization, InAppBrowser, Keyboard, @@ -148,6 +151,13 @@ export const IONIC_NATIVE_PROVIDERS = [ return appProvider.isMobile() ? new FileTransfer() : new FileTransferMock(appProvider, fileProvider); } }, + { + provide: Geolocation, + deps: [CoreAppProvider], + useFactory: (appProvider: CoreAppProvider): Geolocation => { + return appProvider.isMobile() ? new Geolocation() : new GeolocationMock(); + } + }, { provide: Globalization, deps: [CoreAppProvider], diff --git a/src/core/emulator/providers/geolocation.ts b/src/core/emulator/providers/geolocation.ts new file mode 100644 index 000000000..cf9e9a632 --- /dev/null +++ b/src/core/emulator/providers/geolocation.ts @@ -0,0 +1,55 @@ +// (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 { Geolocation, GeolocationOptions, Geoposition } from '@ionic-native/geolocation'; +import { Observable, Subscriber } from 'rxjs'; +import { TeardownLogic } from 'rxjs/Subscription'; + +/** + * Emulates the Cordova Geolocation plugin in desktop apps and in browser. + */ +@Injectable() +export class GeolocationMock extends Geolocation { + + /** + * Get the device's current position. + * + * @param options The geolocation options. + * @returns Returns a Promise that resolves with the position of the device, or rejects with an error. + */ + getCurrentPosition(options?: GeolocationOptions): Promise { + return new Promise((resolve, reject): any => { + return navigator.geolocation.getCurrentPosition(resolve, reject, options); + }); + } + + /** + * Watch the current device's position. Clear the watch by unsubscribing from + * Observable changes. + * + * @param options The geolocation options. + * @returns Returns an Observable that notifies with the position of the device, or errors. + */ + watchPosition(options?: GeolocationOptions): Observable { + return new Observable((subscriber: Subscriber): TeardownLogic => { + const watchId = navigator.geolocation.watchPosition( + subscriber.next.bind(subscriber), subscriber.error.bind(subscriber), options); + + return (): void => { + navigator.geolocation.clearWatch(watchId); + }; + }); + } +}