diff --git a/Cargo.toml b/Cargo.toml index 15492bb..06c6ee5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,7 @@ name = "hardware_toolkit" version = "0.1.0" edition = "2024" +build = "build.rs" [dependencies] iced = { git = "https://github.com/iced-rs/iced.git", features = [ @@ -29,3 +30,7 @@ anyhow = { version = "1.0.98", features = ["backtrace"] } log = "0.4.27" env_logger = "0.11.8" iced_fonts = { version = "0.2.1", features = ["full"] } + + +[build-dependencies] +embed-resource = "3.0.3" diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..57788f3 --- /dev/null +++ b/build.rs @@ -0,0 +1,3 @@ +fn main() { + println!("cargo:rustc-link-search=dylib=runtime"); +} diff --git a/runtime/WinSparkle.dll b/runtime/WinSparkle.dll new file mode 100644 index 0000000..36e9351 Binary files /dev/null and b/runtime/WinSparkle.dll differ diff --git a/runtime/WinSparkle.lib b/runtime/WinSparkle.lib new file mode 100644 index 0000000..2fb1606 Binary files /dev/null and b/runtime/WinSparkle.lib differ diff --git a/src/main.rs b/src/main.rs index a9bef08..15c595f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,15 @@ mod ui; mod utils; mod widgets; -mod winsparkle; fn main() { tracing_subscriber::fmt::init(); + unsafe { + use utils::winsparkle::*; + win_sparkle_set_appcast_url( + "https://dl.wuembed.com/hardware_tk/appcast.xml\0".as_ptr() as *const i8 + ); + win_sparkle_init(); + } ui::main_window::main_window(); } diff --git a/src/ui/main_window.rs b/src/ui/main_window.rs index 7ff838e..4db274b 100644 --- a/src/ui/main_window.rs +++ b/src/ui/main_window.rs @@ -31,7 +31,6 @@ struct MainWindow { title: String, theme: iced::Theme, curr_tab: TabId, - tabs: Vec, home_page: crate::ui::home_page::HomePage, jlc_downloader: crate::ui::jlc_downloader::JlcDownloader, db_browser: crate::ui::db_browser::DbBrowser, @@ -45,7 +44,6 @@ impl Default for MainWindow { curr_tab: Default::default(), home_page: Default::default(), jlc_downloader: Default::default(), - tabs: Vec::new(), db_browser: Default::default(), part_viewer: Default::default(), } @@ -81,11 +79,6 @@ pub(crate) enum TabId { DbBrowser, PartViewer, } -#[allow(dead_code)] -struct TabItem { - pub id: TabId, - content: Box Element<'static, MainWindowMsg>>, -} impl Display for TabId { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!( diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 80d2075..711ae84 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1,2 +1,3 @@ pub mod app_settings; pub mod step_downloader; +pub mod winsparkle; diff --git a/src/utils/winsparkle.rs b/src/utils/winsparkle.rs new file mode 100644 index 0000000..6f29f04 --- /dev/null +++ b/src/utils/winsparkle.rs @@ -0,0 +1,64 @@ +// lib.rs +// winsparkle-sys + +#![cfg(target_os = "windows")] + +// Link to the WinSparkle.dll +#[cfg_attr(target_os = "windows", link(name = "WinSparkle", kind = "dylib"))] +#[allow(dead_code)] +unsafe extern "C" { + /// Initialize WinSparkle. + /// + /// This initializes WinSparkle and should be called at application startup. + pub fn win_sparkle_init(); + + /// Clean up after WinSparkle. + /// + /// Should be called at application shutdown. + /// Cancels any pending update checks and shuts down its helper threads. + pub fn win_sparkle_cleanup(); + + /// Set the URL for the appcast file. + /// + /// This specifies the URL where WinSparkle will look for updates. + pub fn win_sparkle_set_appcast_url(url: *const i8); + + /// Set DSA public key. + /// + /// Only PEM format is supported. + /// Public key will be used to verify DSA signatures of the update file. + /// PEM data will be set only if it contains valid DSA public key. + /// + /// If this function isn't called by the app, public key is obtained from + /// Windows resource named "DSAPub" of type "DSAPEM". + /// + /// returns 1 if valid DSA public key provided, 0 otherwise. + pub fn win_sparkle_set_dsa_pub_pem(dsa_pub_pem: *const i8) -> i32; + + /// Set the path in the registry where WinSparkle will store its settings. + /// + /// This sets the path where WinSparkle will store its settings in the registry. + pub fn win_sparkle_set_registry_path(path: *const i8); + + /// Set the callback function for handling shutdown requests. + /// + /// This sets the callback function that WinSparkle will call when it receives a + /// request to shut down the application during an update. + pub fn win_sparkle_set_shutdown_request_callback(callback: Option ()>); + + /// Check for updates with the WinSparkle UI. + /// + /// This checks for updates and displays the WinSparkle UI if an update is available. + pub fn win_sparkle_check_update_with_ui(); + + /// Check for updates with the WinSparkle UI + /// and immediately install the update if one is available. + pub fn win_sparkle_check_update_with_ui_and_install(); + + /// Check for updates. + /// + /// No progress UI is shown to the user when checking. + /// If an update is available, the usual "update available" UI is shown. + /// This function is *not* completely UI-less. + pub fn win_sparkle_check_update_without_ui(); +} diff --git a/src/winsparkle/mod.rs b/src/winsparkle/mod.rs deleted file mode 100644 index e69de29..0000000 diff --git a/src/winsparkle/winsparkle.rs b/src/winsparkle/winsparkle.rs deleted file mode 100644 index e69de29..0000000