commit 4089338d5770ef7fd99fc962259fe973dcde53b6
parent fc2fced41cf086fb3203cd117f2195f90257d86a
Author: triesap <137732411+triesap@users.noreply.github.com>
Date: Wed, 28 Aug 2024 11:58:38 +0000
client: update iclientgeolocation, add capacitor settings api
Diffstat:
8 files changed, 59 insertions(+), 11 deletions(-)
diff --git a/client/package.json b/client/package.json
@@ -23,6 +23,7 @@
"@capacitor/status-bar": "^6.0.0",
"@radroots/capacitor-bluetooth-le": "workspace:*",
"@radroots/capacitor-date-picker": "workspace:*",
+ "@radroots/capacitor-native-settings": "workspace:*",
"@radroots/capacitor-secure-storage": "workspace:*",
"@radroots/capacitor-sqlite": "workspace:*",
"@radroots/capacitor-wifi": "workspace:*",
diff --git a/client/src/capacitor/geolocation.ts b/client/src/capacitor/geolocation.ts
@@ -1,5 +1,5 @@
import { Geolocation, type Position } from '@capacitor/geolocation';
-import type { IClientGeolocation, IClientGeolocationPosition } from '../types';
+import type { IClientGeolocation, IClientGeolocationPosition, IGeolocationErrorMessage } from '../types';
import { fmt_location_coords } from '../utils';
export class CapacitorClientGeolocation implements IClientGeolocation {
@@ -14,18 +14,31 @@ export class CapacitorClientGeolocation implements IClientGeolocation {
return pos;
}
- private async get_current_position(): Promise<IClientGeolocationPosition | undefined> {
+ private async get_current_position(): Promise<IClientGeolocationPosition | undefined | IGeolocationErrorMessage> {
try {
const position = await Geolocation.getCurrentPosition();
return this.parse_geolocation_position(position);
- } catch (e) { };
+ } catch (e) {
+ if (typeof e.errorMessage === `string` && String(e.errorMessage).includes(`The operation couldn’t be completed`)) return `permissions-required`;
+ };
}
- public async current(): Promise<IClientGeolocationPosition | undefined> {
+ public async current(opts?: {
+ request_permissions?: boolean;
+ }): Promise<IClientGeolocationPosition | undefined | IGeolocationErrorMessage> {
try {
+ const has_permissions = await Geolocation.checkPermissions();
+ console.log(JSON.stringify(has_permissions, null, 4), `has_permissions`)
+ if (opts?.request_permissions && has_permissions.location !== `granted`) {
+ const request_permissions = await Geolocation.requestPermissions({ permissions: [`location`] });
+ console.log(JSON.stringify(request_permissions, null, 4), `request_permissions`)
+ if (request_permissions.location !== `granted`) return `permissions-request-failed`;
+ }
const position = await this.get_current_position();
- if (position) return position;
- } catch (e) { };
+ return position;
+ } catch (e) {
+ console.log(`e `, e)
+ };
}
}
diff --git a/client/src/capacitor/index.ts b/client/src/capacitor/index.ts
@@ -14,6 +14,7 @@ import { CapacitorClientHttp } from "./http";
import { CapacitorClientKeystore } from "./keystore";
import { CapacitorClientNetwork } from "./network";
import { CapacitorClientPreferences } from "./preferences";
+import { CapacitorClientSettings } from "./settings";
import { CapacitorClientShare } from "./share";
import { CapacitorClientSQLite } from "./sql";
import { CapacitorClientWifi } from "./wifi";
@@ -37,6 +38,7 @@ export class ClientCapacitor implements IClient {
private _ble: IClientBluetoothLe = new CapacitorClientBluetoothLe();
private _camera: IClientCamera = new CapacitorClientCamera();
private _db: CapacitorClientSQLite = new CapacitorClientSQLite();
+ private _settings: CapacitorClientSettings = new CapacitorClientSettings();
public get platform() {
return this._platform;
@@ -105,4 +107,8 @@ export class ClientCapacitor implements IClient {
public get db() {
return this._db;
}
+
+ public get settings() {
+ return this._settings;
+ }
};
\ No newline at end of file
diff --git a/client/src/capacitor/settings.ts b/client/src/capacitor/settings.ts
@@ -0,0 +1,17 @@
+import { AndroidSettings, IOSSettings, NativeSettings } from '@radroots/capacitor-native-settings';
+import type { IClientSettings, } from '../types';
+
+export class CapacitorClientSettings implements IClientSettings {
+ public async open(): Promise<boolean> {
+ try {
+ const res = await NativeSettings.open({
+ optionAndroid: AndroidSettings.ApplicationDetails,
+ optionIOS: IOSSettings.App
+ });
+ if (typeof res.status === `boolean`) return res.status;
+ else return false;
+ } catch (e) {
+ return false;
+ };
+ };
+}
diff --git a/client/src/capacitor/sql.ts b/client/src/capacitor/sql.ts
@@ -2,7 +2,6 @@ import { Capacitor } from '@capacitor/core';
import { CapacitorSQLite, SQLiteConnection, SQLiteDBConnection, type DBSQLiteValues, type capSQLiteChanges, type capSQLiteUpgradeOptions, type capSQLiteVersionUpgrade } from '@radroots/capacitor-sqlite';
import { LocationGcsSchema, location_gcs_sort, models_initial_upgrade, parse_location_gcs_form_field_types, parse_location_gcss, type ILocationGcsGet, type ILocationGcsGetList, type ILocationGcsQueryBindValues, type ILocationGcsQueryBindValuesTuple, type ILocationGcsUpdate, type IModelsQueryBindValueOpt, type IModelsQueryBindValueTuple, type IModelsQueryParam, type LocationGcs, type LocationGcsFields, type LocationGcsFormFields } from "@radroots/models";
import { err_msg, time_created_on, uuidv4 } from '@radroots/utils';
-//import { IClientSQLite } from '../types';
const models_upgrades = [
{
@@ -270,6 +269,7 @@ export class CapacitorClientSQLite {
];
for (const field of this.filter_bind_value_fields(fields)) bind_values_tup.push(field);
const bind_values = bind_values_tup.map(([_, v]) => v);
+ console.log(JSON.stringify(bind_values, null, 4), `bind_values`)
const query = `INSERT INTO location_gcs (${bind_values_tup.map(([k]) => k).join(", ")}) VALUES (${bind_values_tup.map((_, num) => `$${1 + num}`).join(", ")});`;
try {
const result = await this.execute(query, bind_values);
diff --git a/client/src/index.ts b/client/src/index.ts
@@ -1,4 +1,5 @@
-export * from "./capacitor"
-export * from "./types"
+export * from "@radroots/models";
+export * from "./capacitor";
+export * from "./types";
diff --git a/client/src/types.ts b/client/src/types.ts
@@ -19,6 +19,7 @@ export type IClient = {
http: IClientHttp;
window: IClientWindow;
ble: IClientBluetoothLe;
+ settings: IClientSettings;
};
export type IClientPlatform = `androiď` | `ios` | `web`;
@@ -130,8 +131,12 @@ export type IClientGeolocationPosition = {
altitude_accuracy: number | undefined;
};
+export type IGeolocationErrorMessage = `permissions-required` | `permissions-request-failed`;
+
export type IClientGeolocation = {
- current(): Promise<IClientGeolocationPosition | undefined>;
+ current(opts?: {
+ request_permissions?: boolean;
+ }): Promise<IClientGeolocationPosition | undefined | IGeolocationErrorMessage>
};
export type IClientHttpOpts = {
@@ -228,4 +233,8 @@ export type OsPhotoGallery = {
export type OsPhotosPermissions = {
camera: string;
photos: string;
+};
+
+export type IClientSettings = {
+ open(): Promise<boolean>;
};
\ No newline at end of file
diff --git a/client/tsconfig.json b/client/tsconfig.json
@@ -8,7 +8,8 @@
"module": "CommonJS",
"outDir": "./dist",
"rootDir": "./src",
- "noEmit": true
+ "noEmit": true,
+ "esModuleInterop": true,
},
"include": [
"src", "src/capacitor/camera.ts",