forked from Blendman974/faceclaw
Add Timer, Weather apps; build out UI of music app; add wakeword action setting
This commit is contained in:
1 parent
008f2277ca
commit
5c73ba2a4d
27 files changed
+2181
-312
No files matched your search
@@ -0,0 +1,53 @@
|
||||
import { Utils } from "@nativescript/core";
|
||||
|
||||
declare const com: any;
|
||||
|
||||
export type CurrentLocation = {
|
||||
latitude: number;
|
||||
longitude: number;
|
||||
accuracyMeters: number | null;
|
||||
timestampMs: number;
|
||||
};
|
||||
|
||||
/** Resolve one current foreground location using Android's LocationManager. */
|
||||
export function getCurrentLocation(): Promise<CurrentLocation> {
|
||||
if (!global.isAndroid) {
|
||||
return Promise.reject(new Error("Weather location is only available on Android."));
|
||||
}
|
||||
const context = Utils.android.getApplicationContext();
|
||||
if (!context) {
|
||||
return Promise.reject(new Error("Android application context unavailable."));
|
||||
}
|
||||
|
||||
return new Promise<CurrentLocation>((resolve, reject) => {
|
||||
const provider = new com.faceclaw.app.FaceclawLocationProvider(context);
|
||||
let settled = false;
|
||||
const listener = new com.faceclaw.app.FaceclawLocationListener({
|
||||
onLocation: (
|
||||
latitude: number,
|
||||
longitude: number,
|
||||
accuracyMeters: number,
|
||||
timestampMs: number,
|
||||
) => {
|
||||
if (settled) return;
|
||||
settled = true;
|
||||
provider.setListener(null);
|
||||
resolve({
|
||||
latitude: Number(latitude),
|
||||
longitude: Number(longitude),
|
||||
accuracyMeters: Number(accuracyMeters) >= 0 ? Number(accuracyMeters) : null,
|
||||
timestampMs: Number(timestampMs),
|
||||
});
|
||||
},
|
||||
onError: (message: string) => {
|
||||
if (settled) return;
|
||||
settled = true;
|
||||
provider.setListener(null);
|
||||
reject(new Error(String(message)));
|
||||
},
|
||||
});
|
||||
// Retain the proxy through the Java provider until one terminal callback.
|
||||
provider.setListener(listener);
|
||||
provider.start();
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user