chore: adjust prettier config, .gitignore and use taplo to format toml files (#1728)

* chore: adjust prettier config, .gitignore and use taplo to format toml files

This brings the plugins-workspace repository to the same code style of the main tauri repo

* format toml

* ignore examples gen dir

* add .vscode/extensions.json

* remove packageManager field

* fmt

* fix audit

* taplo ignore permissions autogenerated files

* remove create dummy dist

* fix prettier workflow

* install fmt in prettier workflow

---------

Co-authored-by: Lucas Nogueira <lucas@tauri.app>
This commit is contained in:
Amr Bashir
2024-09-04 14:54:23 +03:00
committed by GitHub
parent 72c2ce82c1
commit cf4d7d4e6c
227 changed files with 2534 additions and 2505 deletions
-1
View File
@@ -1 +0,0 @@
/.tauri
+4 -4
View File
@@ -9,12 +9,12 @@ repository = { workspace = true }
links = "tauri-plugin-geolocation"
[package.metadata.docs.rs]
rustc-args = [ "--cfg", "docsrs" ]
rustdoc-args = [ "--cfg", "docsrs" ]
targets = [ "x86_64-linux-android" ]
rustc-args = ["--cfg", "docsrs"]
rustdoc-args = ["--cfg", "docsrs"]
targets = ["x86_64-linux-android"]
[build-dependencies]
tauri-plugin = { workspace = true, features = [ "build" ] }
tauri-plugin = { workspace = true, features = ["build"] }
[dependencies]
serde = { workspace = true }
+4 -4
View File
@@ -87,16 +87,16 @@ fn main() {
Afterwards all the plugin's APIs are available through the JavaScript guest bindings:
```javascript
import { getCurrentPosition, watchPosition } from "@tauri-apps/plugin-log";
import { getCurrentPosition, watchPosition } from '@tauri-apps/plugin-log'
const pos = await getCurrentPosition();
const pos = await getCurrentPosition()
await watchPosition(
{ enableHighAccuracy: true, timeout: 10000, maximumAge: 0 },
(pos) => {
console.log(pos);
console.log(pos)
}
);
)
```
## Contributing
+1 -1
View File
@@ -20,4 +20,4 @@ We prefer to receive reports in English.
Please disclose a vulnerability or security relevant issue here: [https://github.com/tauri-apps/plugins-workspace/security/advisories/new](https://github.com/tauri-apps/plugins-workspace/security/advisories/new).
Alternatively, you can also contact us by email via [security@tauri.app](mailto:security@tauri.app).
Alternatively, you can also contact us by email via [security@tauri.app](mailto:security@tauri.app).
+88 -88
View File
@@ -9,77 +9,77 @@
export const commands = {
async getCurrentPosition(
options: PositionOptions | null,
options: PositionOptions | null
): Promise<Result<Position, Error>> {
try {
return {
status: "ok",
data: await TAURI_INVOKE("plugin:geolocation|get_current_position", {
options,
}),
};
status: 'ok',
data: await TAURI_INVOKE('plugin:geolocation|get_current_position', {
options
})
}
} catch (e) {
if (e instanceof Error) throw e;
else return { status: "error", error: e as any };
if (e instanceof Error) throw e
else return { status: 'error', error: e as any }
}
},
async watchPosition(
options: PositionOptions,
channel: any,
channel: any
): Promise<Result<null, Error>> {
try {
return {
status: "ok",
data: await TAURI_INVOKE("plugin:geolocation|watch_position", {
status: 'ok',
data: await TAURI_INVOKE('plugin:geolocation|watch_position', {
options,
channel,
}),
};
channel
})
}
} catch (e) {
if (e instanceof Error) throw e;
else return { status: "error", error: e as any };
if (e instanceof Error) throw e
else return { status: 'error', error: e as any }
}
},
async clearWatch(channelId: number): Promise<Result<null, Error>> {
try {
return {
status: "ok",
data: await TAURI_INVOKE("plugin:geolocation|clear_watch", {
channelId,
}),
};
status: 'ok',
data: await TAURI_INVOKE('plugin:geolocation|clear_watch', {
channelId
})
}
} catch (e) {
if (e instanceof Error) throw e;
else return { status: "error", error: e as any };
if (e instanceof Error) throw e
else return { status: 'error', error: e as any }
}
},
async checkPermissions(): Promise<Result<PermissionStatus, Error>> {
try {
return {
status: "ok",
data: await TAURI_INVOKE("plugin:geolocation|check_permissions"),
};
status: 'ok',
data: await TAURI_INVOKE('plugin:geolocation|check_permissions')
}
} catch (e) {
if (e instanceof Error) throw e;
else return { status: "error", error: e as any };
if (e instanceof Error) throw e
else return { status: 'error', error: e as any }
}
},
async requestPermissions(
permissions: PermissionType[] | null,
permissions: PermissionType[] | null
): Promise<Result<PermissionStatus, Error>> {
try {
return {
status: "ok",
data: await TAURI_INVOKE("plugin:geolocation|request_permissions", {
permissions,
}),
};
status: 'ok',
data: await TAURI_INVOKE('plugin:geolocation|request_permissions', {
permissions
})
}
} catch (e) {
if (e instanceof Error) throw e;
else return { status: "error", error: e as any };
if (e instanceof Error) throw e
else return { status: 'error', error: e as any }
}
},
};
}
}
/** user-defined events **/
@@ -97,31 +97,31 @@ export type Coordinates = {
/**
* Latitude in decimal degrees.
*/
latitude: number;
latitude: number
/**
* Longitude in decimal degrees.
*/
longitude: number;
longitude: number
/**
* Accuracy level of the latitude and longitude coordinates in meters.
*/
accuracy: number;
accuracy: number
/**
* Accuracy level of the altitude coordinate in meters, if available.
* Available on all iOS versions and on Android 8 and above.
*/
altitudeAccuracy: number | null;
altitudeAccuracy: number | null
/**
* The altitude the user is at, if available.
*/
altitude: number | null;
speed: number | null;
altitude: number | null
speed: number | null
/**
* The heading the user is facing, if available.
*/
heading: number | null;
};
export type Error = never;
heading: number | null
}
export type Error = never
/**
* Permission state.
*/
@@ -129,15 +129,15 @@ export type PermissionState =
/**
* Permission access has been granted.
*/
| "granted"
| 'granted'
/**
* Permission access has been denied.
*/
| "denied"
| 'denied'
/**
* The end user should be prompted for permission.
*/
| "prompt";
| 'prompt'
export type PermissionStatus = {
/**
* Permission state for the location alias.
@@ -146,7 +146,7 @@ export type PermissionStatus = {
*
* On iOS it requests/checks location permissions.
*/
location: PermissionState;
location: PermissionState
/**
* Permissions state for the coarseLoaction alias.
*
@@ -156,93 +156,93 @@ export type PermissionStatus = {
*
* On iOS it will have the same value as the `location` alias.
*/
coarseLocation: PermissionState;
};
export type PermissionType = "location" | "coarseLocation";
coarseLocation: PermissionState
}
export type PermissionType = 'location' | 'coarseLocation'
export type Position = {
/**
* Creation time for these coordinates.
*/
timestamp: number;
timestamp: number
/**
* The GPD coordinates along with the accuracy of the data.
*/
coords: Coordinates;
};
coords: Coordinates
}
export type PositionOptions = {
/**
* High accuracy mode (such as GPS, if available)
* Will be ignored on Android 12+ if users didn't grant the ACCESS_FINE_LOCATION permission.
*/
enableHighAccuracy: boolean;
enableHighAccuracy: boolean
/**
* The maximum wait time in milliseconds for location updates.
* On Android the timeout gets ignored for getCurrentPosition.
* Ignored on iOS
*/
timeout: number;
timeout: number
/**
* The maximum age in milliseconds of a possible cached position that is acceptable to return.
* Default: 0
* Ignored on iOS
*/
maximumAge: number;
};
maximumAge: number
}
//export type RandomNumber = number;
/** tauri-specta globals **/
import { invoke as TAURI_INVOKE } from "@tauri-apps/api/core";
import * as TAURI_API_EVENT from "@tauri-apps/api/event";
import { type WebviewWindow as __WebviewWindow__ } from "@tauri-apps/api/webviewWindow";
import { invoke as TAURI_INVOKE } from '@tauri-apps/api/core'
import * as TAURI_API_EVENT from '@tauri-apps/api/event'
import { type WebviewWindow as __WebviewWindow__ } from '@tauri-apps/api/webviewWindow'
type __EventObj__<T> = {
listen: (
cb: TAURI_API_EVENT.EventCallback<T>,
) => ReturnType<typeof TAURI_API_EVENT.listen<T>>;
cb: TAURI_API_EVENT.EventCallback<T>
) => ReturnType<typeof TAURI_API_EVENT.listen<T>>
once: (
cb: TAURI_API_EVENT.EventCallback<T>,
) => ReturnType<typeof TAURI_API_EVENT.once<T>>;
cb: TAURI_API_EVENT.EventCallback<T>
) => ReturnType<typeof TAURI_API_EVENT.once<T>>
emit: T extends null
? (payload?: T) => ReturnType<typeof TAURI_API_EVENT.emit>
: (payload: T) => ReturnType<typeof TAURI_API_EVENT.emit>;
};
: (payload: T) => ReturnType<typeof TAURI_API_EVENT.emit>
}
export type Result<T, E> =
| { status: "ok"; data: T }
| { status: "error"; error: E };
| { status: 'ok'; data: T }
| { status: 'error'; error: E }
function __makeEvents__<T extends Record<string, any>>(
mappings: Record<keyof T, string>,
mappings: Record<keyof T, string>
) {
return new Proxy(
{} as unknown as {
[K in keyof T]: __EventObj__<T[K]> & {
(handle: __WebviewWindow__): __EventObj__<T[K]>;
};
(handle: __WebviewWindow__): __EventObj__<T[K]>
}
},
{
get: (_, event) => {
const name = mappings[event as keyof T];
const name = mappings[event as keyof T]
return new Proxy((() => {}) as any, {
apply: (_, __, [window]: [__WebviewWindow__]) => ({
listen: (arg: any) => window.listen(name, arg),
once: (arg: any) => window.once(name, arg),
emit: (arg: any) => window.emit(name, arg),
emit: (arg: any) => window.emit(name, arg)
}),
get: (_, command: keyof __EventObj__<any>) => {
switch (command) {
case "listen":
return (arg: any) => TAURI_API_EVENT.listen(name, arg);
case "once":
return (arg: any) => TAURI_API_EVENT.once(name, arg);
case "emit":
return (arg: any) => TAURI_API_EVENT.emit(name, arg);
case 'listen':
return (arg: any) => TAURI_API_EVENT.listen(name, arg)
case 'once':
return (arg: any) => TAURI_API_EVENT.once(name, arg)
case 'emit':
return (arg: any) => TAURI_API_EVENT.emit(name, arg)
}
},
});
},
},
);
}
})
}
}
)
}
+11 -11
View File
@@ -4,26 +4,26 @@
/* eslint-disable @typescript-eslint/unbound-method */
import { Channel } from "@tauri-apps/api/core";
import { commands, type PositionOptions, type Position } from "./bindings";
import { Channel } from '@tauri-apps/api/core'
import { commands, type PositionOptions, type Position } from './bindings'
export async function watchPosition(
options: PositionOptions,
// TODO: This can receive errors too
cb: (location: Position | string) => void,
cb: (location: Position | string) => void
): Promise<number> {
const channel = new Channel<Position>();
channel.onmessage = cb;
await commands.watchPosition(options, channel);
return channel.id;
const channel = new Channel<Position>()
channel.onmessage = cb
await commands.watchPosition(options, channel)
return channel.id
}
export const {
getCurrentPosition,
clearWatch,
checkPermissions,
requestPermissions,
} = commands;
requestPermissions
} = commands
export type {
PermissionState,
@@ -31,7 +31,7 @@ export type {
PermissionType,
Position,
PositionOptions,
Coordinates,
} from "./bindings";
Coordinates
} from './bindings'
// export { events };
+2 -2
View File
@@ -2,6 +2,6 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
import { createConfig } from "../../shared/rollup.config.js";
import { createConfig } from '../../shared/rollup.config.js'
export default createConfig();
export default createConfig()