🚧 add the actual instal/remove script
This commit is contained in:
parent
b2deafa69b
commit
5be4a75d7b
|
@ -1,6 +1,7 @@
|
|||
#!/bin/sh
|
||||
|
||||
mkdir -p "${DESTDIR}/${MESON_INSTALL_PREFIX}/share/cachyos-hello/"
|
||||
cp -r "${MESON_SOURCE_ROOT}/src/scripts" "${DESTDIR}/${MESON_INSTALL_PREFIX}/share/cachyos-hello/"
|
||||
cp -r "${MESON_SOURCE_ROOT}/data" "${DESTDIR}/${MESON_INSTALL_PREFIX}/share/cachyos-hello/"
|
||||
cp -r "${MESON_SOURCE_ROOT}/ui" "${DESTDIR}/${MESON_INSTALL_PREFIX}/share/cachyos-hello/"
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
use crate::utils;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[repr(C)]
|
||||
pub struct AlpmHelper {
|
||||
|
@ -76,18 +78,18 @@ impl AlpmHelper {
|
|||
}
|
||||
|
||||
fn install_apps(&self, pkg_list: &Vec<String>, install: bool) -> bool {
|
||||
let mut install_arg: &str = "";
|
||||
let mut install_arg: &str = "-Sy";
|
||||
if pkg_list.is_empty() {
|
||||
return false;
|
||||
} else if !install {
|
||||
install_arg = "-R";
|
||||
}
|
||||
|
||||
println!("pacman {} {:?}", install_arg, pkg_list);
|
||||
|
||||
let packages_do = pkg_list.iter().map(|s| s.to_string() + " ").collect::<String>();
|
||||
let _ = utils::run_cmd_terminal(format!("pacman {} {}", install_arg, packages_do), true);
|
||||
match install {
|
||||
true => !self.app_installed(&pkg_list[0]),
|
||||
false => self.app_installed(&pkg_list[0]),
|
||||
true => self.app_installed(&pkg_list[0]),
|
||||
false => !self.app_installed(&pkg_list[0]),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -193,6 +193,7 @@ impl ApplicationBrowser {
|
|||
self.app_store.clear();
|
||||
|
||||
if refresh {
|
||||
self.alpm_handle = new_alpm().unwrap();
|
||||
self.group_store = load_groups_data(&self.groups);
|
||||
}
|
||||
self.load_app_data();
|
||||
|
|
61
src/pages.rs
61
src/pages.rs
|
@ -11,67 +11,6 @@ use gtk::prelude::*;
|
|||
|
||||
use std::str;
|
||||
use subprocess::{Exec, Redirection};
|
||||
// static mut g_app_browser: Lazy<Mutex<ApplicationBrowser>> =
|
||||
// Lazy::new(|| Mutex::new(ApplicationBrowser::new()));
|
||||
|
||||
// pub fn create_appbrowser_page() -> gtk::Box {
|
||||
// NOTE: we might not even need that here
|
||||
// let app_browser_box = ApplicationBrowser::default_impl().create_page();
|
||||
// let app_browser_box = ApplicationBrowser::default_impl().lock().expect("Initialization
|
||||
// failed!").create_page();
|
||||
|
||||
// let app_browser_box = gtk::Box::new(gtk::Orientation::Vertical, 10);
|
||||
// app_browser_box.set_expand(true);
|
||||
|
||||
// let button_box = gtk::Box::new(gtk::Orientation::Horizontal, 10);
|
||||
// let advanced_button = gtk::Button::with_label("advanced");
|
||||
// advanced_button.set_tooltip_text(Some("Toggle an extended selection of packages"));
|
||||
// advanced_button.connect_clicked(on_advanced_clicked);
|
||||
// let download_button = gtk::Button::with_label("download");
|
||||
// download_button.set_tooltip_text(Some("Download the most recent selection of packages"));
|
||||
// download_button.connect_clicked(on_download_clicked);
|
||||
// let reset_button = gtk::Button::with_label("reset");
|
||||
// reset_button.set_tooltip_text(Some("Reset your current selections..."));
|
||||
// reset_button.connect_clicked(on_reload_clicked);
|
||||
// let update_system_button = unsafe { g_app_browser.lock().unwrap().update_system_btn };
|
||||
|
||||
// Group filter
|
||||
// let data = fs::read_to_string(format!("{}/data/application_utility/default.json",
|
||||
// PKGDATADIR)) .expect("Unable to read file");
|
||||
// let groups: serde_json::Value = serde_json::from_str(&data).expect("Unable to parse");
|
||||
// let group_store = load_groups_data(&groups);
|
||||
// let group_combo = utils::create_combo_with_model(&group_store);
|
||||
|
||||
// Packing button box
|
||||
// button_box.pack_start(&advanced_button, false, false, 10);
|
||||
// button_box.pack_start(&group_combo, false, false, 10);
|
||||
// button_box.pack_end(&update_system_button, false, false, 10);
|
||||
|
||||
// button_box.pack_end(&reset_button, false, false, 10);
|
||||
// button_box.pack_end(&download_button, false, false, 10);
|
||||
// app_browser_box.pack_start(&button_box, false, false, 10);
|
||||
|
||||
// create view and app store
|
||||
// let (tree_view, app_store_size) = create_view_tree(&groups);
|
||||
|
||||
// create a scrollable window
|
||||
// let app_window = gtk::ScrolledWindow::new(gtk::Adjustment::NONE, gtk::Adjustment::NONE);
|
||||
// app_window.set_vexpand(true);
|
||||
// app_window.set_policy(gtk::PolicyType::Never, gtk::PolicyType::Automatic);
|
||||
// add window to tree view
|
||||
// app_window.add(&tree_view);
|
||||
|
||||
// // setup grid
|
||||
// let grid_inter = gtk::Grid::new();
|
||||
// grid_inter.set_column_homogeneous(true);
|
||||
// grid_inter.set_row_homogeneous(true);
|
||||
// // add grid to app browser
|
||||
// app_browser_box.add(&grid_inter);
|
||||
// grid_inter.attach(&app_window, 0, 0, 5, app_store_size as i32);
|
||||
//
|
||||
// app_browser_box
|
||||
// gtk::Box::new(gtk::Orientation::Vertical, 10)
|
||||
//}
|
||||
|
||||
static mut g_local_units: Lazy<Mutex<SystemdUnits>> = Lazy::new(|| Mutex::new(SystemdUnits::new()));
|
||||
static mut g_global_units: Lazy<Mutex<SystemdUnits>> =
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/bash
|
||||
|
||||
exec bash $@
|
|
@ -0,0 +1,64 @@
|
|||
#!/usr/bin/bash
|
||||
#
|
||||
###
|
||||
# This code has been taken from Garuda
|
||||
# Its is only temporal implementation
|
||||
###
|
||||
#
|
||||
# This script tries to exec a terminal emulator by trying some known terminal
|
||||
# emulators.
|
||||
#
|
||||
# Invariants:
|
||||
# 1. $TERMINAL must come first
|
||||
# 2. Distribution-specific mechanisms come next, e.g. x-terminal-emulator
|
||||
# 3. The terminal emulator with best accessibility comes first.
|
||||
# 4. No order is guaranteed/desired for the remaining terminal emulators.
|
||||
|
||||
set -e
|
||||
LAUNCHER_CMD=bash
|
||||
|
||||
usage() {
|
||||
echo "Usage: ${0##*/} [cmd]"
|
||||
echo ' -s [shell] Change shell to [shell]'
|
||||
echo ' -h This help'
|
||||
exit 1
|
||||
}
|
||||
|
||||
opts='s:h'
|
||||
|
||||
while getopts "${opts}" arg; do
|
||||
case "${arg}" in
|
||||
s) LAUNCHER_CMD="$OPTARG" ;;
|
||||
h|?) usage 0 ;;
|
||||
*) echo "invalid argument '${arg}'"; usage 1 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
shift $(($OPTIND - 1))
|
||||
|
||||
file="$(mktemp)"
|
||||
echo "$1" > "$file"
|
||||
cmd="${LAUNCHER_CMD} \"$file\""
|
||||
echo $cmd
|
||||
|
||||
#declare -a terminals=(x-terminal-emulator mate-terminal gnome-terminal terminator xfce4-terminal urxvt rxvt termit Eterm aterm uxterm xterm roxterm termite lxterminal terminology st qterminal lilyterm tilix terminix konsole kitty guake tilda alacritty)
|
||||
terminal=""
|
||||
declare -A terminals=( ["alacritty"]="alacritty -e $cmd || LIBGL_ALWAYS_SOFTWARE=1 alacritty -e $cmd" ["konsole"]="konsole -e $cmd" ["gnome-terminal"]="gnome-terminal --wait -- $cmd" ["xfce4-terminal"]="xfce4-terminal --disable-server --command '$cmd'" ["lxterminal"]="lxterminal -e $cmd" ["xterm"]="xterm -e $cmd" ["st"]="st $cmd")
|
||||
declare -a term_order=( "alacritty" "konsole" "gnome-terminal" "xfce4-terminal" "lxterminal" "xterm" "st")
|
||||
|
||||
if [ -z "$terminal" ] || ! command -v "$terminal" &> /dev/null; then
|
||||
for entry in ${term_order[@]}; do
|
||||
if command -v "$entry" > /dev/null 2>&1; then
|
||||
terminal="$entry"
|
||||
break;
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [ -z "$terminal" ]; then
|
||||
notify-send -t 1500 --app-name=CachyOS "No terminal installed" "Could not find a terminal emulator. Please install one."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
eval "${terminals[${terminal}]}" || { rm "$file"; exit 2; }
|
||||
rm "$file"
|
18
src/utils.rs
18
src/utils.rs
|
@ -2,6 +2,8 @@ use gtk::prelude::*;
|
|||
use std::fs::File;
|
||||
use std::{fs, slice, str};
|
||||
|
||||
use subprocess::{Exec, Redirection};
|
||||
|
||||
#[inline]
|
||||
pub fn fix_path(path: &str) -> String {
|
||||
if !path.starts_with('~') {
|
||||
|
@ -65,6 +67,22 @@ pub fn create_combo_with_model(group_store: >k::ListStore) -> gtk::ComboBox {
|
|||
group_combo
|
||||
}
|
||||
|
||||
pub fn run_cmd_terminal(cmd: String, escalate: bool) -> bool {
|
||||
let cmd_formated = format!("{}; read -p 'Press enter to exit'", cmd);
|
||||
let mut args: Vec<&str> = vec![];
|
||||
if escalate {
|
||||
args.extend_from_slice(&["-s", "pkexec /usr/share/cachyos-hello/scripts/rootshell.sh"]);
|
||||
}
|
||||
args.push(cmd_formated.as_str());
|
||||
|
||||
let exit_status = Exec::cmd("/usr/share/cachyos-hello/scripts/terminal-helper")
|
||||
.args(args.as_slice())
|
||||
.stdout(Redirection::Pipe)
|
||||
.join()
|
||||
.unwrap();
|
||||
exit_status.success()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
|
Loading…
Reference in New Issue