@tauri-apps/plugin-geolocation 2.0.0-rc.0
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/LICENSE.spdx +20 -0
- package/README.md +145 -0
- package/dist-js/bindings.d.ts +113 -0
- package/dist-js/index.cjs +113 -0
- package/dist-js/index.d.ts +4 -0
- package/dist-js/index.js +107 -0
- package/package.json +29 -0
package/LICENSE.spdx
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
SPDXVersion: SPDX-2.1
|
|
2
|
+
DataLicense: CC0-1.0
|
|
3
|
+
PackageName: tauri
|
|
4
|
+
DataFormat: SPDXRef-1
|
|
5
|
+
PackageSupplier: Organization: The Tauri Programme in the Commons Conservancy
|
|
6
|
+
PackageHomePage: https://tauri.app
|
|
7
|
+
PackageLicenseDeclared: Apache-2.0
|
|
8
|
+
PackageLicenseDeclared: MIT
|
|
9
|
+
PackageCopyrightText: 2019-2022, The Tauri Programme in the Commons Conservancy
|
|
10
|
+
PackageSummary: <text>Tauri is a rust project that enables developers to make secure
|
|
11
|
+
and small desktop applications using a web frontend.
|
|
12
|
+
</text>
|
|
13
|
+
PackageComment: <text>The package includes the following libraries; see
|
|
14
|
+
Relationship information.
|
|
15
|
+
</text>
|
|
16
|
+
Created: 2019-05-20T09:00:00Z
|
|
17
|
+
PackageDownloadLocation: git://github.com/tauri-apps/tauri
|
|
18
|
+
PackageDownloadLocation: git+https://github.com/tauri-apps/tauri.git
|
|
19
|
+
PackageDownloadLocation: git+ssh://github.com/tauri-apps/tauri.git
|
|
20
|
+
Creator: Person: Daniel Thompson-Yvetot
|
package/README.md
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
This plugin provides APIs for getting and tracking the device's current position, including information about altitude, heading, and speed (if available).
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
_This plugin requires a Rust version of at least **1.75**_
|
|
8
|
+
|
|
9
|
+
There are three general methods of installation that we can recommend.
|
|
10
|
+
|
|
11
|
+
1. Use crates.io and npm (easiest, and requires you to trust that our publishing pipeline worked)
|
|
12
|
+
2. Pull sources directly from Github using git tags / revision hashes (most secure)
|
|
13
|
+
3. Git submodule install this repo in your tauri project and then use file protocol to ingest the source (most secure, but inconvenient to use)
|
|
14
|
+
|
|
15
|
+
Install the Core plugin by adding the following to your `Cargo.toml` file:
|
|
16
|
+
|
|
17
|
+
`src-tauri/Cargo.toml`
|
|
18
|
+
|
|
19
|
+
```toml
|
|
20
|
+
[dependencies]
|
|
21
|
+
tauri-plugin-geolocation = "2.0.0-rc"
|
|
22
|
+
# alternatively with Git:
|
|
23
|
+
tauri-plugin-geolocation = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
You can install the JavaScript Guest bindings using your preferred JavaScript package manager:
|
|
27
|
+
|
|
28
|
+
> Note: Since most JavaScript package managers are unable to install packages from git monorepos we provide read-only mirrors of each plugin. This makes installation option 2 more ergonomic to use.
|
|
29
|
+
|
|
30
|
+
<!-- Add the branch for installations using git! -->
|
|
31
|
+
|
|
32
|
+
```sh
|
|
33
|
+
pnpm add @tauri-apps/plugin-geolocation
|
|
34
|
+
# or
|
|
35
|
+
npm add @tauri-apps/plugin-geolocation
|
|
36
|
+
# or
|
|
37
|
+
yarn add @tauri-apps/plugin-geolocation
|
|
38
|
+
|
|
39
|
+
# alternatively with Git:
|
|
40
|
+
pnpm add https://github.com/tauri-apps/tauri-plugin-geolocation#v2
|
|
41
|
+
# or
|
|
42
|
+
npm add https://github.com/tauri-apps/tauri-plugin-geolocation#v2
|
|
43
|
+
# or
|
|
44
|
+
yarn add https://github.com/tauri-apps/tauri-plugin-geolocation#v2
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Setting up
|
|
48
|
+
|
|
49
|
+
### iOS
|
|
50
|
+
|
|
51
|
+
Apple requires privacy descriptions to be specified in `Info.plist` for location information:
|
|
52
|
+
|
|
53
|
+
- `NSLocationWhenInUseDescription`
|
|
54
|
+
|
|
55
|
+
### Android
|
|
56
|
+
|
|
57
|
+
This plugin automatically adds the following permissions to your `AndroidManifest.xml` file:
|
|
58
|
+
|
|
59
|
+
```xml
|
|
60
|
+
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
|
61
|
+
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
If your app requires GPS functionality to function, **you** should add the following to your `AndroidManifest.xml` file:
|
|
65
|
+
|
|
66
|
+
```xml
|
|
67
|
+
<uses-feature android:name="android.hardware.gps" android:required="true" />
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
The Google Play Store uses this property to decide whether it should show the app to devices without GPS capabilities.
|
|
71
|
+
|
|
72
|
+
## Usage
|
|
73
|
+
|
|
74
|
+
First you need to register the core plugin with Tauri:
|
|
75
|
+
|
|
76
|
+
`src-tauri/src/main.rs`
|
|
77
|
+
|
|
78
|
+
```rust
|
|
79
|
+
fn main() {
|
|
80
|
+
tauri::Builder::default()
|
|
81
|
+
.plugin(tauri_plugin_geolocation::init())
|
|
82
|
+
.run(tauri::generate_context!())
|
|
83
|
+
.expect("error while running tauri application");
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Afterwards all the plugin's APIs are available through the JavaScript guest bindings:
|
|
88
|
+
|
|
89
|
+
```javascript
|
|
90
|
+
import { getCurrentPosition, watchPosition } from "@tauri-apps/plugin-log";
|
|
91
|
+
|
|
92
|
+
const pos = await getCurrentPosition();
|
|
93
|
+
|
|
94
|
+
await watchPosition(
|
|
95
|
+
{ enableHighAccuracy: true, timeout: 10000, maximumAge: 0 },
|
|
96
|
+
(pos) => {
|
|
97
|
+
console.log(pos);
|
|
98
|
+
}
|
|
99
|
+
);
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Contributing
|
|
103
|
+
|
|
104
|
+
PRs accepted. Please make sure to read the Contributing Guide before making a pull request.
|
|
105
|
+
|
|
106
|
+
## Contributed By
|
|
107
|
+
|
|
108
|
+
<table>
|
|
109
|
+
<tbody>
|
|
110
|
+
<tr>
|
|
111
|
+
<td align="center" valign="middle">
|
|
112
|
+
<a href="https://crabnebula.dev" target="_blank">
|
|
113
|
+
<img src="contributors/crabnebula.svg" alt="CrabNebula" width="283">
|
|
114
|
+
</a>
|
|
115
|
+
</td>
|
|
116
|
+
<td align="center" valign="middle">
|
|
117
|
+
<a href="https://rescue.co" target="_blank">
|
|
118
|
+
<img src="contributors/rescue.png" alt="Rescue.co" width="283" height="90">
|
|
119
|
+
</a>
|
|
120
|
+
</td>
|
|
121
|
+
</tr>
|
|
122
|
+
</tbody>
|
|
123
|
+
</table>
|
|
124
|
+
|
|
125
|
+
## Partners
|
|
126
|
+
|
|
127
|
+
<table>
|
|
128
|
+
<tbody>
|
|
129
|
+
<tr>
|
|
130
|
+
<td align="center" valign="middle">
|
|
131
|
+
<a href="https://crabnebula.dev" target="_blank">
|
|
132
|
+
<img src="https://github.com/tauri-apps/plugins-workspace/raw/v2/.github/sponsors/crabnebula.svg" alt="CrabNebula" width="283">
|
|
133
|
+
</a>
|
|
134
|
+
</td>
|
|
135
|
+
</tr>
|
|
136
|
+
</tbody>
|
|
137
|
+
</table>
|
|
138
|
+
|
|
139
|
+
For the complete list of sponsors please visit our [website](https://tauri.app#sponsors) and [Open Collective](https://opencollective.com/tauri).
|
|
140
|
+
|
|
141
|
+
## License
|
|
142
|
+
|
|
143
|
+
Code: (c) 2015 - Present - The Tauri Programme within The Commons Conservancy.
|
|
144
|
+
|
|
145
|
+
MIT or MIT/Apache 2.0 where applicable.
|
|
@@ -0,0 +1,113 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@tauri-apps/api/core');
|
|
4
|
+
require('@tauri-apps/api/event');
|
|
5
|
+
|
|
6
|
+
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
|
7
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
8
|
+
// 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) {
|
|
101
|
+
const channel = new core.Channel();
|
|
102
|
+
channel.onmessage = cb;
|
|
103
|
+
await commands.watchPosition(options, channel);
|
|
104
|
+
return channel.id;
|
|
105
|
+
}
|
|
106
|
+
const { getCurrentPosition, clearWatch, checkPermissions, requestPermissions, } = commands;
|
|
107
|
+
// export { events };
|
|
108
|
+
|
|
109
|
+
exports.checkPermissions = checkPermissions;
|
|
110
|
+
exports.clearWatch = clearWatch;
|
|
111
|
+
exports.getCurrentPosition = getCurrentPosition;
|
|
112
|
+
exports.requestPermissions = requestPermissions;
|
|
113
|
+
exports.watchPosition = watchPosition;
|
|
@@ -0,0 +1,4 @@
|
|
|
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";
|
package/dist-js/index.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { invoke, Channel } from '@tauri-apps/api/core';
|
|
2
|
+
import '@tauri-apps/api/event';
|
|
3
|
+
|
|
4
|
+
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
|
5
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
6
|
+
// 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) {
|
|
99
|
+
const channel = new Channel();
|
|
100
|
+
channel.onmessage = cb;
|
|
101
|
+
await commands.watchPosition(options, channel);
|
|
102
|
+
return channel.id;
|
|
103
|
+
}
|
|
104
|
+
const { getCurrentPosition, clearWatch, checkPermissions, requestPermissions, } = commands;
|
|
105
|
+
// export { events };
|
|
106
|
+
|
|
107
|
+
export { checkPermissions, clearWatch, getCurrentPosition, requestPermissions, watchPosition };
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tauri-apps/plugin-geolocation",
|
|
3
|
+
"version": "2.0.0-rc.0",
|
|
4
|
+
"license": "MIT or APACHE-2.0",
|
|
5
|
+
"authors": [
|
|
6
|
+
"Tauri Programme within The Commons Conservancy"
|
|
7
|
+
],
|
|
8
|
+
"repository": "https://github.com/tauri-apps/plugins-workspace",
|
|
9
|
+
"type": "module",
|
|
10
|
+
"types": "./dist-js/index.d.ts",
|
|
11
|
+
"main": "./dist-js/index.cjs",
|
|
12
|
+
"module": "./dist-js/index.js",
|
|
13
|
+
"exports": {
|
|
14
|
+
"types": "./dist-js/index.d.ts",
|
|
15
|
+
"import": "./dist-js/index.js",
|
|
16
|
+
"require": "./dist-js/index.cjs"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "rollup -c"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist-js",
|
|
23
|
+
"README.md",
|
|
24
|
+
"LICENSE"
|
|
25
|
+
],
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@tauri-apps/api": "^2.0.0-rc.0"
|
|
28
|
+
}
|
|
29
|
+
}
|