mirror of
https://github.com/snowfallorg/nix-software-center.git
synced 2024-09-11 21:27:09 +03:00
Make launch buttons work
This commit is contained in:
parent
4f168a95b5
commit
d2060474a4
12
Cargo.lock
generated
12
Cargo.lock
generated
@ -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"
|
||||
|
@ -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"]
|
||||
|
@ -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"],
|
||||
}
|
||||
|
@ -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::<RunActionGroup>::new();
|
||||
let launchaction: RelmAction<LaunchAction> = {
|
||||
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<TermShellAction> = {
|
||||
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");
|
||||
|
Loading…
Reference in New Issue
Block a user