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]
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]

View file

@ -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": [
{

View file

@ -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<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 {
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<G: Html>(cx: Scope) -> View<G> {
});
};
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"
}
}
}

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.
///
/// # 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;
}
}