@tauri-apps/plugin-geolocation 2.0.0-rc.0 → 2.0.0-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -87,16 +87,31 @@ fn main() {
87
87
  Afterwards all the plugin's APIs are available through the JavaScript guest bindings:
88
88
 
89
89
  ```javascript
90
- import { getCurrentPosition, watchPosition } from "@tauri-apps/plugin-log";
90
+ import {
91
+ checkPermissions,
92
+ requestPermissions,
93
+ getCurrentPosition,
94
+ watchPosition
95
+ } from '@tauri-apps/plugin-log'
96
+
97
+ let permissions = await checkPermissions()
98
+ if (
99
+ permissions.location === 'prompt' ||
100
+ permissions.location === 'prompt-with-rationale'
101
+ ) {
102
+ permissions = await requestPermissions(['location'])
103
+ }
91
104
 
92
- const pos = await getCurrentPosition();
105
+ if (permissions.location === 'granted') {
106
+ const pos = await getCurrentPosition()
93
107
 
94
- await watchPosition(
95
- { enableHighAccuracy: true, timeout: 10000, maximumAge: 0 },
96
- (pos) => {
97
- console.log(pos);
98
- }
99
- );
108
+ await watchPosition(
109
+ { enableHighAccuracy: true, timeout: 10000, maximumAge: 0 },
110
+ (pos) => {
111
+ console.log(pos)
112
+ }
113
+ )
114
+ }
100
115
  ```
101
116
 
102
117
  ## Contributing
package/dist-js/index.cjs CHANGED
@@ -1,110 +1,44 @@
1
1
  'use strict';
2
2
 
3
3
  var core = require('@tauri-apps/api/core');
4
- require('@tauri-apps/api/event');
5
4
 
6
5
  // Copyright 2019-2023 Tauri Programme within The Commons Conservancy
7
6
  // SPDX-License-Identifier: Apache-2.0
8
7
  // SPDX-License-Identifier: MIT
9
- // @ts-nocheck
10
- // This file was generated by [tauri-specta](https://github.com/oscartbeaumont/tauri-specta). Do not edit this file manually.
11
- /** user-defined commands **/
12
- const commands = {
13
- async getCurrentPosition(options) {
14
- try {
15
- return {
16
- status: "ok",
17
- data: await core.invoke("plugin:geolocation|get_current_position", {
18
- options,
19
- }),
20
- };
21
- }
22
- catch (e) {
23
- if (e instanceof Error)
24
- throw e;
25
- else
26
- return { status: "error", error: e };
27
- }
28
- },
29
- async watchPosition(options, channel) {
30
- try {
31
- return {
32
- status: "ok",
33
- data: await core.invoke("plugin:geolocation|watch_position", {
34
- options,
35
- channel,
36
- }),
37
- };
38
- }
39
- catch (e) {
40
- if (e instanceof Error)
41
- throw e;
42
- else
43
- return { status: "error", error: e };
44
- }
45
- },
46
- async clearWatch(channelId) {
47
- try {
48
- return {
49
- status: "ok",
50
- data: await core.invoke("plugin:geolocation|clear_watch", {
51
- channelId,
52
- }),
53
- };
54
- }
55
- catch (e) {
56
- if (e instanceof Error)
57
- throw e;
58
- else
59
- return { status: "error", error: e };
60
- }
61
- },
62
- async checkPermissions() {
63
- try {
64
- return {
65
- status: "ok",
66
- data: await core.invoke("plugin:geolocation|check_permissions"),
67
- };
68
- }
69
- catch (e) {
70
- if (e instanceof Error)
71
- throw e;
72
- else
73
- return { status: "error", error: e };
74
- }
75
- },
76
- async requestPermissions(permissions) {
77
- try {
78
- return {
79
- status: "ok",
80
- data: await core.invoke("plugin:geolocation|request_permissions", {
81
- permissions,
82
- }),
83
- };
84
- }
85
- catch (e) {
86
- if (e instanceof Error)
87
- throw e;
88
- else
89
- return { status: "error", error: e };
90
- }
91
- },
92
- };
93
-
94
- // Copyright 2019-2023 Tauri Programme within The Commons Conservancy
95
- // SPDX-License-Identifier: Apache-2.0
96
- // SPDX-License-Identifier: MIT
97
- /* eslint-disable @typescript-eslint/unbound-method */
98
- async function watchPosition(options,
99
- // TODO: This can receive errors too
100
- cb) {
8
+ async function watchPosition(options, cb) {
101
9
  const channel = new core.Channel();
102
- channel.onmessage = cb;
103
- await commands.watchPosition(options, channel);
10
+ channel.onmessage = (message) => {
11
+ if (typeof message === 'string') {
12
+ cb(null, message);
13
+ }
14
+ else {
15
+ cb(message);
16
+ }
17
+ };
18
+ await core.invoke('plugin:geolocation|watch_position', {
19
+ options,
20
+ channel
21
+ });
104
22
  return channel.id;
105
23
  }
106
- const { getCurrentPosition, clearWatch, checkPermissions, requestPermissions, } = commands;
107
- // export { events };
24
+ async function getCurrentPosition(options) {
25
+ return await core.invoke('plugin:geolocation|get_current_position', {
26
+ options
27
+ });
28
+ }
29
+ async function clearWatch(channelId) {
30
+ await core.invoke('plugin:geolocation|clear_watch', {
31
+ channelId
32
+ });
33
+ }
34
+ async function checkPermissions() {
35
+ return await core.checkPermissions('geolocation');
36
+ }
37
+ async function requestPermissions(permissions) {
38
+ return await core.invoke('plugin:geolocation|request_permissions', {
39
+ permissions
40
+ });
41
+ }
108
42
 
109
43
  exports.checkPermissions = checkPermissions;
110
44
  exports.clearWatch = clearWatch;
@@ -1,4 +1,84 @@
1
- import { type PositionOptions, type Position } from "./bindings";
2
- export declare function watchPosition(options: PositionOptions, cb: (location: Position | string) => void): Promise<number>;
3
- export declare const getCurrentPosition: (options: PositionOptions | null) => Promise<import("./bindings").Result<Position, import("./bindings").Error>>, clearWatch: (channelId: number) => Promise<import("./bindings").Result<null, import("./bindings").Error>>, checkPermissions: () => Promise<import("./bindings").Result<import("./bindings").PermissionStatus, import("./bindings").Error>>, requestPermissions: (permissions: import("./bindings").PermissionType[] | null) => Promise<import("./bindings").Result<import("./bindings").PermissionStatus, import("./bindings").Error>>;
4
- export type { PermissionState, PermissionStatus, PermissionType, Position, PositionOptions, Coordinates, } from "./bindings";
1
+ import { PermissionState } from '@tauri-apps/api/core';
2
+ export type Coordinates = {
3
+ /**
4
+ * Latitude in decimal degrees.
5
+ */
6
+ latitude: number;
7
+ /**
8
+ * Longitude in decimal degrees.
9
+ */
10
+ longitude: number;
11
+ /**
12
+ * Accuracy level of the latitude and longitude coordinates in meters.
13
+ */
14
+ accuracy: number;
15
+ /**
16
+ * Accuracy level of the altitude coordinate in meters, if available.
17
+ * Available on all iOS versions and on Android 8 and above.
18
+ */
19
+ altitudeAccuracy: number | null;
20
+ /**
21
+ * The altitude the user is at, if available.
22
+ */
23
+ altitude: number | null;
24
+ speed: number | null;
25
+ /**
26
+ * The heading the user is facing, if available.
27
+ */
28
+ heading: number | null;
29
+ };
30
+ export type PermissionStatus = {
31
+ /**
32
+ * Permission state for the location alias.
33
+ *
34
+ * On Android it requests/checks both ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION permissions.
35
+ *
36
+ * On iOS it requests/checks location permissions.
37
+ */
38
+ location: PermissionState;
39
+ /**
40
+ * Permissions state for the coarseLoaction alias.
41
+ *
42
+ * On Android it requests/checks ACCESS_COARSE_LOCATION.
43
+ *
44
+ * On Android 12+, users can choose between Approximate location (ACCESS_COARSE_LOCATION) and Precise location (ACCESS_FINE_LOCATION).
45
+ *
46
+ * On iOS it will have the same value as the `location` alias.
47
+ */
48
+ coarseLocation: PermissionState;
49
+ };
50
+ export type PermissionType = 'location' | 'coarseLocation';
51
+ export type Position = {
52
+ /**
53
+ * Creation time for these coordinates.
54
+ */
55
+ timestamp: number;
56
+ /**
57
+ * The GPD coordinates along with the accuracy of the data.
58
+ */
59
+ coords: Coordinates;
60
+ };
61
+ export type PositionOptions = {
62
+ /**
63
+ * High accuracy mode (such as GPS, if available)
64
+ * Will be ignored on Android 12+ if users didn't grant the ACCESS_FINE_LOCATION permission (`coarseLocation` permission).
65
+ */
66
+ enableHighAccuracy: boolean;
67
+ /**
68
+ * The maximum wait time in milliseconds for location updates.
69
+ * On Android the timeout gets ignored for getCurrentPosition.
70
+ * Ignored on iOS
71
+ */
72
+ timeout: number;
73
+ /**
74
+ * The maximum age in milliseconds of a possible cached position that is acceptable to return.
75
+ * Default: 0
76
+ * Ignored on iOS
77
+ */
78
+ maximumAge: number;
79
+ };
80
+ export declare function watchPosition(options: PositionOptions, cb: (location: Position | null, error?: string) => void): Promise<number>;
81
+ export declare function getCurrentPosition(options?: PositionOptions): Promise<Position>;
82
+ export declare function clearWatch(channelId: number): Promise<void>;
83
+ export declare function checkPermissions(): Promise<PermissionStatus>;
84
+ export declare function requestPermissions(permissions: PermissionType[] | null): Promise<PermissionStatus>;
package/dist-js/index.js CHANGED
@@ -1,107 +1,41 @@
1
- import { invoke, Channel } from '@tauri-apps/api/core';
2
- import '@tauri-apps/api/event';
1
+ import { Channel, invoke, checkPermissions as checkPermissions$1 } from '@tauri-apps/api/core';
3
2
 
4
3
  // Copyright 2019-2023 Tauri Programme within The Commons Conservancy
5
4
  // SPDX-License-Identifier: Apache-2.0
6
5
  // SPDX-License-Identifier: MIT
7
- // @ts-nocheck
8
- // This file was generated by [tauri-specta](https://github.com/oscartbeaumont/tauri-specta). Do not edit this file manually.
9
- /** user-defined commands **/
10
- const commands = {
11
- async getCurrentPosition(options) {
12
- try {
13
- return {
14
- status: "ok",
15
- data: await invoke("plugin:geolocation|get_current_position", {
16
- options,
17
- }),
18
- };
19
- }
20
- catch (e) {
21
- if (e instanceof Error)
22
- throw e;
23
- else
24
- return { status: "error", error: e };
25
- }
26
- },
27
- async watchPosition(options, channel) {
28
- try {
29
- return {
30
- status: "ok",
31
- data: await invoke("plugin:geolocation|watch_position", {
32
- options,
33
- channel,
34
- }),
35
- };
36
- }
37
- catch (e) {
38
- if (e instanceof Error)
39
- throw e;
40
- else
41
- return { status: "error", error: e };
42
- }
43
- },
44
- async clearWatch(channelId) {
45
- try {
46
- return {
47
- status: "ok",
48
- data: await invoke("plugin:geolocation|clear_watch", {
49
- channelId,
50
- }),
51
- };
52
- }
53
- catch (e) {
54
- if (e instanceof Error)
55
- throw e;
56
- else
57
- return { status: "error", error: e };
58
- }
59
- },
60
- async checkPermissions() {
61
- try {
62
- return {
63
- status: "ok",
64
- data: await invoke("plugin:geolocation|check_permissions"),
65
- };
66
- }
67
- catch (e) {
68
- if (e instanceof Error)
69
- throw e;
70
- else
71
- return { status: "error", error: e };
72
- }
73
- },
74
- async requestPermissions(permissions) {
75
- try {
76
- return {
77
- status: "ok",
78
- data: await invoke("plugin:geolocation|request_permissions", {
79
- permissions,
80
- }),
81
- };
82
- }
83
- catch (e) {
84
- if (e instanceof Error)
85
- throw e;
86
- else
87
- return { status: "error", error: e };
88
- }
89
- },
90
- };
91
-
92
- // Copyright 2019-2023 Tauri Programme within The Commons Conservancy
93
- // SPDX-License-Identifier: Apache-2.0
94
- // SPDX-License-Identifier: MIT
95
- /* eslint-disable @typescript-eslint/unbound-method */
96
- async function watchPosition(options,
97
- // TODO: This can receive errors too
98
- cb) {
6
+ async function watchPosition(options, cb) {
99
7
  const channel = new Channel();
100
- channel.onmessage = cb;
101
- await commands.watchPosition(options, channel);
8
+ channel.onmessage = (message) => {
9
+ if (typeof message === 'string') {
10
+ cb(null, message);
11
+ }
12
+ else {
13
+ cb(message);
14
+ }
15
+ };
16
+ await invoke('plugin:geolocation|watch_position', {
17
+ options,
18
+ channel
19
+ });
102
20
  return channel.id;
103
21
  }
104
- const { getCurrentPosition, clearWatch, checkPermissions, requestPermissions, } = commands;
105
- // export { events };
22
+ async function getCurrentPosition(options) {
23
+ return await invoke('plugin:geolocation|get_current_position', {
24
+ options
25
+ });
26
+ }
27
+ async function clearWatch(channelId) {
28
+ await invoke('plugin:geolocation|clear_watch', {
29
+ channelId
30
+ });
31
+ }
32
+ async function checkPermissions() {
33
+ return await checkPermissions$1('geolocation');
34
+ }
35
+ async function requestPermissions(permissions) {
36
+ return await invoke('plugin:geolocation|request_permissions', {
37
+ permissions
38
+ });
39
+ }
106
40
 
107
41
  export { checkPermissions, clearWatch, getCurrentPosition, requestPermissions, watchPosition };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tauri-apps/plugin-geolocation",
3
- "version": "2.0.0-rc.0",
3
+ "version": "2.0.0-rc.2",
4
4
  "license": "MIT or APACHE-2.0",
5
5
  "authors": [
6
6
  "Tauri Programme within The Commons Conservancy"
@@ -24,6 +24,6 @@
24
24
  "LICENSE"
25
25
  ],
26
26
  "dependencies": {
27
- "@tauri-apps/api": "^2.0.0-rc.0"
27
+ "@tauri-apps/api": "^2.0.0-rc.4"
28
28
  }
29
29
  }
@@ -1,113 +0,0 @@
1
- /** user-defined commands **/
2
- export declare const commands: {
3
- getCurrentPosition(options: PositionOptions | null): Promise<Result<Position, Error>>;
4
- watchPosition(options: PositionOptions, channel: any): Promise<Result<null, Error>>;
5
- clearWatch(channelId: number): Promise<Result<null, Error>>;
6
- checkPermissions(): Promise<Result<PermissionStatus, Error>>;
7
- requestPermissions(permissions: PermissionType[] | null): Promise<Result<PermissionStatus, Error>>;
8
- };
9
- /** user-defined events **/
10
- /** user-defined statics **/
11
- /** user-defined types **/
12
- export type Coordinates = {
13
- /**
14
- * Latitude in decimal degrees.
15
- */
16
- latitude: number;
17
- /**
18
- * Longitude in decimal degrees.
19
- */
20
- longitude: number;
21
- /**
22
- * Accuracy level of the latitude and longitude coordinates in meters.
23
- */
24
- accuracy: number;
25
- /**
26
- * Accuracy level of the altitude coordinate in meters, if available.
27
- * Available on all iOS versions and on Android 8 and above.
28
- */
29
- altitudeAccuracy: number | null;
30
- /**
31
- * The altitude the user is at, if available.
32
- */
33
- altitude: number | null;
34
- speed: number | null;
35
- /**
36
- * The heading the user is facing, if available.
37
- */
38
- heading: number | null;
39
- };
40
- export type Error = never;
41
- /**
42
- * Permission state.
43
- */
44
- export type PermissionState =
45
- /**
46
- * Permission access has been granted.
47
- */
48
- "granted"
49
- /**
50
- * Permission access has been denied.
51
- */
52
- | "denied"
53
- /**
54
- * The end user should be prompted for permission.
55
- */
56
- | "prompt";
57
- export type PermissionStatus = {
58
- /**
59
- * Permission state for the location alias.
60
- *
61
- * On Android it requests/checks both ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION permissions.
62
- *
63
- * On iOS it requests/checks location permissions.
64
- */
65
- location: PermissionState;
66
- /**
67
- * Permissions state for the coarseLoaction alias.
68
- *
69
- * On Android it requests/checks ACCESS_COARSE_LOCATION.
70
- *
71
- * On Android 12+, users can choose between Approximate location (ACCESS_COARSE_LOCATION) and Precise location (ACCESS_FINE_LOCATION).
72
- *
73
- * On iOS it will have the same value as the `location` alias.
74
- */
75
- coarseLocation: PermissionState;
76
- };
77
- export type PermissionType = "location" | "coarseLocation";
78
- export type Position = {
79
- /**
80
- * Creation time for these coordinates.
81
- */
82
- timestamp: number;
83
- /**
84
- * The GPD coordinates along with the accuracy of the data.
85
- */
86
- coords: Coordinates;
87
- };
88
- export type PositionOptions = {
89
- /**
90
- * High accuracy mode (such as GPS, if available)
91
- * Will be ignored on Android 12+ if users didn't grant the ACCESS_FINE_LOCATION permission.
92
- */
93
- enableHighAccuracy: boolean;
94
- /**
95
- * The maximum wait time in milliseconds for location updates.
96
- * On Android the timeout gets ignored for getCurrentPosition.
97
- * Ignored on iOS
98
- */
99
- timeout: number;
100
- /**
101
- * The maximum age in milliseconds of a possible cached position that is acceptable to return.
102
- * Default: 0
103
- * Ignored on iOS
104
- */
105
- maximumAge: number;
106
- };
107
- export type Result<T, E> = {
108
- status: "ok";
109
- data: T;
110
- } | {
111
- status: "error";
112
- error: E;
113
- };