Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

chore: dep updates #265

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ publish/src
publish/package
src/platforms/android/nativescript_geolocation.aar
!demo-vue/app/app.js
package-lock.json
*.tgz
3 changes: 2 additions & 1 deletion src/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
tsconfig.json
/platforms/android/**/*
!platforms/android/include.gradle
!platforms/android/nativescript_geolocation.aar
!platforms/android/nativescript_geolocation.aar
*.tgz
26 changes: 12 additions & 14 deletions src/geolocation.android.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { on as applicationOn, android as androidAppInstance, AndroidApplication, uncaughtErrorEvent, UnhandledErrorEventData } from "application";
import { Accuracy } from "tns-core-modules/ui/enums";
import { setTimeout, clearTimeout } from "tns-core-modules/timer";
import { Enums, Application, UnhandledErrorEventData, AndroidApplication } from "@nativescript/core";
import { LocationBase, defaultGetLocationTimeout, fastestTimeUpdate, minTimeUpdate } from "./geolocation.common";
import { Options, successCallbackType, errorCallbackType } from "./location-monitor";
import * as permissions from "nativescript-permissions";
Expand All @@ -18,10 +16,10 @@ let attachedForErrorHandling = false;
function _ensureLocationClient() {
// Wrapped in a function as we should not access java object there because of the snapshots.
fusedLocationClient = fusedLocationClient ||
com.google.android.gms.location.LocationServices.getFusedLocationProviderClient(androidAppInstance.context);
com.google.android.gms.location.LocationServices.getFusedLocationProviderClient(Application.android.context);
}

androidAppInstance.on(AndroidApplication.activityResultEvent, function (args: any) {
Application.android.on(AndroidApplication.activityResultEvent, function (args: any) {
if (args.requestCode === REQUEST_ENABLE_LOCATION) {
if (args.resultCode === 0) {
if (_onEnableLocationFail) {
Expand All @@ -34,13 +32,13 @@ androidAppInstance.on(AndroidApplication.activityResultEvent, function (args: an
});

function isAirplaneModeOn(): boolean {
return android.provider.Settings.System.getInt(androidAppInstance.context.getContentResolver(),
return android.provider.Settings.System.getInt(Application.android.context.getContentResolver(),
android.provider.Settings.System.AIRPLANE_MODE_ON) !== 0;
}

function isProviderEnabled(provider: string): boolean {
try {
const locationManager: android.location.LocationManager = (<android.content.Context>androidAppInstance.context)
const locationManager: android.location.LocationManager = (<android.content.Context>Application.android.context)
.getSystemService(android.content.Context.LOCATION_SERVICE);
return locationManager.isProviderEnabled(provider);
} catch (ex) {
Expand Down Expand Up @@ -115,7 +113,7 @@ function _getLocationRequest(options: Options): any {
if (options.updateDistance) {
mLocationRequest.setSmallestDisplacement(options.updateDistance);
}
if (options.desiredAccuracy === Accuracy.high) {
if (options.desiredAccuracy === Enums.Accuracy.high) {
mLocationRequest.setPriority(com.google.android.gms.location.LocationRequest.PRIORITY_HIGH_ACCURACY);
} else {
mLocationRequest.setPriority(com.google.android.gms.location.LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
Expand Down Expand Up @@ -178,7 +176,7 @@ export function watchLocation(successCallback: successCallbackType, errorCallbac

if (!attachedForErrorHandling) {
attachedForErrorHandling = true;
applicationOn(uncaughtErrorEvent, errorHandler.bind(this));
Application.on(Application.uncaughtErrorEvent, errorHandler.bind(this));
}

let locationRequest = _getLocationRequest(options);
Expand Down Expand Up @@ -215,7 +213,7 @@ export function enableLocationRequest(always?: boolean): Promise<void> {
// on REQUEST_ENABLE_LOCATION Activity Result
_onEnableLocationSuccess = resolve;
_onEnableLocationFail = reject;
return ex.startResolutionForResult(androidAppInstance.foregroundActivity, REQUEST_ENABLE_LOCATION);
return ex.startResolutionForResult(Application.android.foregroundActivity, REQUEST_ENABLE_LOCATION);
} catch (sendEx) {
// Ignore the error.
return resolve();
Expand All @@ -240,7 +238,7 @@ function _makeGooglePlayServicesAvailable(): Promise<void> {
return;
}
let googleApiAvailability = com.google.android.gms.common.GoogleApiAvailability.getInstance();
googleApiAvailability.makeGooglePlayServicesAvailable(androidAppInstance.foregroundActivity)
googleApiAvailability.makeGooglePlayServicesAvailable(Application.android.foregroundActivity)
.addOnSuccessListener(_getTaskSuccessListener(resolve))
.addOnFailureListener(_getTaskFailListener(reject));
});
Expand All @@ -253,7 +251,7 @@ function _isGooglePlayServicesAvailable(): boolean {

let isLocationServiceEnabled = true;
let googleApiAvailability = com.google.android.gms.common.GoogleApiAvailability.getInstance();
let resultCode = googleApiAvailability.isGooglePlayServicesAvailable(androidAppInstance.context);
let resultCode = googleApiAvailability.isGooglePlayServicesAvailable(Application.android.context);
if (resultCode !== com.google.android.gms.common.ConnectionResult.SUCCESS) {
isLocationServiceEnabled = false;
}
Expand All @@ -268,12 +266,12 @@ function _isLocationServiceEnabled(options?: Options): Promise<boolean> {
return;
}

options = options || { desiredAccuracy: Accuracy.high, updateTime: 0, updateDistance: 0, maximumAge: 0, timeout: 0 };
options = options || { desiredAccuracy: Enums.Accuracy.high, updateTime: 0, updateDistance: 0, maximumAge: 0, timeout: 0 };
let locationRequest = _getLocationRequest(options);
let locationSettingsBuilder = new com.google.android.gms.location.LocationSettingsRequest.Builder();
locationSettingsBuilder.addLocationRequest(locationRequest);
locationSettingsBuilder.setAlwaysShow(true);
let locationSettingsClient = com.google.android.gms.location.LocationServices.getSettingsClient(androidAppInstance.context);
let locationSettingsClient = com.google.android.gms.location.LocationServices.getSettingsClient(Application.android.context);
locationSettingsClient.checkLocationSettings(locationSettingsBuilder.build())
.addOnSuccessListener(_getTaskSuccessListener(resolve))
.addOnFailureListener(_getTaskFailListener(reject));
Expand Down
16 changes: 7 additions & 9 deletions src/geolocation.ios.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { Accuracy } from "tns-core-modules/ui/enums";
import { setTimeout, clearTimeout } from "tns-core-modules/timer";
import { on as applicationOn, uncaughtErrorEvent, UnhandledErrorEventData } from "tns-core-modules/application";
import { Application, Enums, UnhandledErrorEventData, Device } from "@nativescript/core";

import {
LocationBase,
Expand All @@ -12,13 +10,13 @@ import {
successCallbackType,
errorCallbackType
} from "./location-monitor";
import * as Platform from "platform";

const locationManagers = {};
const locationListeners = {};
let watchId = 0;
let attachedForErrorHandling = false;

@NativeClass()
class LocationListenerImpl extends NSObject implements CLLocationManagerDelegate {
public static ObjCProtocols = [CLLocationManagerDelegate]; // tslint:disable-line:variable-name

Expand Down Expand Up @@ -140,7 +138,7 @@ function errorHandler(errData: UnhandledErrorEventData) {
}

function getVersionMaj () {
return parseInt(Platform.device.osVersion.split(".")[0]);
return parseInt(Device.osVersion.split(".")[0]);
}

// options - desiredAccuracy, updateDistance, minimumUpdateTime, maximumAge, timeout
Expand Down Expand Up @@ -184,7 +182,7 @@ export function getCurrentLocation(options: Options): Promise<Location> {
return;
}

if (options.desiredAccuracy !== Accuracy.any && !initLocation) {
if (options.desiredAccuracy !== Enums.Accuracy.any && !initLocation) {
// regardless of desired accuracy ios returns first location as quick as possible even if not as accurate as requested
initLocation = location;
return;
Expand Down Expand Up @@ -223,7 +221,7 @@ export function watchLocation(successCallback: successCallbackType,
options: Options): number {
if (!attachedForErrorHandling) {
attachedForErrorHandling = true;
applicationOn(uncaughtErrorEvent, errorHandler.bind(this));
Application.on(Application.uncaughtErrorEvent, errorHandler.bind(this));
}

let zonedSuccessCallback = (<any>global).zonedCallback(successCallback);
Expand Down Expand Up @@ -359,7 +357,7 @@ export class LocationMonitor {
static createiOSLocationManager(locListener: any, options: Options): CLLocationManager {
let iosLocManager = new CLLocationManager();
iosLocManager.delegate = locListener;
iosLocManager.desiredAccuracy = options ? options.desiredAccuracy : Accuracy.high;
iosLocManager.desiredAccuracy = options ? options.desiredAccuracy : Enums.Accuracy.high;
iosLocManager.distanceFilter = options ? options.updateDistance : minRangeUpdate;
locationManagers[locListener.id] = iosLocManager;
locationListeners[locListener.id] = locListener;
Expand All @@ -384,7 +382,7 @@ function getIOSLocationManager(locListener: any, options: Options): CLLocationMa
let manager = new iosLocationManager();

manager.delegate = locListener;
manager.desiredAccuracy = options ? options.desiredAccuracy : Accuracy.high;
manager.desiredAccuracy = options ? options.desiredAccuracy : Enums.Accuracy.high;
manager.distanceFilter = options ? options.updateDistance : minRangeUpdate;

locationManagers[locListener.id] = manager;
Expand Down
21 changes: 12 additions & 9 deletions src/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nativescript-geolocation",
"version": "5.1.0",
"name": "@nativescript/geolocation",
"version": "7.0.0",
"description": "Provides API for getting and monitoring location for NativeScript app.",
"main": "geolocation",
"typings": "index.d.ts",
Expand All @@ -12,7 +12,7 @@
},
"scripts": {
"tsc": "tsc -skipLibCheck",
"build": "npm i && tsc",
"build": "npm i && ts-patch install && tsc",
"test.android": "npm i && npm run tsc && npm run tslint && cd ../demo && tns build android && tns test android --justlaunch",
"test.ios": "npm i && npm run tsc && npm run tslint && cd ../demo && tns build ios && tns test ios --justlaunch",
"tslint": "cd .. && tslint \"**/*.ts\" --config tslint.json --exclude \"**/node_modules/**\" --exclude \"*demo*/platforms/**\"",
Expand All @@ -38,15 +38,18 @@
"homepage": "https://github.com/NativeScript/nativescript-geolocation",
"readmeFilename": "README.md",
"devDependencies": {
"tns-core-modules": "^5.0.0",
"tns-platform-declarations": "^5.0.0",
"typescript": "~3.1.6",
"@nativescript/core": "rc",
"@nativescript/types": "rc",
"@nativescript/webpack": "~2.1.3",
"typescript": "~3.9.0",
"prompt": "~1.0.0",
"rimraf": "~2.6.2",
"tslint": "~5.11.0"
"rimraf": "~3.0.2",
"tslint": "~6.1.3",
"ts-patch": "~1.3.0"
},
"dependencies": {
"nativescript-permissions": "~1.3.0"
"nativescript-permissions": "~1.3.0",
"ts-node": "^8.10.2"
},
"bootstrapper": "nativescript-plugin-seed"
}
5 changes: 3 additions & 2 deletions src/references.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/// <reference path="./node_modules/tns-platform-declarations/ios.d.ts" />
/// <reference path="./node_modules/tns-platform-declarations/android.d.ts" />
/// <reference path="./node_modules/@nativescript/core/global-types.d.ts" />
/// <reference path="./node_modules/@nativescript/types/ios.d.ts" />
/// <reference path="./node_modules/@nativescript/types/android.d.ts" />
14 changes: 6 additions & 8 deletions src/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"target": "es2017",
"module": "esnext",
"moduleResolution": "node",
"declaration": false,
"removeComments": true,
"preserveConstEnums": true,
Expand All @@ -20,12 +21,9 @@
"noImplicitUseStrict": false,
"noFallthroughCasesInSwitch": true,
"baseUrl": ".",
"paths": {
"*": [
"./node_modules/tns-core-modules/*",
"./node_modules/*"
]
}
"plugins": [
{ "transform": "@nativescript/webpack/transformers/ns-transform-native-classes", "type": "raw" }
]
},
"exclude": [
"node_modules",
Expand Down