finalize scx page

This commit is contained in:
Ward from fusion-voyager-3 2024-06-20 01:11:00 +03:00
parent ffbc340b93
commit 3d4df58282
4 changed files with 40 additions and 11 deletions

View File

@ -85,10 +85,6 @@ pub fn build_ui(app: &adw::Application) {
), ),
Some("content_page"), Some("content_page"),
); );
content_stack.add_named(
&sched_ext::sched_ext_page(&content_stack, &window),
Some("sched_ext_page"),
);
window_toolbar.add_top_bar(&window_headerbar); window_toolbar.add_top_bar(&window_headerbar);
window_toolbar.add_top_bar(&window_banner); window_toolbar.add_top_bar(&window_banner);

View File

@ -1,4 +1,4 @@
use crate::{kernel_pkg, KernelBranch, RunningKernelInfo}; use crate::{kernel_pkg, KernelBranch, RunningKernelInfo, sched_ext};
use adw::prelude::*; use adw::prelude::*;
use adw::ExpanderRow; use adw::ExpanderRow;
use async_channel::Receiver; use async_channel::Receiver;
@ -150,7 +150,11 @@ pub fn content(
.build(); .build();
config_kernel_button.add_css_class("circular"); config_kernel_button.add_css_class("circular");
config_kernel_button.connect_clicked(clone!(@weak content_stack => move |_| { config_kernel_button.connect_clicked(clone!(@weak content_stack, @weak window => move |_| {
content_stack.add_named(
&sched_ext::sched_ext_page(&content_stack, &window),
Some("sched_ext_page"),
);
content_stack.set_visible_child_name("sched_ext_page") content_stack.set_visible_child_name("sched_ext_page")
})); }));

View File

@ -12,6 +12,7 @@ use crate::gdk::Display;
const APP_ID: &str = "com.github.cosmicfusion.fedora-kernel-manager"; const APP_ID: &str = "com.github.cosmicfusion.fedora-kernel-manager";
const PRETTY_NAME: &str = "Fedora Kernel Manager"; const PRETTY_NAME: &str = "Fedora Kernel Manager";
#[derive(Clone)]
struct RunningKernelInfo { struct RunningKernelInfo {
kernel: String, kernel: String,
version: String, version: String,

View File

@ -4,11 +4,12 @@ use adw::prelude::*;
use glib::*; use glib::*;
use gtk::prelude::*; use gtk::prelude::*;
use gtk::*; use gtk::*;
use std::{fs, io}; use std::{fs, io, thread};
use std::cell::RefCell; use std::cell::RefCell;
use std::fs::*; use std::fs::*;
use std::process::Stdio; use std::process::Stdio;
use std::rc::Rc; use std::rc::Rc;
use std::time::Duration;
use duct::cmd; use duct::cmd;
use gtk::AccessibleRole::Command; use gtk::AccessibleRole::Command;
@ -63,7 +64,7 @@ pub fn sched_ext_page(content_stack: &gtk::Stack, window: &adw::ApplicationWindo
&kernel_badges_size_group1, &kernel_badges_size_group1,
); );
let selected_scx_sched = Rc::new(RefCell::new(initial_running_kernel_info.sched)); let selected_scx_sched = Rc::new(RefCell::new(initial_running_kernel_info.clone().sched));
let cmd_status_dialog = adw::MessageDialog::builder() let cmd_status_dialog = adw::MessageDialog::builder()
.transient_for(window) .transient_for(window)
@ -113,19 +114,21 @@ pub fn sched_ext_page(content_stack: &gtk::Stack, window: &adw::ApplicationWindo
back_button.add_css_class("pill"); back_button.add_css_class("pill");
back_button.connect_clicked(clone!(@weak content_stack => move |_| { back_button.connect_clicked(clone!(@weak content_stack, @weak main_box => move |_| {
content_stack.set_visible_child_name("content_page") content_stack.set_visible_child_name("content_page");
content_stack.remove(&main_box);
})); }));
let apply_button = gtk::Button::builder() let apply_button = gtk::Button::builder()
.halign(Align::End) .halign(Align::End)
.label("Apply Changes") .label("Apply Changes")
.sensitive(false)
.build(); .build();
apply_button.add_css_class("pill"); apply_button.add_css_class("pill");
apply_button.add_css_class("destructive-action"); apply_button.add_css_class("destructive-action");
apply_button.connect_clicked(clone! (@weak badge_box, @weak kernel_badges_size_group, @weak kernel_badges_size_group0, @weak kernel_badges_size_group1 => move |_| { apply_button.connect_clicked(clone! (@weak badge_box, @weak kernel_badges_size_group, @weak kernel_badges_size_group0, @weak kernel_badges_size_group1, @weak selected_scx_sched => move |_| {
let selected_scx_sched_clone1 = selected_scx_sched.borrow().clone(); let selected_scx_sched_clone1 = selected_scx_sched.borrow().clone();
match change_scx_scheduler(&selected_scx_sched_clone1, match change_scx_scheduler(&selected_scx_sched_clone1,
@ -150,9 +153,34 @@ pub fn sched_ext_page(content_stack: &gtk::Stack, window: &adw::ApplicationWindo
let cancel_button = gtk::Button::builder() let cancel_button = gtk::Button::builder()
.halign(Align::End) .halign(Align::End)
.label("Cancel Changes") .label("Cancel Changes")
.sensitive(false)
.build(); .build();
cancel_button.add_css_class("pill"); cancel_button.add_css_class("pill");
//
let (loop0_sender, loop0_receiver) = async_channel::unbounded();
let loop0_sender = loop0_sender.clone();
std::thread::spawn(move || loop {
loop0_sender.send_blocking(false).expect("error on loop0");
thread::sleep(Duration::from_millis(100));
});
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 {
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(&back_button);
window_bottombar.append(&cancel_button); window_bottombar.append(&cancel_button);
window_bottombar.append(&apply_button); window_bottombar.append(&apply_button);