mirror of
https://github.com/velopack/velopack.git
synced 2025-10-25 15:19:22 +00:00
Fix Iced sample
This commit is contained in:
4699
samples/RustIced/Cargo.lock
generated
Normal file
4699
samples/RustIced/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
17
samples/RustIced/Cargo.toml
Normal file
17
samples/RustIced/Cargo.toml
Normal file
@@ -0,0 +1,17 @@
|
||||
[package]
|
||||
name = "velorusticedsample"
|
||||
version = "0.0.1"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0"
|
||||
iced = { version = "0.13", features = ["async-std", "debug"] }
|
||||
async-std = "1.5"
|
||||
once_cell = "1.19"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
uuid = { version = "1.0", features = ["v4", "fast-rng", "serde"] }
|
||||
directories-next = "2.0"
|
||||
tracing-subscriber = "0.3"
|
||||
velopack = { path = "../../src/lib-rust", features = ["async"] }
|
||||
BIN
samples/RustIced/Velopack.icns
Normal file
BIN
samples/RustIced/Velopack.icns
Normal file
Binary file not shown.
BIN
samples/RustIced/Velopack.png
Normal file
BIN
samples/RustIced/Velopack.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.4 KiB |
26
samples/RustIced/build-osx.sh
Normal file
26
samples/RustIced/build-osx.sh
Normal file
@@ -0,0 +1,26 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Find the absolute path of the script
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
|
||||
# Check if version parameter is provided
|
||||
if [ "$#" -ne 1 ]; then
|
||||
echo "Version number is required."
|
||||
echo "Usage: ./build.sh [version]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
BUILD_VERSION="$1"
|
||||
RELEASE_DIR="$SCRIPT_DIR/releases"
|
||||
PUBLISH_DIR="$SCRIPT_DIR/publish"
|
||||
ICON_PATH="$SCRIPT_DIR/Velopack.icns"
|
||||
|
||||
echo ""
|
||||
echo "Compiling Rust/Iced with cargo..."
|
||||
cargo build -r
|
||||
mkdir publish
|
||||
cp target/release/velorusticedsample publish/VeloRustIcedSample
|
||||
|
||||
echo ""
|
||||
echo "Building Velopack Release v$BUILD_VERSION"
|
||||
vpk pack -u VeloRustIcedSample -v $BUILD_VERSION -o "$RELEASE_DIR" -p "$PUBLISH_DIR" -i "$ICON_PATH"
|
||||
20
samples/RustIced/build-win.bat
Normal file
20
samples/RustIced/build-win.bat
Normal file
@@ -0,0 +1,20 @@
|
||||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
if "%~1"=="" (
|
||||
echo Version number is required.
|
||||
echo Usage: build.bat [version] [extra_args...]
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
cd %~dp0
|
||||
|
||||
echo.
|
||||
echo Building Iced/Rust
|
||||
cargo build
|
||||
|
||||
echo.
|
||||
echo Building Velopack Release v%~1
|
||||
mkdir publish
|
||||
move target\debug\velorusticedsample.exe publish\velorusticedsample.exe
|
||||
vpk pack -u VeloRustIcedSample -o releases -p publish -v %*
|
||||
7
samples/RustIced/build.rs
Normal file
7
samples/RustIced/build.rs
Normal file
@@ -0,0 +1,7 @@
|
||||
use std::path::Path;
|
||||
|
||||
fn main() {
|
||||
let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap();
|
||||
let releases_dir = Path::new(&manifest_dir).join("releases");
|
||||
println!("cargo:rustc-env=RELEASES_DIR={}", releases_dir.to_string_lossy());
|
||||
}
|
||||
127
samples/RustIced/src/main.rs
Normal file
127
samples/RustIced/src/main.rs
Normal file
@@ -0,0 +1,127 @@
|
||||
#![windows_subsystem = "windows"]
|
||||
use anyhow::Result;
|
||||
use iced::widget::{Button, Column, Text};
|
||||
|
||||
use velopack::*;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Message {
|
||||
CheckForUpdates,
|
||||
UpdatesFound(Option<UpdateInfo>),
|
||||
DownloadUpdates,
|
||||
DownloadProgress(i16),
|
||||
DownloadComplete,
|
||||
Restart,
|
||||
}
|
||||
|
||||
pub struct GUI {
|
||||
update_manager: Option<UpdateManager>,
|
||||
state: GUIState,
|
||||
current_version: Option<String>,
|
||||
update_info: Option<UpdateInfo>,
|
||||
download_progress: i16,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum GUIState {
|
||||
NotInstalled,
|
||||
Idle,
|
||||
Checking,
|
||||
UpdatesAvailable,
|
||||
Downloading,
|
||||
ReadyToRestart,
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
VelopackApp::build().run();
|
||||
|
||||
let source = sources::FileSource::new(env!("RELEASES_DIR"));
|
||||
let um = UpdateManager::new(source, None, None);
|
||||
let mut version: Option<String> = None;
|
||||
let mut state = GUIState::NotInstalled;
|
||||
if um.is_ok() {
|
||||
state = GUIState::Idle;
|
||||
version = Some(um.as_ref().unwrap().current_version().unwrap());
|
||||
}
|
||||
|
||||
let gui = GUI { update_manager: um.ok(), state, current_version: version, update_info: None, download_progress: 0 };
|
||||
|
||||
iced::application("A cool application", update, view)
|
||||
.window_size(iced::Size::new(400.0, 200.0))
|
||||
.run_with(move || (gui, iced::Task::none()))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn update(gui: &mut GUI, message: Message) -> iced::Task<Message> {
|
||||
match message {
|
||||
Message::CheckForUpdates => {
|
||||
gui.state = GUIState::Checking;
|
||||
iced::Task::perform(gui.update_manager.as_ref().unwrap().check_for_updates_async(), |result| match result {
|
||||
Ok(update_info) => {
|
||||
match update_info {
|
||||
UpdateCheck::RemoteIsEmpty => Message::UpdatesFound(None),
|
||||
UpdateCheck::NoUpdateAvailable => Message::UpdatesFound(None),
|
||||
UpdateCheck::UpdateAvailable(updates) => Message::UpdatesFound(Some(updates)),
|
||||
}
|
||||
},
|
||||
Err(_) => {
|
||||
// Handle the error case, perhaps by logging or setting an error state
|
||||
// For simplicity, we're sending a None update here, but you should handle errors appropriately
|
||||
Message::UpdatesFound(None)
|
||||
}
|
||||
})
|
||||
}
|
||||
Message::UpdatesFound(update) => {
|
||||
gui.update_info = update;
|
||||
gui.state = match gui.update_info {
|
||||
Some(_) => GUIState::UpdatesAvailable,
|
||||
None => GUIState::Idle,
|
||||
};
|
||||
iced::Task::none()
|
||||
}
|
||||
Message::DownloadUpdates => {
|
||||
gui.state = GUIState::Downloading;
|
||||
let update_info = gui.update_info.clone().unwrap(); // Ensure you handle this safely in your actual code
|
||||
iced::Task::perform(gui.update_manager.as_ref().unwrap().download_updates_async(&update_info, None), |_| Message::DownloadComplete)
|
||||
}
|
||||
Message::DownloadProgress(progress) => {
|
||||
gui.download_progress = progress;
|
||||
iced::Task::none()
|
||||
}
|
||||
Message::DownloadComplete => {
|
||||
gui.state = GUIState::ReadyToRestart;
|
||||
iced::Task::none()
|
||||
}
|
||||
Message::Restart => {
|
||||
let update_info = gui.update_info.clone().unwrap(); // Ensure you handle this safely in your actual code
|
||||
gui.update_manager.as_ref().unwrap().apply_updates_and_restart(update_info).unwrap();
|
||||
iced::Task::none()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn view(gui: &GUI) -> iced::Element<Message> {
|
||||
let content = match gui.state {
|
||||
GUIState::NotInstalled => Column::new()
|
||||
.push(Text::new("Can't check for updates if not installed")),
|
||||
GUIState::Idle => Column::new()
|
||||
.push(Text::new(format!("Current version: {}", gui.current_version.as_ref().unwrap_or(&"Unknown".to_string()))))
|
||||
.push(Button::new(Text::new("Check for updates")).on_press(Message::CheckForUpdates)),
|
||||
GUIState::Checking => Column::new()
|
||||
.push(Text::new("Checking for updates...")),
|
||||
GUIState::UpdatesAvailable => {
|
||||
let update_version = gui.update_info.as_ref().map_or("Unknown", |info| &info.TargetFullRelease.Version);
|
||||
Column::new()
|
||||
.push(Text::new(format!("Update available: {}", update_version)))
|
||||
.push(Button::new(Text::new("Download updates")).on_press(Message::DownloadUpdates))
|
||||
}
|
||||
GUIState::Downloading => Column::new()
|
||||
.push(Text::new(format!("Downloading updates... Progress: {}%", gui.download_progress))),
|
||||
GUIState::ReadyToRestart => Column::new()
|
||||
.push(Text::new("Updates downloaded. Ready to restart."))
|
||||
.push(Button::new(Text::new("Restart")).on_press(Message::Restart)),
|
||||
};
|
||||
|
||||
content.into()
|
||||
}
|
||||
Reference in New Issue
Block a user