From 33a0fcc6b036144943c305a7bad82f6e2cc65414 Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Wed, 4 Sep 2024 11:55:36 +0000 Subject: [PATCH] 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 Committed via a GitHub action: https://github.com/tauri-apps/plugins-workspace/actions/runs/10701104849 Co-authored-by: lucasfernog --- Cargo.toml | 8 +-- README.md | 10 ++-- SECURITY.md | 2 +- dist-js/index.cjs | 18 +++---- dist-js/index.d.ts | 8 +-- dist-js/index.js | 18 +++---- guest-js/index.ts | 108 +++++++++++++++++++-------------------- permissions/default.toml | 8 +-- rollup.config.js | 4 +- 9 files changed, 92 insertions(+), 92 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0d5cc8b..0a035eb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,13 +10,13 @@ repository = { workspace = true } links = "tauri-plugin-updater" [package.metadata.docs.rs] -rustc-args = [ "--cfg", "docsrs" ] -rustdoc-args = [ "--cfg", "docsrs" ] +rustc-args = ["--cfg", "docsrs"] +rustdoc-args = ["--cfg", "docsrs"] no-default-features = true -features = [ "zip" ] +features = ["zip"] [build-dependencies] -tauri-plugin = { workspace = true, features = [ "build" ] } +tauri-plugin = { workspace = true, features = ["build"] } [dependencies] tauri = { workspace = true } diff --git a/README.md b/README.md index e2309f1..836a63b 100644 --- a/README.md +++ b/README.md @@ -67,12 +67,12 @@ fn main() { Afterwards all the plugin's APIs are available through the JavaScript guest bindings: ```javascript -import { check } from "@tauri-apps/plugin-updater"; -import { relaunch } from "@tauri-apps/plugin-process"; -const update = await check(); +import { check } from '@tauri-apps/plugin-updater' +import { relaunch } from '@tauri-apps/plugin-process' +const update = await check() if (update?.available) { - await update.downloadAndInstall(); - await relaunch(); + await update.downloadAndInstall() + await relaunch() } ``` diff --git a/SECURITY.md b/SECURITY.md index 67d831f..4f09bba 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -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). \ No newline at end of file +Alternatively, you can also contact us by email via [security@tauri.app](mailto:security@tauri.app). diff --git a/dist-js/index.cjs b/dist-js/index.cjs index f472782..f778f33 100644 --- a/dist-js/index.cjs +++ b/dist-js/index.cjs @@ -20,21 +20,21 @@ class Update extends core.Resource { if (onEvent) { channel.onmessage = onEvent; } - const downloadedBytesRid = await core.invoke("plugin:updater|download", { + const downloadedBytesRid = await core.invoke('plugin:updater|download', { onEvent: channel, rid: this.rid, - ...options, + ...options }); this.downloadedBytes = new core.Resource(downloadedBytesRid); } /** Install downloaded updater package */ async install() { if (!this.downloadedBytes) { - throw new Error("Update.install called before Update.download"); + throw new Error('Update.install called before Update.download'); } - await core.invoke("plugin:updater|install", { + await core.invoke('plugin:updater|install', { updateRid: this.rid, - bytesRid: this.downloadedBytes.rid, + bytesRid: this.downloadedBytes.rid }); // Don't need to call close, we did it in rust side already this.downloadedBytes = undefined; @@ -45,10 +45,10 @@ class Update extends core.Resource { if (onEvent) { channel.onmessage = onEvent; } - await core.invoke("plugin:updater|download_and_install", { + await core.invoke('plugin:updater|download_and_install', { onEvent: channel, rid: this.rid, - ...options, + ...options }); } async close() { @@ -61,8 +61,8 @@ async function check(options) { if (options?.headers) { options.headers = Array.from(new Headers(options.headers).entries()); } - return await core.invoke("plugin:updater|check", { - ...options, + return await core.invoke('plugin:updater|check', { + ...options }).then((meta) => (meta.available ? new Update(meta) : null)); } diff --git a/dist-js/index.d.ts b/dist-js/index.d.ts index 392b7fd..c27a572 100644 --- a/dist-js/index.d.ts +++ b/dist-js/index.d.ts @@ -1,4 +1,4 @@ -import { Resource } from "@tauri-apps/api/core"; +import { Resource } from '@tauri-apps/api/core'; /** Options used when checking for updates */ interface CheckOptions { /** @@ -39,17 +39,17 @@ interface UpdateMetadata { } /** Updater download event */ type DownloadEvent = { - event: "Started"; + event: 'Started'; data: { contentLength?: number; }; } | { - event: "Progress"; + event: 'Progress'; data: { chunkLength: number; }; } | { - event: "Finished"; + event: 'Finished'; }; declare class Update extends Resource { available: boolean; diff --git a/dist-js/index.js b/dist-js/index.js index d87aebb..270ce25 100644 --- a/dist-js/index.js +++ b/dist-js/index.js @@ -18,21 +18,21 @@ class Update extends Resource { if (onEvent) { channel.onmessage = onEvent; } - const downloadedBytesRid = await invoke("plugin:updater|download", { + const downloadedBytesRid = await invoke('plugin:updater|download', { onEvent: channel, rid: this.rid, - ...options, + ...options }); this.downloadedBytes = new Resource(downloadedBytesRid); } /** Install downloaded updater package */ async install() { if (!this.downloadedBytes) { - throw new Error("Update.install called before Update.download"); + throw new Error('Update.install called before Update.download'); } - await invoke("plugin:updater|install", { + await invoke('plugin:updater|install', { updateRid: this.rid, - bytesRid: this.downloadedBytes.rid, + bytesRid: this.downloadedBytes.rid }); // Don't need to call close, we did it in rust side already this.downloadedBytes = undefined; @@ -43,10 +43,10 @@ class Update extends Resource { if (onEvent) { channel.onmessage = onEvent; } - await invoke("plugin:updater|download_and_install", { + await invoke('plugin:updater|download_and_install', { onEvent: channel, rid: this.rid, - ...options, + ...options }); } async close() { @@ -59,8 +59,8 @@ async function check(options) { if (options?.headers) { options.headers = Array.from(new Headers(options.headers).entries()); } - return await invoke("plugin:updater|check", { - ...options, + return await invoke('plugin:updater|check', { + ...options }).then((meta) => (meta.available ? new Update(meta) : null)); } diff --git a/guest-js/index.ts b/guest-js/index.ts index 42e6971..54d1d17 100644 --- a/guest-js/index.ts +++ b/guest-js/index.ts @@ -2,26 +2,26 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: MIT -import { invoke, Channel, Resource } from "@tauri-apps/api/core"; +import { invoke, Channel, Resource } from '@tauri-apps/api/core' /** Options used when checking for updates */ interface CheckOptions { /** * Request headers */ - headers?: HeadersInit; + headers?: HeadersInit /** * Timeout in milliseconds */ - timeout?: number; + timeout?: number /** * A proxy url to be used when checking and downloading updates. */ - proxy?: string; + proxy?: string /** * Target identifier for the running application. This is sent to the backend. */ - target?: string; + target?: string } /** Options used when downloading an update */ @@ -29,109 +29,109 @@ interface DownloadOptions { /** * Request headers */ - headers?: HeadersInit; + headers?: HeadersInit /** * Timeout in milliseconds */ - timeout?: number; + timeout?: number } interface UpdateMetadata { - rid: number; - available: boolean; - currentVersion: string; - version: string; - date?: string; - body?: string; + rid: number + available: boolean + currentVersion: string + version: string + date?: string + body?: string } /** Updater download event */ type DownloadEvent = - | { event: "Started"; data: { contentLength?: number } } - | { event: "Progress"; data: { chunkLength: number } } - | { event: "Finished" }; + | { event: 'Started'; data: { contentLength?: number } } + | { event: 'Progress'; data: { chunkLength: number } } + | { event: 'Finished' } class Update extends Resource { - available: boolean; - currentVersion: string; - version: string; - date?: string; - body?: string; - private downloadedBytes?: Resource; + available: boolean + currentVersion: string + version: string + date?: string + body?: string + private downloadedBytes?: Resource constructor(metadata: UpdateMetadata) { - super(metadata.rid); - this.available = metadata.available; - this.currentVersion = metadata.currentVersion; - this.version = metadata.version; - this.date = metadata.date; - this.body = metadata.body; + super(metadata.rid) + this.available = metadata.available + this.currentVersion = metadata.currentVersion + this.version = metadata.version + this.date = metadata.date + this.body = metadata.body } /** Download the updater package */ async download( onEvent?: (progress: DownloadEvent) => void, - options?: DownloadOptions, + options?: DownloadOptions ): Promise { - const channel = new Channel(); + const channel = new Channel() if (onEvent) { - channel.onmessage = onEvent; + channel.onmessage = onEvent } - const downloadedBytesRid = await invoke("plugin:updater|download", { + const downloadedBytesRid = await invoke('plugin:updater|download', { onEvent: channel, rid: this.rid, - ...options, - }); - this.downloadedBytes = new Resource(downloadedBytesRid); + ...options + }) + this.downloadedBytes = new Resource(downloadedBytesRid) } /** Install downloaded updater package */ async install(): Promise { if (!this.downloadedBytes) { - throw new Error("Update.install called before Update.download"); + throw new Error('Update.install called before Update.download') } - await invoke("plugin:updater|install", { + await invoke('plugin:updater|install', { updateRid: this.rid, - bytesRid: this.downloadedBytes.rid, - }); + bytesRid: this.downloadedBytes.rid + }) // Don't need to call close, we did it in rust side already - this.downloadedBytes = undefined; + this.downloadedBytes = undefined } /** Downloads the updater package and installs it */ async downloadAndInstall( onEvent?: (progress: DownloadEvent) => void, - options?: DownloadOptions, + options?: DownloadOptions ): Promise { - const channel = new Channel(); + const channel = new Channel() if (onEvent) { - channel.onmessage = onEvent; + channel.onmessage = onEvent } - await invoke("plugin:updater|download_and_install", { + await invoke('plugin:updater|download_and_install', { onEvent: channel, rid: this.rid, - ...options, - }); + ...options + }) } async close(): Promise { - await this.downloadedBytes?.close(); - await super.close(); + await this.downloadedBytes?.close() + await super.close() } } /** Check for updates, resolves to `null` if no updates are available */ async function check(options?: CheckOptions): Promise { if (options?.headers) { - options.headers = Array.from(new Headers(options.headers).entries()); + options.headers = Array.from(new Headers(options.headers).entries()) } - return await invoke("plugin:updater|check", { - ...options, - }).then((meta) => (meta.available ? new Update(meta) : null)); + return await invoke('plugin:updater|check', { + ...options + }).then((meta) => (meta.available ? new Update(meta) : null)) } -export type { CheckOptions, DownloadOptions, DownloadEvent }; -export { check, Update }; +export type { CheckOptions, DownloadOptions, DownloadEvent } +export { check, Update } diff --git a/permissions/default.toml b/permissions/default.toml index 6ae34b6..fcf08fa 100644 --- a/permissions/default.toml +++ b/permissions/default.toml @@ -11,8 +11,8 @@ is enabled. """ permissions = [ - "allow-check", - "allow-download", - "allow-install", - "allow-download-and-install", + "allow-check", + "allow-download", + "allow-install", + "allow-download-and-install", ] diff --git a/rollup.config.js b/rollup.config.js index 977dfac..1f349ec 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -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()