From d2060474a4aa0ae7717841316a573aec3d544a4e Mon Sep 17 00:00:00 2001 From: Victor Fuentes Date: Wed, 7 Sep 2022 19:34:20 -0400 Subject: [PATCH] Make launch buttons work --- Cargo.lock | 12 ++++++ Cargo.toml | 1 + src/ui/about.rs | 2 +- src/ui/pkgpage.rs | 96 +++++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 106 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3deb418..94c558c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1509,6 +1509,7 @@ dependencies = [ "strum_macros", "tokio", "tracker", + "which", ] [[package]] @@ -2993,6 +2994,17 @@ version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9193164d4de03a926d909d3bc7c30543cecb35400c02114792c2cae20d5e2dbb" +[[package]] +name = "which" +version = "4.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c831fbbee9e129a8cf93e7747a82da9d95ba8e16621cae60ec2cdc849bacb7b" +dependencies = [ + "either", + "libc", + "once_cell", +] + [[package]] name = "winapi" version = "0.3.9" diff --git a/Cargo.toml b/Cargo.toml index 50f413b..d31fa2b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,6 +34,7 @@ edit-distance = "2.1" ijson = "0.1" strum = "0.24" strum_macros = "0.24" +which = "4.3" [workspace] members = [".", "nsc-helper"] diff --git a/src/ui/about.rs b/src/ui/about.rs index 96c2570..7253bd0 100644 --- a/src/ui/about.rs +++ b/src/ui/about.rs @@ -33,7 +33,7 @@ impl SimpleComponent for AboutPageModel { set_developer_name: "Victor Fuentes", set_version: env!("CARGO_PKG_VERSION"), set_issue_url: "https://github.com/vlinkz/nix-software-center/issues", - set_license_type: gtk::License::MitX11, + set_license_type: gtk::License::Gpl30, set_website: "https://github.com/vlinkz/nix-software-center", set_developers: &["Victor Fuentes https://github.com/vlinkz"], } diff --git a/src/ui/pkgpage.rs b/src/ui/pkgpage.rs index ff445d4..e7a912a 100644 --- a/src/ui/pkgpage.rs +++ b/src/ui/pkgpage.rs @@ -155,6 +155,8 @@ pub enum PkgMsg { FinishedProcess(WorkPkg), FailedProcess(WorkPkg), Launch, + NixRun, + NixShell, SetInstallType(InstallType), AddToQueue(WorkPkg), } @@ -1024,18 +1026,18 @@ impl Component for PkgModel { let rungroup = RelmActionGroup::::new(); let launchaction: RelmAction = { - let _sender = sender.clone(); + let sender = sender.clone(); RelmAction::new_stateless(move |_| { println!("LAUNCH!"); - // sender.input(AppMsg::Increment); + sender.input(PkgMsg::NixRun); }) }; let termaction: RelmAction = { - let _sender = sender; + let sender = sender; RelmAction::new_stateless(move |_| { println!("TERM!"); - // sender.input(AppMsg::Increment); + sender.input(PkgMsg::NixShell) }) }; @@ -1490,6 +1492,65 @@ impl Component for PkgModel { } } } + PkgMsg::NixRun => { + println!("NIXRUN!"); + if let Some(l) = &self.launchable { + match l { + Launch::GtkApp(x) => { + match self.userpkgtype { + UserPkgs::Env => { + let _ = Command::new("nix-shell") + .arg("-p") + .arg(&self.pkg) + .arg("--command") + .arg(&format!("XDG_DATA_DIRS=$XDG_DATA_DIRS:$buildInputs/share gtk-launch {}", x)) + .spawn(); + } + UserPkgs::Profile => { + let _ = Command::new("nix") + .arg("shell") + .arg(&format!("nixpkgs#{}", self.pkg)) + .arg("--command") + .arg(&format!("env XDG_DATA_DIRS=$XDG_DATA_DIRS:$(nix eval nixpkgs#{}.outPath --raw)/share gtk-launch {}", self.pkg, x)) + .spawn(); + } + } + } + Launch::TerminalApp(x) => { + let cmd = match self.userpkgtype { + UserPkgs::Env => { + format!("nix-shell -p {} --command \"{}; $SHELL\"", self.pkg, x) + } + UserPkgs::Profile => { + format!("nix shell nixpkgs#{} --command \"{}; $SHELL\"", self.pkg, x) + } + }; + launchterm(&cmd); + } + } + } else { + let cmd = match self.userpkgtype { + UserPkgs::Env => { + format!("nix-shell -p {} --command \"{}; $SHELL\"", self.pkg, self.pname) + } + UserPkgs::Profile => { + format!("nix shell nixpkgs#{} --command \"{}; $SHELL\"", self.pkg, self.pname) + } + }; + launchterm(&cmd); + } + } + PkgMsg::NixShell => { + let cmd = match self.userpkgtype { + UserPkgs::Env => { + format!("nix-shell -p {}", self.pkg) + } + UserPkgs::Profile => { + format!("nix shell nixpkgs#{}", self.pkg) + } + }; + launchterm(&cmd); + } PkgMsg::SetInstallType(t) => { self.set_installtype(t); } @@ -1514,6 +1575,33 @@ impl Component for PkgModel { } } +fn launchterm(cmd: &str) { + if which::which("kgx").is_ok() { + println!("LAUNCHING WITH KGX"); + let _ = Command::new("kgx").arg("-e").arg(&cmd).spawn(); + } else if which::which("gnome-terminal").is_ok() { + let _ = Command::new("gnome-terminal").arg("--").arg(&cmd).spawn(); + } else if which::which("konsole").is_ok() { + let _ = Command::new("konsole").arg("-e").arg(&cmd).spawn(); + } else if which::which("mate-terminal").is_ok() { + let _ = Command::new("mate-terminal").arg("-e").arg(&cmd).spawn(); + } else if which::which("xfce4-terminal").is_ok() { + let _ = Command::new("xfce4-terminal").arg("-e").arg(&cmd).spawn(); + } else if which::which("tilix").is_ok() { + let _ = Command::new("tilix").arg("-e").arg(&cmd).spawn(); + } else if which::which("terminology").is_ok() { + let _ = Command::new("terminology").arg("-e").arg(&cmd).spawn(); + } else if which::which("alacritty").is_ok() { + let _ = Command::new("alacritty").arg("-e").arg(&cmd).spawn(); + } else if which::which("urxvt").is_ok() { + let _ = Command::new("urxvt").arg("-e").arg(&cmd).spawn(); + } else if which::which("xterm").is_ok() { + let _ = Command::new("xterm").arg("-e").arg(&cmd).spawn(); + } else { + eprintln!("No terminal detected!") + } +} + relm4::new_action_group!(ModeActionGroup, "mode"); relm4::new_stateless_action!(NixEnvAction, ModeActionGroup, "env"); relm4::new_stateless_action!(NixProfileAction, ModeActionGroup, "profile");