🚧 add new options & fix icons

This commit is contained in:
Vladislav Nepogodin 2022-07-06 01:32:12 +04:00
parent b80bfe5d3f
commit 921831da15
No known key found for this signature in database
GPG Key ID: B62C3D10C54D5DA9
10 changed files with 176 additions and 44 deletions

View File

@ -5,7 +5,7 @@ Categories=GNOME;GTK;System;
StartupNotify=false
Name=CachyOS Hello
Exec=/usr/bin/cachyos-hello
Icon=cachyos
Icon=org.cachyos.hello
Comment=A tool providing access to documentation and support for new CachyOS users.
Comment[da]=En app med adgang til dokumentation og support for nye CachyOS brugere.
Comment[de]=Ein Tool für schnellen Zugriff auf Support und Dokumentation für neue CachyOS-Nutzer.
@ -17,4 +17,4 @@ Comment[pt_BR]=Uma ferramenta que fornece acesso à documentação e suporte par
Comment[pt_PT]=Uma ferramenta que fornece acesso à documentação e suporte para novos usuários CachyOS.
Comment[ru]=Средство доступа к документации и поддержке для новых пользователей CachyOS.
Comment[it]=Strumento per accedere alla documentazione e supporto per nuovi utenti CachyOS.
Comment[tr]=Yeni CachyOS kullanıcıları için dökümantasyon ve destek sağlayan bir araç.
Comment[tr]=Yeni CachyOS kullanıcıları için dökümantasyon ve destek sağlayan bir araç.

View File

@ -6,7 +6,7 @@
"installer_path": "/usr/bin/calamares",
"live_path": "/run/archiso/bootmnt/arch",
"locale_path": "/usr/share/locale/",
"logo_path": "/usr/share/icons/hicolor/64x64/apps/cachyos.png",
"logo_path": "/usr/share/icons/hicolor/scalable/apps/",
"save_path": "~/.config/cachyos-hello.json",
"ui_path": "/usr/share/cachyos-hello/ui/cachyos-hello.glade",
"style_path": "/usr/share/cachyos-hello/ui/style.css",

4
icons/meson.build Normal file
View File

@ -0,0 +1,4 @@
install_data(
'@0@.svg'.format(application_id),
install_dir: iconsdir / 'hicolor' / 'scalable' / 'apps'
)

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 7.1 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 6.1 KiB

View File

@ -1,5 +1,6 @@
#![feature(const_slice_from_raw_parts)]
#![feature(const_str_from_utf8)]
#![feature(string_remove_matches)]
#![allow(non_upper_case_globals)]
mod alpm_helper;
@ -74,13 +75,16 @@ fn show_about_dialog() {
unsafe {
main_window = g_hello_window.clone().unwrap().window.clone();
}
let logo_path = format!("/usr/share/icons/hicolor/scalable/apps/{}.svg", APP_ID);
let logo = Pixbuf::from_file(logo_path).unwrap();
let dialog = gtk::AboutDialog::builder()
.transient_for(&main_window)
.modal(true)
.program_name(&gettextrs::gettext("CachyOS Hello"))
.comments(&gettextrs::gettext("Welcome screen for CachyOS"))
.version(VERSION)
.logo_icon_name(APP_ID)
.logo(&logo)
.authors(vec![
"Vladislav Nepogodin".into(),
])
@ -133,14 +137,14 @@ fn build_ui(application: &gtk::Application) {
// Import Css
let provider = gtk::CssProvider::new();
provider.load_from_path(preferences["style_path"].as_str().unwrap()).unwrap();
if let Some(screen) = gdk::Screen::default() {
gtk::StyleContext::add_provider_for_screen(
&screen,
&provider,
gtk::STYLE_PROVIDER_PRIORITY_APPLICATION,
);
}
provider
.load_from_path(preferences["style_path"].as_str().unwrap())
.expect("Failed to load CSS");
gtk::StyleContext::add_provider_for_screen(
&gdk::Screen::default().expect("Error initializing gtk css provider."),
&provider,
gtk::STYLE_PROVIDER_PRIORITY_APPLICATION,
);
// Init window
let builder: Builder = Builder::from_file(preferences["ui_path"].as_str().unwrap());
@ -175,7 +179,7 @@ fn build_ui(application: &gtk::Application) {
header.set_subtitle(Some("CachyOS rolling"));
// Load images
let logo_path = preferences["logo_path"].as_str().unwrap();
let logo_path = format!("{}/{}.svg", preferences["logo_path"].as_str().unwrap(), APP_ID);
if Path::new(&logo_path).exists() {
let logo = Pixbuf::from_file(logo_path).unwrap();
main_window.set_icon(Some(&logo));

View File

@ -1,10 +1,11 @@
// extern crate gtk;
use crate::application_browser::ApplicationBrowser;
use crate::data_types::*;
use crate::utils;
use crate::utils::PacmanWrapper;
use gtk::{glib, Builder};
use once_cell::sync::Lazy;
use std::fmt::Write as _;
use std::path::Path;
use std::sync::Mutex;
use gtk::prelude::*;
@ -16,6 +17,65 @@ static mut g_local_units: Lazy<Mutex<SystemdUnits>> = Lazy::new(|| Mutex::new(Sy
static mut g_global_units: Lazy<Mutex<SystemdUnits>> =
Lazy::new(|| Mutex::new(SystemdUnits::new()));
fn create_fixes_section() -> gtk::Box {
let topbox = gtk::Box::new(gtk::Orientation::Vertical, 2);
let button_box_f = gtk::Box::new(gtk::Orientation::Horizontal, 10);
let button_box_s = gtk::Box::new(gtk::Orientation::Horizontal, 10);
let label = gtk::Label::new(None);
label.set_line_wrap(true);
label.set_justify(gtk::Justification::Center);
label.set_text("Fixes");
let removelock_btn = gtk::Button::with_label("Remove db lock");
let reinstall_btn = gtk::Button::with_label("Reinstall all packages");
let refreshkeyring_btn = gtk::Button::with_label("Refresh keyrings");
let update_system_btn = gtk::Button::with_label("System update");
let remove_orphans_btn = gtk::Button::with_label("Remove orphans");
let clear_pkgcache_btn = gtk::Button::with_label("Clear package cache");
removelock_btn.connect_clicked(move |_| {
if Path::new("/var/lib/pacman/db.lck").exists() {
let _ = Exec::cmd("/sbin/pkexec")
.arg("bash")
.arg("-c")
.arg("rm /var/lib/pacman/db.lck")
.join()
.unwrap();
if !Path::new("/var/lib/pacman/db.lck").exists() {
let dialog = gtk::MessageDialog::builder()
.message_type(gtk::MessageType::Info)
.text("Pacman db lock was removed!")
.build();
dialog.show();
}
}
});
reinstall_btn.connect_clicked(move |_| {
let _ = utils::run_cmd_terminal(String::from("pacman -S $(pacman -Qnq)"), true);
});
refreshkeyring_btn.connect_clicked(on_refreshkeyring_btn_clicked);
update_system_btn.connect_clicked(on_update_system_btn_clicked);
remove_orphans_btn.connect_clicked(move |_| {
let _ = utils::run_cmd_terminal(String::from("pacman -Rns $(pacman -Qtdq)"), true);
});
clear_pkgcache_btn.connect_clicked(on_clear_pkgcache_btn_clicked);
topbox.pack_start(&label, true, false, 1);
button_box_f.pack_start(&update_system_btn, true, true, 2);
button_box_f.pack_start(&reinstall_btn, true, true, 2);
button_box_f.pack_end(&refreshkeyring_btn, true, true, 2);
button_box_s.pack_start(&removelock_btn, true, true, 2);
button_box_s.pack_start(&clear_pkgcache_btn, true, true, 2);
button_box_s.pack_end(&remove_orphans_btn, true, true, 2);
button_box_f.set_halign(gtk::Align::Fill);
button_box_s.set_halign(gtk::Align::Fill);
topbox.pack_end(&button_box_s, true, true, 5);
topbox.pack_end(&button_box_f, true, true, 5);
topbox.set_hexpand(true);
topbox
}
fn create_options_section() -> gtk::Box {
let topbox = gtk::Box::new(gtk::Orientation::Vertical, 2);
let box_collection = gtk::Box::new(gtk::Orientation::Horizontal, 10);
@ -62,7 +122,7 @@ fn create_options_section() -> gtk::Box {
box_collection.pack_start(&apparmor_btn, true, false, 2);
box_collection.pack_start(&ananicy_cpp_btn, true, false, 2);
box_collection.set_halign(gtk::Align::Fill);
topbox.pack_start(&box_collection, true, false, 1);
topbox.pack_end(&box_collection, true, false, 1);
topbox.set_hexpand(true);
topbox
@ -85,10 +145,10 @@ fn create_apps_section() -> gtk::Box {
box_collection.pack_start(&cachyos_pi, true, true, 2);
box_collection.pack_start(&cachyos_km, true, true, 2);
topbox.pack_start(&label, true, true, 2);
topbox.pack_start(&label, true, true, 5);
box_collection.set_halign(gtk::Align::Fill);
topbox.pack_start(&box_collection, true, true, 0);
topbox.pack_end(&box_collection, true, true, 0);
topbox.set_hexpand(true);
topbox
@ -110,9 +170,9 @@ fn load_enabled_units() {
for service in service_list {
let out: Vec<&str> = service.split(' ').collect();
g_local_units.lock().unwrap().loaded_units.push(out[0].to_string());
g_local_units.lock().unwrap().loaded_units.push(String::from(out[0]));
if out[1] == "enabled" {
g_local_units.lock().unwrap().enabled_units.push(out[0].to_string());
g_local_units.lock().unwrap().enabled_units.push(String::from(out[0]));
}
}
}
@ -134,9 +194,9 @@ fn load_global_enabled_units() {
let service_list = exec_out.split('\n');
for service in service_list {
let out: Vec<&str> = service.split(' ').collect();
g_global_units.lock().unwrap().loaded_units.push(out[0].to_string());
g_global_units.lock().unwrap().loaded_units.push(String::from(out[0]));
if out[1] == "enabled" {
g_global_units.lock().unwrap().enabled_units.push(out[0].to_string());
g_global_units.lock().unwrap().enabled_units.push(String::from(out[0]));
}
}
}
@ -150,8 +210,6 @@ pub fn create_tweaks_page(builder: &Builder) {
load_global_enabled_units();
let viewport = gtk::Viewport::new(gtk::Adjustment::NONE, gtk::Adjustment::NONE);
// let label = gtk::Label::new(None);
// label.set_line_wrap(true);
let image = gtk::Image::from_icon_name(Some("go-previous"), gtk::IconSize::Button);
let back_btn = gtk::Button::new();
back_btn.set_image(Some(&image));
@ -164,6 +222,7 @@ pub fn create_tweaks_page(builder: &Builder) {
}));
let options_section_box = create_options_section();
let fixes_section_box = create_fixes_section();
let apps_section_box = create_apps_section();
let grid = gtk::Grid::new();
@ -175,8 +234,9 @@ pub fn create_tweaks_page(builder: &Builder) {
grid.attach(&back_btn, 0, 1, 1, 1);
let box_collection = gtk::Box::new(gtk::Orientation::Vertical, 5);
box_collection.pack_start(&options_section_box, true, true, 5);
box_collection.pack_start(&apps_section_box, true, true, 5);
box_collection.pack_start(&options_section_box, false, false, 10);
box_collection.pack_start(&fixes_section_box, false, false, 10);
box_collection.pack_end(&apps_section_box, false, false, 10);
box_collection.set_valign(gtk::Align::Center);
box_collection.set_halign(gtk::Align::Center);
@ -194,8 +254,6 @@ pub fn create_appbrowser_page(builder: &Builder) {
install.set_visible(true);
let viewport = gtk::Viewport::new(gtk::Adjustment::NONE, gtk::Adjustment::NONE);
// let label = gtk::Label::new(None);
// label.set_line_wrap(true);
let image = gtk::Image::from_icon_name(Some("go-previous"), gtk::IconSize::Button);
let back_btn = gtk::Button::new();
back_btn.set_image(Some(&image));
@ -269,6 +327,49 @@ fn on_servbtn_clicked(button: &gtk::CheckButton) {
});
}
fn on_refreshkeyring_btn_clicked(_: &gtk::Button) {
let pacman = pacmanconf::Config::with_opts(None, Some("/etc/pacman.conf"), Some("/")).unwrap();
let alpm = alpm_utils::alpm_with_conf(&pacman).unwrap();
// pacman -Qq | grep keyring
let needles = alpm
.localdb()
.search([".*-keyring"].iter())
.unwrap()
.into_iter()
.filter(|pkg| pkg.name() != "gnome-keyring")
.map(|pkg| {
let mut pkgname = String::from(pkg.name());
pkgname.remove_matches("-keyring");
format!("{} ", pkgname)
})
.collect::<String>();
let _ = utils::run_cmd_terminal(
format!("pacman-key --init && pacman-key --populate {}", needles),
true,
);
}
fn on_update_system_btn_clicked(_: &gtk::Button) {
let (cmd, escalate) = match utils::get_pacman_wrapper() {
PacmanWrapper::Pak => ("pak -Syu", false),
PacmanWrapper::Yay => ("yay -Syu", false),
PacmanWrapper::Paru => ("paru --removemake -Syu", false),
_ => ("pacman -Syu", true),
};
let _ = utils::run_cmd_terminal(String::from(cmd), escalate);
}
fn on_clear_pkgcache_btn_clicked(_: &gtk::Button) {
let (cmd, escalate) = match utils::get_pacman_wrapper() {
PacmanWrapper::Pak => ("pak -Sc", false),
PacmanWrapper::Yay => ("yay -Sc", false),
PacmanWrapper::Paru => ("paru -Sc", false),
_ => ("pacman -Sc", true),
};
let _ = utils::run_cmd_terminal(String::from(cmd), escalate);
}
fn on_appbtn_clicked(button: &gtk::Button) {
// Get button label.
let name = button.label().unwrap();

View File

@ -1,9 +1,18 @@
use gtk::prelude::*;
use std::fs::File;
use std::path::Path;
use std::{fs, slice, str};
use subprocess::{Exec, Redirection};
#[derive(Debug)]
pub enum PacmanWrapper {
Pak,
Yay,
Paru,
Pacman,
}
#[inline]
pub fn fix_path(path: &str) -> String {
if !path.starts_with('~') {
@ -83,6 +92,19 @@ pub fn run_cmd_terminal(cmd: String, escalate: bool) -> bool {
exit_status.success()
}
#[inline]
pub fn get_pacman_wrapper() -> PacmanWrapper {
if Path::new("/sbin/pak").exists() {
return PacmanWrapper::Pak;
} else if Path::new("/sbin/yay").exists() {
return PacmanWrapper::Yay;
} else if Path::new("/sbin/paru").exists() {
return PacmanWrapper::Paru;
}
PacmanWrapper::Pacman
}
#[cfg(test)]
mod test {
use super::*;

View File

@ -1,15 +0,0 @@
window {
border-bottom-left-radius: 7px;
border-bottom-right-radius: 7px;
}
.homepage button {
transition: border 100ms ease-in-out;
padding: 10px 30px;
border: none;
border-radius: 5px 5px 5px 5px;
}
.aboutdialog {
border-radius: 7px;
}

View File

@ -1 +1,15 @@
@import url("base.css");
window {
border-bottom-left-radius: 7px;
border-bottom-right-radius: 7px;
}
.homepage button {
transition: border 100ms ease-in-out;
padding: 10px 30px;
border: none;
border-radius: 5px 5px 5px 5px;
}
.aboutdialog {
border-radius: 7px;
}