add credit window

This commit is contained in:
Ward from fusion-voyager-3 2024-06-20 01:29:27 +03:00
parent 3d4df58282
commit a87d458001
4 changed files with 43 additions and 15 deletions

View File

@ -1,4 +1,8 @@
use crate::{content, kernel_pkg, sched_ext, KernelBranch, PRETTY_NAME};
use crate::APP_GITHUB;
use crate::VERSION;
use crate::APP_ID;
use crate::APP_ICON;
use crate::{content, kernel_pkg, sched_ext, KernelBranch};
use adw::prelude::*;
use adw::*;
use glib::property::PropertyGet;
@ -59,7 +63,7 @@ pub fn build_ui(app: &adw::Application) {
}));
let window_headerbar = adw::HeaderBar::builder()
.title_widget(&adw::WindowTitle::builder().title(PRETTY_NAME).build())
.title_widget(&adw::WindowTitle::builder().title("Fedora Kernel Manager").build())
.build();
let content_stack = gtk::Stack::builder()
@ -74,6 +78,8 @@ pub fn build_ui(app: &adw::Application) {
.width_request(600)
.height_request(600)
.resizable(false)
.icon_name(APP_ICON)
.startup_id(APP_ID)
.build();
content_stack.add_named(
@ -98,6 +104,24 @@ pub fn build_ui(app: &adw::Application) {
glib::Propagation::Proceed
});
let credits_button = gtk::Button::builder()
.icon_name("dialog-information-symbolic")
.build();
let credits_window = adw::AboutWindow::builder()
.application_icon(APP_ICON)
.application_name("Fedora Kernel Manager")
.transient_for(&window)
.version(VERSION)
.hide_on_close(true)
.developer_name("Cosmo")
.issue_url(APP_GITHUB.to_owned() + "/issues")
.build();
window_headerbar.pack_end(&credits_button);
credits_button
.connect_clicked(clone!(@weak credits_button => move |_| credits_window.present()));
window.present();
}

View File

@ -146,10 +146,15 @@ pub fn content(
.height_request(50)
.width_request(50)
.tooltip_text("Configure Sched_EXT settings")
.sensitive(is_scx_kernel())
.hexpand(true)
.build();
config_kernel_button.add_css_class("circular");
if ! is_scx_kernel() {
config_kernel_button.set_tooltip_text(Some("Currently running kernel doesn't support Sched-EXT"));
}
config_kernel_button.connect_clicked(clone!(@weak content_stack, @weak window => move |_| {
content_stack.add_named(
&sched_ext::sched_ext_page(&content_stack, &window),
@ -412,8 +417,15 @@ pub fn get_running_kernel_info() -> RunningKernelInfo {
info
}
pub fn get_current_scheduler(version: String) -> String {
fn is_scx_kernel() -> bool {
if Path::new("/sys/kernel/sched_ext/root/ops").exists() {
true
} else {
false
}
}
pub fn get_current_scheduler(version: String) -> String {
if is_scx_kernel() {
println!("sched_ext is detected, getting scx scheduler");
let scx_sched = match fs::read_to_string("/sys/kernel/sched_ext/root/ops") {
Ok(t) => t,

View File

@ -10,7 +10,9 @@ use gtk::*;
use crate::gdk::Display;
const APP_ID: &str = "com.github.cosmicfusion.fedora-kernel-manager";
const PRETTY_NAME: &str = "Fedora Kernel Manager";
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
pub const APP_ICON: &str = "com.github.cosmicfusion.fedora-kernel-manager";
pub const APP_GITHUB: &str = "https://github.com/CosmicFusion/fedora-kernel-manager";
#[derive(Clone)]
struct RunningKernelInfo {

View File

@ -150,13 +150,6 @@ pub fn sched_ext_page(content_stack: &gtk::Stack, window: &adw::ApplicationWindo
};
}));
let cancel_button = gtk::Button::builder()
.halign(Align::End)
.label("Cancel Changes")
.sensitive(false)
.build();
cancel_button.add_css_class("pill");
//
let (loop0_sender, loop0_receiver) = async_channel::unbounded();
let loop0_sender = loop0_sender.clone();
@ -168,21 +161,18 @@ pub fn sched_ext_page(content_stack: &gtk::Stack, window: &adw::ApplicationWindo
let loop0_context = MainContext::default();
// The main loop executes the asynchronous block
loop0_context.spawn_local(clone!(@weak apply_button, @weak cancel_button, @strong selected_scx_sched, @strong initial_running_kernel_info => async move {
loop0_context.spawn_local(clone!(@weak apply_button, @strong selected_scx_sched, @strong initial_running_kernel_info => async move {
while let Ok(_state) = loop0_receiver.recv().await {
if *selected_scx_sched.borrow() == initial_running_kernel_info.sched {
apply_button.set_sensitive(false);
cancel_button.set_sensitive(false);
} else {
apply_button.set_sensitive(true);
cancel_button.set_sensitive(true);
}
}
}));
//
window_bottombar.append(&back_button);
window_bottombar.append(&cancel_button);
window_bottombar.append(&apply_button);
main_box.append(&badge_box);