Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RMET-3900 :: bridge :: add getCurrentPosition wrapper for both capacitor and cordova #1

Merged
merged 20 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
2a99be8
feat: add wrapper as a package
OS-martacarlos Dec 19, 2024
1fa586f
refactor: avoid similar types
OS-martacarlos Dec 20, 2024
02e5c0a
feat(capacitor): add pwa getCurrentPosition
OS-martacarlos Dec 20, 2024
3988616
refactor(wrapper): adds UUIDs to wrapper
OS-martacarlos Dec 20, 2024
8340740
feat(capacitor): add pwa code
OS-martacarlos Dec 20, 2024
c02588c
fix: use plugin.xml as standard file, not link
alexgerardojacinto Dec 23, 2024
4fda383
fix: remove files that do not exist (yet)
alexgerardojacinto Dec 23, 2024
351b570
fix: fixing function name for `watchPosition` and `id field for clear…
alexgerardojacinto Dec 23, 2024
a1490e8
fix: convert position result for watchPosition like we do for getCurr…
alexgerardojacinto Dec 26, 2024
b39abe4
fix: include `watchId` in the parameters for `watchPosition in the co…
alexgerardojacinto Dec 26, 2024
a5eef58
chore: update README.md file
alexgerardojacinto Dec 27, 2024
02f470b
chore: fix typo in iOS library name
alexgerardojacinto Dec 27, 2024
86294d7
chore(cordova-plugin): update dist
OS-ricardomoreirasilva Dec 30, 2024
a0452bf
chore(js): create WatchPositionOptions structure
OS-ricardomoreirasilva Jan 2, 2025
283c740
chore: add success and error callbacks to clearWatch in outsystems-wr…
alexgerardojacinto Jan 3, 2025
be9b246
fix: add missing callbacks when calling clearWatch
alexgerardojacinto Jan 3, 2025
54a138c
fix: correctly pass options to clearWatch
alexgerardojacinto Jan 3, 2025
6ee6dc8
fix: correctly pass watchId to clearWatch
alexgerardojacinto Jan 3, 2025
741d72a
fix: correctly pass watchId to clearWatch
alexgerardojacinto Jan 3, 2025
2fcd073
fix: typos and remove unnecessary callback
OS-martacarlos Jan 6, 2025
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
3 changes: 1 addition & 2 deletions packages/android-lib/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.outsystems.plugins.osgeolocation">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
</manifest>
20 changes: 18 additions & 2 deletions packages/capacitor-plugin/src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,25 @@ import { WebPlugin } from '@capacitor/core';
import type { CallbackID, ClearWatchOptions, GeolocationPluginPermissions, IGeolocationPlugin, PermissionStatus, Position, PositionOptions, WatchPositionCallback } from './definitions';

export class GeolocationPluginWeb extends WebPlugin implements IGeolocationPlugin {
getCurrentPosition(options?: PositionOptions): Promise<Position> {
throw new Error('Method not implemented.');
async getCurrentPosition(options?: PositionOptions): Promise<Position> {
return new Promise((resolve, reject) => {
navigator.geolocation.getCurrentPosition(
pos => {
resolve(pos);
},
err => {
reject(err);
},
{
enableHighAccuracy: false,
timeout: 10000,
maximumAge: 0,
...options,
OS-pedrogustavobilro marked this conversation as resolved.
Show resolved Hide resolved
},
);
});
}

watchPosition(options: PositionOptions, callback: WatchPositionCallback): Promise<CallbackID> {
throw new Error('Method not implemented.');
}
Expand Down
3 changes: 1 addition & 2 deletions packages/cordova-plugin/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@ node_modules/

# Generated by Cordova
/plugins/
/platforms/
dist/
/platforms/
4 changes: 4 additions & 0 deletions packages/cordova-plugin/dist/defaults.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { ClearWatchOptions, PositionOptions } from './definitions';

export declare const PositionOptionsDefault: PositionOptions;
export declare const ClearWatchOptionsDefault: ClearWatchOptions;
130 changes: 130 additions & 0 deletions packages/cordova-plugin/dist/definitions.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
export type PluginError = {
code: string;
message: string;
};
export type OSGLOCPosition = {
timestamp: number;
latitude: number;
longitude: number;
accuracy: number;
altitude: number | null;
speed: number | null;
heading: number | null;
altitudeAccuracy: number | null;
};
export type LegacyOSPosition = {
timestamp: number;
latitude: number;
longitude: number;
accuracy: number;
altitudeAccuracy: number | null | undefined;
altitude: number | null;
velocity: number | null;
heading: number | null;
};
OS-ricardomoreirasilva marked this conversation as resolved.
Show resolved Hide resolved
export type PositionOptions = {
/**
* High accuracy mode (such as GPS, if available)
*
* On Android 12+ devices it will be ignored if users didn't grant
* ACCESS_FINE_LOCATION permissions (can be checked with location alias).
*
* @default false
* @since 1.0.0
*/
enableHighAccuracy?: boolean;
/**
* The maximum wait time in milliseconds for location updates.
*
* In Android, since version 4.0.0 of the plugin, timeout gets ignored for getCurrentPosition.
*
* @default 10000
* @since 1.0.0
*/
timeout?: number;
/**
* The maximum age in milliseconds of a possible cached position that is acceptable to return
*
* @default 0
* @since 1.0.0
*/
maximumAge?: number;
/**
* The minumum update interval for location updates.
*
* If location updates are available faster than this interval then an update
* will only occur if the minimum update interval has expired since the last location update.
*
* This parameter is only available for Android. It has no effect on iOS or Web platforms.
*
* @default 5000
* @since 6.1.0
*/
minimumUpdateInterval?: number;
/**
* @deprecate since 1.0.0
* */
id?: ReturnType<typeof setTimeout>;
};
export type ClearWatchOptions = {
id: string;
};
export type Position = {
/**
* Creation timestamp for coords
*
* @since 1.0.0
*/
timestamp: number;
/**
* The GPS coordinates along with the accuracy of the data
*
* @since 1.0.0
*/
coords: {
/**
* Latitude in decimal degrees
*
* @since 1.0.0
*/
latitude: number;
/**
* longitude in decimal degrees
*
* @since 1.0.0
*/
longitude: number;
/**
* Accuracy level of the latitude and longitude coordinates in meters
*
* @since 1.0.0
*/
accuracy: number;
/**
* Accuracy level of the altitude coordinate in meters, if available.
*
* Available on all iOS versions and on Android 8.0+.
*
* @since 1.0.0
*/
altitudeAccuracy: number | null | undefined;
/**
* The altitude the user is at (if available)
*
* @since 1.0.0
*/
altitude: number | null;
/**
* The speed the user is traveling (if available)
*
* @since 1.0.0
*/
speed: number | null;
/**
* The heading the user is facing (if available)
*
* @since 1.0.0
*/
heading: number | null;
};
};
2 changes: 2 additions & 0 deletions packages/cordova-plugin/dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './web';
export * from './definitions';
90 changes: 90 additions & 0 deletions packages/cordova-plugin/dist/plugin.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
"use strict";
const cordova = require("cordova");
function s(t) {
t.CapacitorUtils.Synapse = new Proxy(
{},
{
get(e, o) {
return new Proxy({}, {
get(w, r) {
return (c, p, n) => {
const i = t.Capacitor.Plugins[o];
if (i === void 0) {
n(new Error(`Capacitor plugin ${o} not found`));
return;
}
if (typeof i[r] != "function") {
n(new Error(`Method ${r} not found in Capacitor plugin ${o}`));
return;
}
(async () => {
try {
const a = await i[r](c);
p(a);
} catch (a) {
n(a);
}
})();
};
}
});
}
}
);
}
function u(t) {
t.CapacitorUtils.Synapse = new Proxy(
{},
{
get(e, o) {
return t.cordova.plugins[o];
}
}
);
}
function y() {
window.CapacitorUtils = window.CapacitorUtils || {}, window.Capacitor !== void 0 ? s(window) : window.cordova !== void 0 && u(window);
}
const PositionOptionsDefault = {
enableHighAccuracy: false,
timeout: 1e3,
maximumAge: 0,
minimumUpdateInterval: 5e3
};
const ClearWatchOptionsDefault = {
id: "-1"
};
var exec = cordova.require("cordova/exec");
function getCurrentPosition(options, success, error) {
options = { ...PositionOptionsDefault, ...options };
let convertOnSuccess = (position) => {
let convertedPosition = {
coords: {
latitude: position.latitude,
longitude: position.longitude,
altitude: position.altitude,
accuracy: position.accuracy,
heading: position.heading,
speed: position.speed,
altitudeAccuracy: position.accuracy
},
timestamp: position.timestamp
};
success(convertedPosition);
};
exec(convertOnSuccess, error, "OSGeolocation", "getCurrentPosition", [options]);
}
function watchPosition(options, success, error) {
options = options || PositionOptionsDefault;
exec(success, error, "OSGeolocation", "watchPosition", [options]);
}
function clearWatch(options, success, error) {
options = options || ClearWatchOptionsDefault;
exec(success, error, "OSGeolocation", "clearWatch", [options]);
}
module.exports = {
getCurrentPosition,
watchPosition,
clearWatch
};
y();
93 changes: 93 additions & 0 deletions packages/cordova-plugin/dist/plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
(function(global, factory) {
typeof exports === "object" && typeof module !== "undefined" ? factory(require("cordova")) : typeof define === "function" && define.amd ? define(["cordova"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.cordova));
})(this, function(cordova) {
"use strict";
function s(t) {
t.CapacitorUtils.Synapse = new Proxy(
{},
{
get(e, o) {
return new Proxy({}, {
get(w, r) {
return (c, p, n) => {
const i = t.Capacitor.Plugins[o];
if (i === void 0) {
n(new Error(`Capacitor plugin ${o} not found`));
return;
}
if (typeof i[r] != "function") {
n(new Error(`Method ${r} not found in Capacitor plugin ${o}`));
return;
}
(async () => {
try {
const a = await i[r](c);
p(a);
} catch (a) {
n(a);
}
})();
};
}
});
}
}
);
}
function u(t) {
t.CapacitorUtils.Synapse = new Proxy(
{},
{
get(e, o) {
return t.cordova.plugins[o];
}
}
);
}
function y() {
window.CapacitorUtils = window.CapacitorUtils || {}, window.Capacitor !== void 0 ? s(window) : window.cordova !== void 0 && u(window);
}
const PositionOptionsDefault = {
enableHighAccuracy: false,
timeout: 1e3,
maximumAge: 0,
minimumUpdateInterval: 5e3
};
const ClearWatchOptionsDefault = {
id: "-1"
};
var exec = cordova.require("cordova/exec");
function getCurrentPosition(options, success, error) {
options = { ...PositionOptionsDefault, ...options };
let convertOnSuccess = (position) => {
let convertedPosition = {
coords: {
latitude: position.latitude,
longitude: position.longitude,
altitude: position.altitude,
accuracy: position.accuracy,
heading: position.heading,
speed: position.speed,
altitudeAccuracy: position.accuracy
},
timestamp: position.timestamp
};
success(convertedPosition);
};
exec(convertOnSuccess, error, "OSGeolocation", "getCurrentPosition", [options]);
}
function watchPosition(options, success, error) {
options = options || PositionOptionsDefault;
exec(success, error, "OSGeolocation", "watchPosition", [options]);
}
function clearWatch(options, success, error) {
options = options || ClearWatchOptionsDefault;
exec(success, error, "OSGeolocation", "clearWatch", [options]);
}
module.exports = {
getCurrentPosition,
watchPosition,
clearWatch
};
y();
});
Loading