From c7821f4bd9efebd63d5aff73b0067fe14f8be4b7 Mon Sep 17 00:00:00 2001 From: Max Coppen <44031065+mxcop@users.noreply.github.com> Date: Thu, 3 Nov 2022 22:05:12 +0100 Subject: [PATCH] wip: trail & error --- examples/api/src-tauri/Cargo.toml | 2 +- examples/api/src-tauri/tauri.conf.json | 7 ++++- examples/api/src/views/updater.rs | 43 +++++++++++++------------- src/updater.rs | 37 +++++++++++++++++----- 4 files changed, 58 insertions(+), 31 deletions(-) diff --git a/examples/api/src-tauri/Cargo.toml b/examples/api/src-tauri/Cargo.toml index ee6ef6f..400173d 100644 --- a/examples/api/src-tauri/Cargo.toml +++ b/examples/api/src-tauri/Cargo.toml @@ -16,7 +16,7 @@ tauri-build = { git = "https://github.com/tauri-apps/tauri", features = [] } [dependencies] serde_json = "1.0" serde = { version = "1.0", features = ["derive"] } -tauri = { git = "https://github.com/tauri-apps/tauri", features = ["api-all"] } +tauri = { git = "https://github.com/tauri-apps/tauri", features = ["api-all", "updater"] } shared = { path = "../shared" } [features] diff --git a/examples/api/src-tauri/tauri.conf.json b/examples/api/src-tauri/tauri.conf.json index 15e818e..32eedf6 100644 --- a/examples/api/src-tauri/tauri.conf.json +++ b/examples/api/src-tauri/tauri.conf.json @@ -51,7 +51,12 @@ "csp": null }, "updater": { - "active": false + "active": true, + "endpoints": [ + "https://releases.myapp.com/{{target}}/{{current_version}}" + ], + "dialog": true, + "pubkey": "YOUR_UPDATER_SIGNATURE_PUBKEY_HERE" }, "windows": [ { diff --git a/examples/api/src/views/updater.rs b/examples/api/src/views/updater.rs index b022248..179276f 100644 --- a/examples/api/src/views/updater.rs +++ b/examples/api/src/views/updater.rs @@ -1,13 +1,17 @@ use sycamore::prelude::*; -use tauri_sys::clipboard::{read_text, write_text}; +use tauri_sys::updater::check_update; #[component] pub fn Updater(cx: Scope) -> View { - let text = create_signal(cx, "clipboard message".to_string()); + let text = create_signal(cx, "...".to_string()); - let write = move |_| { + let check = move |_| { sycamore::futures::spawn_local_scoped(cx, async move { - write_text(&text.get()).await + log::info!("Test"); + + let text = format!("{:?}", check_update().await); + + log::info!("Update info {:?}", text); // .then(() => { // onMessage('Wrote to the clipboard') // }) @@ -15,27 +19,24 @@ pub fn Updater(cx: Scope) -> View { }); }; - let read = |_| { - sycamore::futures::spawn_local(async move { - let text = read_text().await; + // let read = |_| { + // sycamore::futures::spawn_local(async move { + // let text = read_text().await; - log::info!("Read text from clipboard {:?}", text); - // readText() - // .then((contents) => { - // onMessage(`Clipboard contents: ${contents}`) - // }) - // .catch(onMessage) - }); - }; + // log::info!("Read text from clipboard {:?}", text); + // // readText() + // // .then((contents) => { + // // onMessage(`Clipboard contents: ${contents}`) + // // }) + // // .catch(onMessage) + // }); + // }; view! { cx, div(class="flex gap-1") { - input(class="grow input",placeholder="Text to write to the clipboard",bind:value=text) - button(class="btn",type="button",on:click=write) { - "Write" - } - button(class="btn",type="button",on:click=read) { - "Read" + p(class="grow input",bind:value=text) + button(class="btn",type="button",on:click=check) { + "Check" } } } diff --git a/src/updater.rs b/src/updater.rs index 5ce159b..937c517 100644 --- a/src/updater.rs +++ b/src/updater.rs @@ -1,3 +1,26 @@ +use serde::Deserialize; + +#[derive(Deserialize, Debug)] +pub struct UpdateManifest { + pub body: String, + pub date: String, + pub version: String +} + +#[derive(Deserialize, Debug)] +pub struct UpdateResult { + pub manifest: Option, + pub should_update: bool +} + +#[derive(Deserialize)] +pub enum UpdateStatus { + PENDING, + ERROR, + DONE, + UPTODATE +} + /// Install the update if there's one available. /// /// # Example @@ -17,16 +40,14 @@ pub async fn install_update() { /// # Example /// /// ```rust,no_run -/// use tauri_api::clipboard::{write_text, read_text}; +/// use tauri_api::updater::{check_update, UpdateResult}; /// -/// write_text("Tauri is awesome!").await; -/// assert_eq!(read_text().await, "Tauri is awesome!"); +/// let update: UpdateResult = check_update().await; /// ``` -/// -/// @returns A promise indicating the success or failure of the operation. #[inline(always)] -pub async fn check_update() { - inner::checkUpdate().await +pub async fn check_update() -> UpdateResult { + let update = inner::checkUpdate().await; + serde_wasm_bindgen::from_value(update).unwrap() } mod inner { @@ -35,6 +56,6 @@ mod inner { #[wasm_bindgen(module = "/dist/updater.js")] extern "C" { pub async fn installUpdate(); - pub async fn checkUpdate(); + pub async fn checkUpdate() -> JsValue; } }