🧹 drop unsafe at pages.rs
This commit is contained in:
parent
33cf5d7fa4
commit
c40aee852a
38
src/pages.rs
38
src/pages.rs
|
@ -13,9 +13,8 @@ use gtk::prelude::*;
|
||||||
use std::str;
|
use std::str;
|
||||||
use subprocess::{Exec, Redirection};
|
use subprocess::{Exec, Redirection};
|
||||||
|
|
||||||
static mut g_local_units: Lazy<Mutex<SystemdUnits>> = Lazy::new(|| Mutex::new(SystemdUnits::new()));
|
static G_LOCAL_UNITS: Lazy<Mutex<SystemdUnits>> = Lazy::new(|| Mutex::new(SystemdUnits::new()));
|
||||||
static mut g_global_units: Lazy<Mutex<SystemdUnits>> =
|
static G_GLOBAL_UNITS: Lazy<Mutex<SystemdUnits>> = Lazy::new(|| Mutex::new(SystemdUnits::new()));
|
||||||
Lazy::new(|| Mutex::new(SystemdUnits::new()));
|
|
||||||
|
|
||||||
fn create_fixes_section() -> gtk::Box {
|
fn create_fixes_section() -> gtk::Box {
|
||||||
let topbox = gtk::Box::new(gtk::Orientation::Vertical, 2);
|
let topbox = gtk::Box::new(gtk::Orientation::Vertical, 2);
|
||||||
|
@ -128,8 +127,8 @@ fn create_options_section() -> gtk::Box {
|
||||||
for btn in &[&psd_btn, &systemd_oomd_btn, &apparmor_btn, &bluetooth_btn, &ananicy_cpp_btn] {
|
for btn in &[&psd_btn, &systemd_oomd_btn, &apparmor_btn, &bluetooth_btn, &ananicy_cpp_btn] {
|
||||||
unsafe {
|
unsafe {
|
||||||
let data: &str = *btn.data("actionData").unwrap().as_ptr();
|
let data: &str = *btn.data("actionData").unwrap().as_ptr();
|
||||||
if g_local_units.lock().unwrap().enabled_units.contains(&String::from(data))
|
if G_LOCAL_UNITS.lock().unwrap().enabled_units.contains(&String::from(data))
|
||||||
|| g_global_units.lock().unwrap().enabled_units.contains(&String::from(data))
|
|| G_GLOBAL_UNITS.lock().unwrap().enabled_units.contains(&String::from(data))
|
||||||
{
|
{
|
||||||
btn.set_active(true);
|
btn.set_active(true);
|
||||||
}
|
}
|
||||||
|
@ -144,7 +143,7 @@ fn create_options_section() -> gtk::Box {
|
||||||
matches!(alpm.localdb().pkg(pkg_name.as_bytes()), Ok(_))
|
matches!(alpm.localdb().pkg(pkg_name.as_bytes()), Ok(_))
|
||||||
};
|
};
|
||||||
let is_local_service_enabled = |service_unit_name: &str| -> bool {
|
let is_local_service_enabled = |service_unit_name: &str| -> bool {
|
||||||
let local_units = unsafe { &g_local_units.lock().unwrap().enabled_units };
|
let local_units = &G_LOCAL_UNITS.lock().unwrap().enabled_units;
|
||||||
local_units.contains(&String::from(service_unit_name))
|
local_units.contains(&String::from(service_unit_name))
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -231,9 +230,8 @@ fn create_apps_section() -> Option<gtk::Box> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load_enabled_units() {
|
fn load_enabled_units() {
|
||||||
unsafe {
|
G_LOCAL_UNITS.lock().unwrap().loaded_units.clear();
|
||||||
g_local_units.lock().unwrap().loaded_units.clear();
|
G_LOCAL_UNITS.lock().unwrap().enabled_units.clear();
|
||||||
g_local_units.lock().unwrap().enabled_units.clear();
|
|
||||||
|
|
||||||
let mut exec_out = Exec::shell("systemctl list-unit-files -q --no-pager | tr -s \" \"")
|
let mut exec_out = Exec::shell("systemctl list-unit-files -q --no-pager | tr -s \" \"")
|
||||||
.stdout(Redirection::Pipe)
|
.stdout(Redirection::Pipe)
|
||||||
|
@ -246,18 +244,16 @@ fn load_enabled_units() {
|
||||||
|
|
||||||
for service in service_list {
|
for service in service_list {
|
||||||
let out: Vec<&str> = service.split(' ').collect();
|
let out: Vec<&str> = service.split(' ').collect();
|
||||||
g_local_units.lock().unwrap().loaded_units.push(String::from(out[0]));
|
G_LOCAL_UNITS.lock().unwrap().loaded_units.push(String::from(out[0]));
|
||||||
if out[1] == "enabled" {
|
if out[1] == "enabled" {
|
||||||
g_local_units.lock().unwrap().enabled_units.push(String::from(out[0]));
|
G_LOCAL_UNITS.lock().unwrap().enabled_units.push(String::from(out[0]));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load_global_enabled_units() {
|
fn load_global_enabled_units() {
|
||||||
unsafe {
|
G_GLOBAL_UNITS.lock().unwrap().loaded_units.clear();
|
||||||
g_global_units.lock().unwrap().loaded_units.clear();
|
G_GLOBAL_UNITS.lock().unwrap().enabled_units.clear();
|
||||||
g_global_units.lock().unwrap().enabled_units.clear();
|
|
||||||
|
|
||||||
let mut exec_out =
|
let mut exec_out =
|
||||||
Exec::shell("systemctl --global list-unit-files -q --no-pager | tr -s \" \"")
|
Exec::shell("systemctl --global list-unit-files -q --no-pager | tr -s \" \"")
|
||||||
|
@ -270,10 +266,9 @@ fn load_global_enabled_units() {
|
||||||
let service_list = exec_out.split('\n');
|
let service_list = exec_out.split('\n');
|
||||||
for service in service_list {
|
for service in service_list {
|
||||||
let out: Vec<&str> = service.split(' ').collect();
|
let out: Vec<&str> = service.split(' ').collect();
|
||||||
g_global_units.lock().unwrap().loaded_units.push(String::from(out[0]));
|
G_GLOBAL_UNITS.lock().unwrap().loaded_units.push(String::from(out[0]));
|
||||||
if out[1] == "enabled" {
|
if out[1] == "enabled" {
|
||||||
g_global_units.lock().unwrap().enabled_units.push(String::from(out[0]));
|
G_GLOBAL_UNITS.lock().unwrap().enabled_units.push(String::from(out[0]));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -378,10 +373,8 @@ fn on_servbtn_clicked(button: >k::CheckButton) {
|
||||||
let (user_only, pkexec_only) =
|
let (user_only, pkexec_only) =
|
||||||
if action_type == "user_service" { ("--user", "--user $(logname)") } else { ("", "") };
|
if action_type == "user_service" { ("--user", "--user $(logname)") } else { ("", "") };
|
||||||
|
|
||||||
let cmd: String;
|
let local_units = &G_LOCAL_UNITS.lock().unwrap().enabled_units;
|
||||||
unsafe {
|
let cmd = if !local_units.contains(&String::from(action_data)) {
|
||||||
let local_units = &g_local_units.lock().unwrap().enabled_units;
|
|
||||||
cmd = if !local_units.contains(&String::from(action_data)) {
|
|
||||||
format!(
|
format!(
|
||||||
"/sbin/pkexec {pkexec_only} bash -c \"systemctl {user_only} enable --now --force \
|
"/sbin/pkexec {pkexec_only} bash -c \"systemctl {user_only} enable --now --force \
|
||||||
{action_data}\""
|
{action_data}\""
|
||||||
|
@ -392,7 +385,6 @@ fn on_servbtn_clicked(button: >k::CheckButton) {
|
||||||
{action_data}\""
|
{action_data}\""
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
// Spawn child process in separate thread.
|
// Spawn child process in separate thread.
|
||||||
std::thread::spawn(move || {
|
std::thread::spawn(move || {
|
||||||
|
|
Loading…
Reference in New Issue