update example, use channel

pull/351/head
Lucas Nogueira 2 years ago
parent 22039ce791
commit bf92af354b
No known key found for this signature in database
GPG Key ID: FFEA6C72E73482F1

File diff suppressed because it is too large Load Diff

@ -30,8 +30,8 @@ tauri-plugin-shell = { path = "../../../plugins/shell" }
tauri-plugin-updater = { path = "../../../plugins/updater" }
[patch.crates-io]
tauri = { git = "https://github.com/tauri-apps/tauri", branch = "next" }
tauri-build = { git = "https://github.com/tauri-apps/tauri", branch = "next" }
tauri = { git = "https://github.com/tauri-apps/tauri", branch = "feat/channel" }
tauri-build = { git = "https://github.com/tauri-apps/tauri", branch = "feat/channel" }
[dependencies.tauri]
version = "2.0.0-alpha.8"

@ -24,11 +24,14 @@
async function install() {
isInstalling = true;
try {
await newUpdate.downloadAndInstall(onMessage);
await newUpdate.downloadAndInstall((res) => {
console.log("event", res);
});
onMessage("Installation complete, restarting...");
await new Promise((resolve) => setTimeout(resolve, 2000));
await relaunch();
} catch (e) {
console.error(e);
onMessage(e);
} finally {
isInstalling = false;

@ -18,7 +18,7 @@ Install the Core plugin by adding the following to your `Cargo.toml` file:
```toml
[dependencies]
tauri-plugin-cli = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "next" }
tauri-plugin-cli = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
```
You can install the JavaScript Guest bindings using your preferred JavaScript package manager:

@ -18,5 +18,5 @@ edition = "2021"
#thiserror.workspace = true
serde = "1"
thiserror = "1"
tauri = { git = "https://github.com/tauri-apps/tauri", branch = "next" }
tauri = { git = "https://github.com/tauri-apps/tauri", branch = "feat/channel" }
anyhow = "1"

@ -12,7 +12,7 @@ edition = "2021"
#tauri.workspace = true
#log.workspace = true
#thiserror.workspace = true
tauri = { git = "https://github.com/tauri-apps/tauri", branch = "next" }
tauri = { git = "https://github.com/tauri-apps/tauri", branch = "feat/channel" }
serde = "1"
serde_json = "1"
thiserror = "1"

@ -1311,6 +1311,32 @@ dependencies = [
"want",
]
[[package]]
name = "hyper-rustls"
version = "0.23.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1788965e61b367cd03a62950836d5cd41560c3577d90e40e0819373194d1661c"
dependencies = [
"http",
"hyper",
"rustls",
"tokio",
"tokio-rustls",
]
[[package]]
name = "hyper-tls"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905"
dependencies = [
"bytes",
"hyper",
"native-tls",
"tokio",
"tokio-native-tls",
]
[[package]]
name = "iana-time-zone"
version = "0.1.56"
@ -1706,6 +1732,24 @@ dependencies = [
"similar",
]
[[package]]
name = "native-tls"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e"
dependencies = [
"lazy_static",
"libc",
"log",
"openssl",
"openssl-probe",
"openssl-sys",
"schannel",
"security-framework",
"security-framework-sys",
"tempfile",
]
[[package]]
name = "ndk"
version = "0.6.0"
@ -1851,6 +1895,60 @@ version = "1.17.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3"
[[package]]
name = "openssl"
version = "0.10.52"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "01b8574602df80f7b85fdfc5392fa884a4e3b3f4f35402c070ab34c3d3f78d56"
dependencies = [
"bitflags",
"cfg-if",
"foreign-types",
"libc",
"once_cell",
"openssl-macros",
"openssl-sys",
]
[[package]]
name = "openssl-macros"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.15",
]
[[package]]
name = "openssl-probe"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf"
[[package]]
name = "openssl-src"
version = "111.25.3+1.1.1t"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "924757a6a226bf60da5f7dd0311a34d2b52283dd82ddeb103208ddc66362f80c"
dependencies = [
"cc",
]
[[package]]
name = "openssl-sys"
version = "0.9.87"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e17f59264b2809d77ae94f0e1ebabc434773f370d6ca667bd223ea10e06cc7e"
dependencies = [
"cc",
"libc",
"openssl-src",
"pkg-config",
"vcpkg",
]
[[package]]
name = "overload"
version = "0.1.1"
@ -2297,17 +2395,24 @@ dependencies = [
"http",
"http-body",
"hyper",
"hyper-rustls",
"hyper-tls",
"ipnet",
"js-sys",
"log",
"mime",
"native-tls",
"once_cell",
"percent-encoding",
"pin-project-lite",
"rustls",
"rustls-pemfile",
"serde",
"serde_json",
"serde_urlencoded",
"tokio",
"tokio-native-tls",
"tokio-rustls",
"tokio-util",
"tower-service",
"url",
@ -2315,9 +2420,25 @@ dependencies = [
"wasm-bindgen-futures",
"wasm-streams",
"web-sys",
"webpki-roots",
"winreg 0.10.1",
]
[[package]]
name = "ring"
version = "0.16.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc"
dependencies = [
"cc",
"libc",
"once_cell",
"spin",
"untrusted",
"web-sys",
"winapi",
]
[[package]]
name = "rustc_version"
version = "0.4.0"
@ -2341,6 +2462,27 @@ dependencies = [
"windows-sys 0.48.0",
]
[[package]]
name = "rustls"
version = "0.20.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fff78fc74d175294f4e83b28343315ffcfb114b156f0185e9741cb5570f50e2f"
dependencies = [
"log",
"ring",
"sct",
"webpki",
]
[[package]]
name = "rustls-pemfile"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d194b56d58803a43635bdc398cd17e383d6f71f9182b9a192c127ca42494a59b"
dependencies = [
"base64 0.21.0",
]
[[package]]
name = "rustversion"
version = "1.0.12"
@ -2368,6 +2510,15 @@ dependencies = [
"winapi-util",
]
[[package]]
name = "schannel"
version = "0.1.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "713cfb06c7059f3588fb8044c0fad1d09e3c01d225e25b9220dbfdcf16dbb1b3"
dependencies = [
"windows-sys 0.42.0",
]
[[package]]
name = "scoped-tls"
version = "1.0.1"
@ -2386,6 +2537,39 @@ version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1792db035ce95be60c3f8853017b3999209281c24e2ba5bc8e59bf97a0c590c1"
[[package]]
name = "sct"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d53dcdb7c9f8158937a7981b48accfd39a43af418591a5d008c7b22b5e1b7ca4"
dependencies = [
"ring",
"untrusted",
]
[[package]]
name = "security-framework"
version = "2.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a332be01508d814fed64bf28f798a146d73792121129962fdf335bb3c49a4254"
dependencies = [
"bitflags",
"core-foundation",
"core-foundation-sys",
"libc",
"security-framework-sys",
]
[[package]]
name = "security-framework-sys"
version = "2.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "31c9bb296072e961fcbd8853511dd39c2d8be2deb1e17c6860b1d30732b323b4"
dependencies = [
"core-foundation-sys",
"libc",
]
[[package]]
name = "selectors"
version = "0.22.0"
@ -2629,6 +2813,12 @@ dependencies = [
"system-deps",
]
[[package]]
name = "spin"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
[[package]]
name = "stable_deref_trait"
version = "1.2.0"
@ -3129,6 +3319,27 @@ dependencies = [
"windows-sys 0.48.0",
]
[[package]]
name = "tokio-native-tls"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2"
dependencies = [
"native-tls",
"tokio",
]
[[package]]
name = "tokio-rustls"
version = "0.23.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c43ee83903113e03984cb9e5cebe6c04a5116269e900e3ddba8f068a62adda59"
dependencies = [
"rustls",
"tokio",
"webpki",
]
[[package]]
name = "tokio-stream"
version = "0.1.14"
@ -3323,6 +3534,12 @@ version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b"
[[package]]
name = "untrusted"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a"
[[package]]
name = "url"
version = "2.3.1"
@ -3356,6 +3573,12 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
[[package]]
name = "vcpkg"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
[[package]]
name = "version-compare"
version = "0.1.1"
@ -3553,6 +3776,25 @@ dependencies = [
"system-deps",
]
[[package]]
name = "webpki"
version = "0.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f095d78192e208183081cc07bc5515ef55216397af48b873e5edcd72637fa1bd"
dependencies = [
"ring",
"untrusted",
]
[[package]]
name = "webpki-roots"
version = "0.22.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6c71e40d7d2c34a5106301fb632274ca37242cd0c9d3e64dbece371a40a2d87"
dependencies = [
"webpki",
]
[[package]]
name = "webview2-com"
version = "0.22.1"
@ -3680,6 +3922,21 @@ version = "0.44.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee78911e3f4ce32c1ad9d3c7b0bd95389662ad8d8f1a3155688fed70bd96e2b6"
[[package]]
name = "windows-sys"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7"
dependencies = [
"windows_aarch64_gnullvm 0.42.2",
"windows_aarch64_msvc 0.42.2",
"windows_i686_gnu 0.42.2",
"windows_i686_msvc 0.42.2",
"windows_x86_64_gnu 0.42.2",
"windows_x86_64_gnullvm 0.42.2",
"windows_x86_64_msvc 0.42.2",
]
[[package]]
name = "windows-sys"
version = "0.45.0"

@ -11,7 +11,7 @@ edition = "2021"
#serde.workspace = true
#serde_json.workspace = true
#thiserror.workspace = true
tauri = { path = "../../../tauri/core/tauri", features = ["updater", "fs-extract-api"] }
tauri = { git = "https://github.com/tauri-apps/tauri", branch = "feat/channel", features = ["updater", "fs-extract-api"] }
serde = "1"
serde_json = "1"
thiserror = "1"
@ -33,5 +33,10 @@ tempfile = "3"
mockito = "0.31"
tokio-test = "0.4.2"
[patch.crates-io]
tauri-runtime = { path = "../../../tauri/core/tauri-runtime/" }
[features]
native-tls = [ "reqwest/native-tls" ]
native-tls-vendored = [ "reqwest/native-tls-vendored" ]
rustls-tls = [ "reqwest/rustls-tls" ]
[patch.'https://github.com/tauri-apps/tauri']
tauri = { path = "../../../tauri/core/tauri" }

@ -26,16 +26,26 @@ interface UpdateResponse {
// TODO: use channel from @tauri-apps/api on v2
class Channel<T = unknown> {
id: number
onmessage: (response: T) => void = () => {
// do nothing
// @ts-expect-error field used by the IPC serializer
private readonly __TAURI_CHANNEL_MARKER__ = true
#onmessage: (response: T) => void = () => {
// no-op
}
constructor() {
this.id = transformCallback((response: T) => {
this.onmessage(response)
this.#onmessage(response)
})
}
set onmessage(handler: (response: T) => void) {
this.#onmessage = handler;
}
get onmessage(): (response: T) => void {
return this.#onmessage
}
toJSON(): string {
return `__CHANNEL__:${this.id}`
}
@ -49,7 +59,7 @@ type DownloadEvent =
class Update {
response: UpdateResponse
private constructor(response: UpdateResponse) {
constructor(response: UpdateResponse) {
this.response = response
}
@ -63,7 +73,7 @@ class Update {
}
async function check(options?: CheckOptions): Promise<Update> {
return invoke('plugin:updater|check', { ...options })
return invoke<UpdateResponse>('plugin:updater|check', { ...options }).then(response => new Update(response))
}
export type { CheckOptions, UpdateResponse, DownloadEvent }

@ -91,10 +91,10 @@ pub(crate) async fn download_and_install<R: Runtime>(
pending: State<'_, PendingUpdate<R>>,
on_event: Channel<R>,
) -> Result<()> {
if let Some(pending) = pending.0.lock().await.take() {
if let Some(pending) = &*pending.0.lock().await {
pending
.download_and_install(move |event| {
let _ = on_event.send(&event);
on_event.send(&event).unwrap();
})
.await?;
}

@ -507,7 +507,7 @@ impl<R: Runtime> Clone for Update<R> {
}
}
#[derive(Serialize)]
#[derive(Debug, Serialize)]
#[serde(tag = "event", content = "data")]
pub enum DownloadEvent {
#[serde(rename_all = "camelCase")]

@ -269,7 +269,7 @@ impl<R: Runtime> UpdateResponse<R> {
}
/// Downloads and installs the update.
pub async fn download_and_install<F: Fn(DownloadEvent)>(self, on_event: F) -> Result<()> {
pub async fn download_and_install<F: Fn(DownloadEvent)>(&self, on_event: F) -> Result<()> {
// Launch updater download process
// macOS we display the `Ready to restart dialog` asking to restart
// Windows is closing the current App and launch the downloaded MSI when ready (the process stop here)

@ -15,9 +15,6 @@ serde = "1"
serde_json = "1"
time = { version = "0.3", features = ["formatting"] }
[patch.crates-io]
tauri-runtime = { path = "../../../../../tauri/core/tauri-runtime/" }
[features]
default = ["custom-protocol"]
custom-protocol = ["tauri/custom-protocol"]

Loading…
Cancel
Save