update react examples

This commit is contained in:
tensor-programming
2019-12-24 14:03:16 -05:00
parent 8d422294f4
commit cce215f97e
6 changed files with 44 additions and 82 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"
@@ -22,13 +23,14 @@ icon = [
[dependencies]
serde_json = "1.0.41"
serde = "1.0"
serde_derive = "1.0"
serde = "1.0.104"
serde_derive = "1.0.104"
tiny_http = "0.6"
phf = "0.7.24"
includedir = "0.5.0"
tauri = { version = "0.2.0", features = [ "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,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),
};
}

View File

@@ -9,6 +9,7 @@ license = ""
repository = ""
default-run = "gatsby-themed-site-app"
edition = "2018"
build = "src/build.rs"
[package.metadata.bundle]
identifier = "com.tauri.dev"
@@ -21,21 +22,20 @@ 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 = { version = "0.2.0", features = [ "edge" ] }
[dependencies.tauri]
path = "../../../../tauri"
features = [ "edge" ]
[target."cfg(windows)".build-dependencies]
winres = "0.1"
[features]
dev-server = [ "tauri/dev-server" ]
embedded-server = [ "tauri/embedded-server" ]
no-server = [ "tauri/no-server" ]
[[bin]]
name = "gatsby-themed-site-app"
name = "app"
path = "src/main.rs"

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]