update vue example

This commit is contained in:
tensor-programming
2019-12-24 14:06:43 -05:00
parent cce215f97e
commit a5d58f55b4
4 changed files with 27 additions and 77 deletions

View File

@@ -9,6 +9,7 @@ license = ""
repository = ""
default-run = "app"
edition = "2018"
build = "src/build.rs"
[package.metadata.bundle]
identifier = "com.tauri.dev"
@@ -21,14 +22,15 @@ icon = [
]
[dependencies]
serde_json = "1.0.44"
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0.41"
serde = "1.0.104"
serde_derive = "1.0.104"
tiny_http = "0.6"
phf = "0.8.0"
includedir = "0.5.0"
tauri = { path = "../../../../tauri", features = [ "all-api", "edge" ] }
[target."cfg(windows)".build-dependencies]
winres = "0.1"
[features]
dev-server = [ "tauri/dev-server" ]
embedded-server = [ "tauri/embedded-server" ]

View File

@@ -0,0 +1,12 @@
#[cfg(windows)]
extern crate winres;
#[cfg(windows)]
fn main() {
let mut res = winres::WindowsResource::new();
res.set_icon("icons/icon.ico");
res.compile().expect("Unable to find visual studio tools");
}
#[cfg(not(windows))]
fn main() {}

View File

@@ -1,3 +1,8 @@
#![cfg_attr(
all(not(debug_assertions), target_os = "windows"),
windows_subsystem = "windows"
)]
mod cmd;
#[macro_use]
@@ -12,15 +17,15 @@ fn main() {
#[derive(Serialize)]
pub struct Reply {
pub msg: String,
pub rep: String
pub rep: String,
}
let reply = Reply {
msg: format!("{}", msg).to_string(),
rep: "something else".to_string()
rep: "something else".to_string(),
};
tauri::event::emit(&handle, "reply", serde_json::to_string(&reply).unwrap());
tauri::event::emit(&handle, "reply", serde_json::to_string(&reply).unwrap());
println!("Message from emit:hello => {}", msg);
});

View File

@@ -1,69 +0,0 @@
use crate::tauri::process::{ProcessExt, Signal, SystemExt};
fn update() -> Result<(), String> {
let target = tauri::platform::target_triple().map_err(|_| "Could not determine target")?;
let github_release = tauri::updater::github::get_latest_release("jaemk", "self_update")
.map_err(|_| "Could not fetch latest release")?;
match github_release.asset_for(&target) {
Some(github_release_asset) => {
let release = tauri::updater::Release {
version: github_release.tag.trim_start_matches('v').to_string(),
download_url: github_release_asset.download_url,
asset_name: github_release_asset.name,
};
let status = tauri::updater::Update::configure()
.unwrap()
.release(release)
.bin_path_in_archive("github")
.bin_name("app")
.bin_install_path(&tauri::command::command_path("app".to_string()).unwrap())
.show_download_progress(true)
.current_version(env!("CARGO_PKG_VERSION"))
.build()
.unwrap()
.update()
.unwrap();
println!("found release: {}", status.version());
/*let tmp_dir = tauri::dir::with_temp_dir(|dir| {
let file_path = dir.path().join("my-temporary-note.pdf");
let mut tmp_archive = std::fs::File::create(file_path).unwrap();
tauri::http::download(&"https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf".to_string(), &mut tmp_archive, true).unwrap();
});*/
Ok(())
}
None => Err(format!("Could not find release for target {}", target)),
}
}
fn restart_app(app_command: String) -> Result<(), String> {
let mut system = tauri::process::System::new();
let parent_process = tauri::process::get_parent_process(&mut system)
.map_err(|_| "Could not determine parent process")?;
if parent_process.name() == "app" {
parent_process.kill(Signal::Kill);
std::thread::sleep(std::time::Duration::from_secs(1));
std::process::Command::new(app_command)
.spawn()
.map_err(|_| "Could not start app")?;
}
Ok(())
}
fn run_updater() -> Result<(), String> {
let app_command = tauri::command::relative_command("app".to_string())
.map_err(|_| "Could not determine app path")?;
update()?;
restart_app(app_command)?;
Ok(())
}
fn main() {
match run_updater() {
Ok(_) => {}
Err(err) => panic!(err),
};
}