connect GUI to pijul to display simple channel list
Dependencies
- [2]
NSE6BLWAinit slint project from https://github.com/slint-ui/slint-rust-template - [*]
NCRTU7M4cargo init
Change contents
- replacement in ui/app-window.slint at line 4
in-out property <int> counter: 42;callback request-increase-value();in-out property <string> channel_list: "";callback request-channel-list(); - replacement in ui/app-window.slint at line 8
text: "Counter: \{root.counter}";text: "channels: \n\{root.channel_list}"; - replacement in ui/app-window.slint at line 12
text: "Increase value";text: "Refresh"; - replacement in ui/app-window.slint at line 14
root.request-increase-value();root.request-channel-list(); - edit in src/main.rs at line 3
mod cmds;use std::path::Path; - replacement in src/main.rs at line 8
use std::error::Error;use anyhow::Error;use cmds::channel;use slint::SharedString; - replacement in src/main.rs at line 14
fn main() -> Result<(), Box<dyn Error>> {fn main() -> Result<(), Error> { - replacement in src/main.rs at line 17
ui.on_request_increase_value({ui.on_request_channel_list({ - replacement in src/main.rs at line 21
ui.set_counter(ui.get_counter() + 1);let channel_output = channel(Path::new("/Users/beckerawqatty/.nix-profile/bin/pijul"),Path::new("/Users/beckerawqatty/Repos/pijul-gui/"),);let channel_list = match channel_output {Ok(channel_list) => channel_list,Err(e) => {println!("{:?}", e);return;}};ui.set_channel_list(SharedString::from(&channel_list)); - file addition: cmds.rs[4.15]
use anyhow::Error;use std::process::{Command, ExitStatus};pub fn channel(exe: &std::path::Path, repo: &std::path::Path) -> Result<String, Error> {let mut cmd = Command::new(exe);let cmd = cmd.arg("channel").arg("--no-prompt").arg("--repository").arg(repo);let output = cmd.output()?;check_exit_status(cmd, output.status)?;Ok(String::from_utf8(output.stdout)?)}fn check_exit_status(cmd: &Command, exit_status: ExitStatus) -> Result<(), Error> {if exit_status.success() {Ok(())} else {Err(Error::from(ExecutionError {command: format!("{:?}", cmd),exit_code: exit_status.code(),}))}}/// Execution of a [`Command`] finished with an unsuccessful error code.#[derive(Debug, Clone, PartialEq, thiserror::Error)]#[error("Received an exit code of {} from {}", exit_code.unwrap_or(1), command)]pub struct ExecutionError {pub command: String,pub exit_code: Option<i32>,} - edit in Cargo.toml at line 10
anyhow = "1.0.89"thiserror = "1.0.64" - edit in Cargo.lock at line 192
[[package]]name = "anyhow"version = "1.0.89"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" - edit in Cargo.lock at line 2803
"anyhow", - edit in Cargo.lock at line 2806
"thiserror",