nativescript-accelerometer
Advanced tools
Comparing version 2.0.1 to 3.0.0
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var application = require("application"); | ||
var utils_1 = require("tns-core-modules/utils/utils"); | ||
var messages_1 = require("./messages"); | ||
var baseAcceleration = -9.81; | ||
@@ -23,12 +24,13 @@ var sensorListener; | ||
function startAccelerometerUpdates(callback, options) { | ||
if (sensorListener) { | ||
throw new Error("Already listening for accelerometer updates."); | ||
if (isListening()) { | ||
console.log(messages_1.startButNotStopped); | ||
stopAccelerometerUpdates(); | ||
} | ||
var wrappedCallback = zonedCallback(callback); | ||
var activity = application.android.foregroundActivity; | ||
if (!activity) { | ||
throw Error("Could not get foregroundActivity."); | ||
var context = utils_1.ad.getApplicationContext(); | ||
if (!context) { | ||
throw Error("Could not get Android application context."); | ||
} | ||
if (!sensorManager) { | ||
sensorManager = activity.getSystemService(android.content.Context.SENSOR_SERVICE); | ||
sensorManager = context.getSystemService(android.content.Context.SENSOR_SERVICE); | ||
if (!sensorManager) { | ||
@@ -60,8 +62,14 @@ throw Error("Could not initialize SensorManager."); | ||
function stopAccelerometerUpdates() { | ||
if (!sensorListener) { | ||
throw new Error("Currently not listening for acceleration events."); | ||
if (sensorListener) { | ||
sensorManager.unregisterListener(sensorListener); | ||
sensorListener = undefined; | ||
} | ||
sensorManager.unregisterListener(sensorListener); | ||
sensorListener = undefined; | ||
else { | ||
console.log(messages_1.stopButNotStarted); | ||
} | ||
} | ||
exports.stopAccelerometerUpdates = stopAccelerometerUpdates; | ||
function isListening() { | ||
return !!sensorListener; | ||
} | ||
exports.isListening = isListening; |
@@ -12,3 +12,4 @@ export interface AccelerometerData { | ||
export function startAccelerometerUpdates(callback: (AccelerometerData) => void, options?: AccelerometerOptions); | ||
export function stopAccelerometerUpdates(); | ||
export function startAccelerometerUpdates(callback: (data: AccelerometerData) => void, options?: AccelerometerOptions): void; | ||
export function stopAccelerometerUpdates(): void; | ||
export function isListening(): boolean; |
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var messages_1 = require("./messages"); | ||
var accManager; | ||
var isListening = false; | ||
var isListeningForUpdates = false; | ||
var main_queue = dispatch_get_current_queue(); | ||
@@ -21,4 +22,5 @@ function getNativeDelay(options) { | ||
function startAccelerometerUpdates(callback, options) { | ||
if (isListening) { | ||
throw new Error("Already listening for accelerometer updates."); | ||
if (isListeningForUpdates) { | ||
console.log(messages_1.startButNotStopped); | ||
stopAccelerometerUpdates(); | ||
} | ||
@@ -41,3 +43,3 @@ var wrappedCallback = zonedCallback(callback); | ||
}); | ||
isListening = true; | ||
isListeningForUpdates = true; | ||
} | ||
@@ -50,8 +52,14 @@ else { | ||
function stopAccelerometerUpdates() { | ||
if (!isListening) { | ||
throw new Error("Currently not listening for acceleration events."); | ||
if (isListeningForUpdates) { | ||
accManager.stopAccelerometerUpdates(); | ||
isListeningForUpdates = false; | ||
} | ||
accManager.stopAccelerometerUpdates(); | ||
isListening = false; | ||
else { | ||
console.log(messages_1.stopButNotStarted); | ||
} | ||
} | ||
exports.stopAccelerometerUpdates = stopAccelerometerUpdates; | ||
function isListening() { | ||
return isListeningForUpdates; | ||
} | ||
exports.isListening = isListening; |
{ | ||
"name": "nativescript-accelerometer", | ||
"version": "2.0.1", | ||
"version": "3.0.0", | ||
"description": "NativeScript accelerometer plugin.", | ||
"main": "index.js", | ||
"typings": "index.d.ts", | ||
"scripts": { | ||
"prepublish": "tsc" | ||
}, | ||
"repository": { | ||
@@ -44,6 +41,22 @@ "type": "git", | ||
"devDependencies": { | ||
"conventional-changelog-cli": "^2.0.25", | ||
"tns-core-modules": ">2.0.0", | ||
"tns-platform-declarations": ">2.0.0", | ||
"typescript": ">2.0.6" | ||
"typescript": "~3.6.4" | ||
}, | ||
"scripts": { | ||
"tsc": "npm i && tsc", | ||
"build": "npm run tsc && npm run build.native", | ||
"tslint": "cd .. && tslint \"**/*.ts\" --config tslint.json --exclude \"**/node_modules/**\"", | ||
"ci.tslint": "npm i && tslint '**/*.ts' --config '../tslint.json' --exclude '**/node_modules/**' --exclude '**/platforms/**'", | ||
"demo.ios": "cd ../demo && tns run ios", | ||
"demo.android": "cd ../demo && tns run android", | ||
"demo.reset": "cd ../demo && npx rimraf -- hooks node_modules platforms package-lock.json", | ||
"demo-angular.ios": "cd ../demo-angular && tns run ios", | ||
"demo-angular.android": "cd ../demo-angular && tns run android", | ||
"demo-angular.reset": "cd ../demo-angular && npx rimraf -- hooks node_modules platforms package-lock.json", | ||
"plugin.prepare": "npm run build && cd ../demo && tns plugin remove nativescript-accelerometer && tns plugin add ../src && cd ../demo-angular && tns plugin remove nativescript-accelerometer && tns plugin add ../src", | ||
"clean": "npm run demo.reset && npm run demo-angular.reset && npx rimraf -- node_modules package-lock.json && npm i", | ||
"version": "conventional-changelog -p angular -i ../CHANGELOG.md -s && git add ../CHANGELOG.md" | ||
} | ||
} |
9883
4
7
149