wip: trail & error

This commit is contained in:
Max Coppen 2022-11-03 22:05:12 +01:00
parent 728556dddf
commit c7821f4bd9
4 changed files with 58 additions and 31 deletions

View file

@ -16,7 +16,7 @@ tauri-build = { git = "https://github.com/tauri-apps/tauri", features = [] }
[dependencies] [dependencies]
serde_json = "1.0" serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] } 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" } shared = { path = "../shared" }
[features] [features]

View file

@ -51,7 +51,12 @@
"csp": null "csp": null
}, },
"updater": { "updater": {
"active": false "active": true,
"endpoints": [
"https://releases.myapp.com/{{target}}/{{current_version}}"
],
"dialog": true,
"pubkey": "YOUR_UPDATER_SIGNATURE_PUBKEY_HERE"
}, },
"windows": [ "windows": [
{ {

View file

@ -1,13 +1,17 @@
use sycamore::prelude::*; use sycamore::prelude::*;
use tauri_sys::clipboard::{read_text, write_text}; use tauri_sys::updater::check_update;
#[component] #[component]
pub fn Updater<G: Html>(cx: Scope) -> View<G> { pub fn Updater<G: Html>(cx: Scope) -> View<G> {
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 { 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(() => { // .then(() => {
// onMessage('Wrote to the clipboard') // onMessage('Wrote to the clipboard')
// }) // })
@ -15,27 +19,24 @@ pub fn Updater<G: Html>(cx: Scope) -> View<G> {
}); });
}; };
let read = |_| { // let read = |_| {
sycamore::futures::spawn_local(async move { // sycamore::futures::spawn_local(async move {
let text = read_text().await; // let text = read_text().await;
log::info!("Read text from clipboard {:?}", text); // log::info!("Read text from clipboard {:?}", text);
// readText() // // readText()
// .then((contents) => { // // .then((contents) => {
// onMessage(`Clipboard contents: ${contents}`) // // onMessage(`Clipboard contents: ${contents}`)
// }) // // })
// .catch(onMessage) // // .catch(onMessage)
}); // });
}; // };
view! { cx, view! { cx,
div(class="flex gap-1") { div(class="flex gap-1") {
input(class="grow input",placeholder="Text to write to the clipboard",bind:value=text) p(class="grow input",bind:value=text)
button(class="btn",type="button",on:click=write) { button(class="btn",type="button",on:click=check) {
"Write" "Check"
}
button(class="btn",type="button",on:click=read) {
"Read"
} }
} }
} }

View file

@ -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<UpdateManifest>,
pub should_update: bool
}
#[derive(Deserialize)]
pub enum UpdateStatus {
PENDING,
ERROR,
DONE,
UPTODATE
}
/// Install the update if there's one available. /// Install the update if there's one available.
/// ///
/// # Example /// # Example
@ -17,16 +40,14 @@ pub async fn install_update() {
/// # Example /// # Example
/// ///
/// ```rust,no_run /// ```rust,no_run
/// use tauri_api::clipboard::{write_text, read_text}; /// use tauri_api::updater::{check_update, UpdateResult};
/// ///
/// write_text("Tauri is awesome!").await; /// let update: UpdateResult = check_update().await;
/// assert_eq!(read_text().await, "Tauri is awesome!");
/// ``` /// ```
///
/// @returns A promise indicating the success or failure of the operation.
#[inline(always)] #[inline(always)]
pub async fn check_update() { pub async fn check_update() -> UpdateResult {
inner::checkUpdate().await let update = inner::checkUpdate().await;
serde_wasm_bindgen::from_value(update).unwrap()
} }
mod inner { mod inner {
@ -35,6 +56,6 @@ mod inner {
#[wasm_bindgen(module = "/dist/updater.js")] #[wasm_bindgen(module = "/dist/updater.js")]
extern "C" { extern "C" {
pub async fn installUpdate(); pub async fn installUpdate();
pub async fn checkUpdate(); pub async fn checkUpdate() -> JsValue;
} }
} }