mirror of
https://github.com/tauri-apps/tauri-plugin-updater.git
synced 2026-01-31 00:55:19 +01:00
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> Committed via a GitHub action: https://github.com/tauri-apps/plugins-workspace/actions/runs/10701104849 Co-authored-by: lucasfernog <lucasfernog@users.noreply.github.com>
This commit is contained in:
@@ -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 }
|
||||
|
||||
10
README.md
10
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()
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
8
dist-js/index.d.ts
vendored
8
dist-js/index.d.ts
vendored
@@ -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;
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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<void> {
|
||||
const channel = new Channel<DownloadEvent>();
|
||||
const channel = new Channel<DownloadEvent>()
|
||||
if (onEvent) {
|
||||
channel.onmessage = onEvent;
|
||||
channel.onmessage = onEvent
|
||||
}
|
||||
const downloadedBytesRid = await invoke<number>("plugin:updater|download", {
|
||||
const downloadedBytesRid = await invoke<number>('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<void> {
|
||||
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<void> {
|
||||
const channel = new Channel<DownloadEvent>();
|
||||
const channel = new Channel<DownloadEvent>()
|
||||
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<void> {
|
||||
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<Update | null> {
|
||||
if (options?.headers) {
|
||||
options.headers = Array.from(new Headers(options.headers).entries());
|
||||
options.headers = Array.from(new Headers(options.headers).entries())
|
||||
}
|
||||
|
||||
return await invoke<UpdateMetadata>("plugin:updater|check", {
|
||||
...options,
|
||||
}).then((meta) => (meta.available ? new Update(meta) : null));
|
||||
return await invoke<UpdateMetadata>('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 }
|
||||
|
||||
@@ -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",
|
||||
]
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user