connect GUI to pijul to display simple channel list

CrepeGoat
Oct 8, 2024, 10:23 PM
4RPYR65C4IEKV3INJ67NN4DOH37UDY45EE7VGF55ZKDFH75LXLJAC

Dependencies

  • [2] NSE6BLWA init slint project from https://github.com/slint-ui/slint-rust-template
  • [*] NCRTU7M4 cargo init

Change contents

  • replacement in ui/app-window.slint at line 4
    [2.161][2.161:239]()
    in-out property <int> counter: 42;
    callback request-increase-value();
    [2.161]
    [2.239]
    in-out property <string> channel_list: "";
    callback request-channel-list();
  • replacement in ui/app-window.slint at line 8
    [2.272][2.272:318]()
    text: "Counter: \{root.counter}";
    [2.272]
    [2.318]
    text: "channels: \n\{root.channel_list}";
  • replacement in ui/app-window.slint at line 12
    [2.346][2.346:382]()
    text: "Increase value";
    [2.346]
    [2.382]
    text: "Refresh";
  • replacement in ui/app-window.slint at line 14
    [2.407][2.407:454]()
    root.request-increase-value();
    [2.407]
    [2.454]
    root.request-channel-list();
  • edit in src/main.rs at line 3
    [2.709]
    [2.709]
    mod cmds;
    use std::path::Path;
  • replacement in src/main.rs at line 8
    [2.710][2.710:733]()
    use std::error::Error;
    [2.710]
    [2.733]
    use anyhow::Error;
    use cmds::channel;
    use slint::SharedString;
  • replacement in src/main.rs at line 14
    [2.762][2.762:804]()
    fn main() -> Result<(), Box<dyn Error>> {
    [2.762]
    [2.804]
    fn main() -> Result<(), Error> {
  • replacement in src/main.rs at line 17
    [2.837][2.837:872]()
    ui.on_request_increase_value({
    [2.837]
    [2.872]
    ui.on_request_channel_list({
  • replacement in src/main.rs at line 21
    [2.969][2.969:1019]()
    ui.set_counter(ui.get_counter() + 1);
    [2.969]
    [2.1019]
    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
    [2.1308]
    [2.1308]
    anyhow = "1.0.89"
    thiserror = "1.0.64"
  • edit in Cargo.lock at line 192
    [2.6025]
    [2.6025]
    [[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
    [2.69755]
    [2.69755]
    "anyhow",
  • edit in Cargo.lock at line 2806
    [2.69781]
    [2.69781]
    "thiserror",