Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Commit

Permalink
1.4.2 WIP1
Browse files Browse the repository at this point in the history
  • Loading branch information
felikcat committed Dec 8, 2024
1 parent 9566482 commit 7e1e60e
Show file tree
Hide file tree
Showing 2 changed files with 190 additions and 60 deletions.
224 changes: 164 additions & 60 deletions src/gui.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
mod appx_support;
mod create_system_restore_point;
mod defaults;
mod disable_defender_and_smartscreen;
mod disable_sleep;
mod disable_vbs;
mod reduce_forensics;
mod reduce_online_data_collection;
mod disable_defender_and_smartscreen;
mod disable_vbs;
mod remove_w11boost;

use fltk::{
app::{self, Screen}, button::{Button, CheckButton}, dialog, draw::{self}, enums::{self, Color}, frame::{self}, prelude::*, widget::Widget, window::Window
app::{self, Screen},
button::{Button, CheckButton},
dialog,
draw::{self},
enums::{self, Color},
frame::{self},
prelude::*,
widget::Widget,
window::Window,
};
use fltk_theme::{ColorTheme, color_themes};
use std::{
borrow::BorrowMut,
cell::RefCell,
error::Error,
mem,
ops::DerefMut,
process::{Command, exit},
rc::Rc,
};
use windows::Win32::{
Foundation::HWND,
Expand Down Expand Up @@ -52,19 +65,32 @@ pub fn draw_gui() -> Result<(), Box<dyn Error>> {
let mut apply = Button::new(
0,
0,
wind.width() - 2,
(wind.width() - 6) / 2,
(wind.height() * 14) / 100,
"Apply W11Boost",
)
.center_of(&wind);

apply.set_pos(
wind.width() - apply.width() - 1,
wind.height() - apply.height() - 2,
); // Put button at the bottom
let mut remove = Button::new(
wind.width() / 2,
0,
(wind.width() - 6) / 2,
(wind.height() * 14) / 100,
"Remove W11Boost",
)
.center_of(&wind);

apply.set_pos(2, wind.height() - apply.height() - 2); // Put button at the bottom

remove.set_pos(
wind.width() - remove.width() - 2,
wind.height() - remove.height() - 2,
);

apply.set_label_font(enums::Font::by_name(&font));
apply.set_label_size(16);
remove.set_label_font(enums::Font::by_name(&font));
remove.set_label_size(16);

let checkbox_height = wind.height() / 12;

Expand Down Expand Up @@ -142,11 +168,14 @@ pub fn draw_gui() -> Result<(), Box<dyn Error>> {
my_checkboxes[2].set_value(true);
my_checkboxes[8].set_value(true);

let mut frame0 = Widget::default()
let frame0 = RefCell::new(Widget::default()
.with_size(wind.width(), wind.height() - titlebar.height())
.with_pos(0, titlebar.height());
frame0.set_frame(enums::FrameType::BorderBox);
frame0.draw( move |f| {
.with_pos(0, titlebar.height()));

let frame0_clone = frame0.clone();

frame0_clone.borrow_mut().set_frame(enums::FrameType::BorderBox);
frame0_clone.borrow_mut().draw(move |f| {
let label = f.label();
let txt = label.split(" ").nth(0).unwrap();
let x = f.x();
Expand All @@ -161,8 +190,8 @@ pub fn draw_gui() -> Result<(), Box<dyn Error>> {
draw::draw_text2(txt, x, y - 16, w, h, f.align());
draw::pop_clip();
});
frame0.set_label("Applying W11Boost, please wait...");
frame0.hide();
frame0_clone.borrow_mut().set_label("Applying W11Boost, please wait...");
frame0_clone.borrow_mut().hide();

wind.end();
wind.show();
Expand Down Expand Up @@ -210,71 +239,146 @@ pub fn draw_gui() -> Result<(), Box<dyn Error>> {
}
});

let mut clone_apply = apply.clone();

apply.set_callback(move |_| {
fn hide_elements(
frame0: &mut impl WidgetExt,
apply_clone: &mut impl ButtonExt,
my_checkboxes: &mut [impl WidgetExt],
) {
frame0.show();
frame0.top_window();

// So these aren't accidentally clicked.
clone_apply.hide();
for checkbox in &mut my_checkboxes {
apply_clone.hide();
for checkbox in my_checkboxes {
checkbox.hide();
}

// Force window to redraw to display frame0.
app::flush();
app::wait();

// Has to be first!
if my_checkboxes[2].is_checked() {
create_system_restore_point::run().expect("create_system_restore_point::run failed");
}
}

if my_checkboxes[0].is_checked() {
reduce_forensics::run().expect("reduce_forensics::run failed");
}
if my_checkboxes[1].is_checked() {
reduce_online_data_collection::run()
.expect("reduce_online_data_collection::run failed");
}
if my_checkboxes[3].is_checked() {
Command::new("wsreset.exe")
.output()
.expect("wsreset.exe failed to execute");
}
if my_checkboxes[4].is_checked() {
appx_support::install().expect("appx_support::install failed");
fn show_elements(
frame0: &mut impl WidgetExt,
apply_clone: &mut impl ButtonExt,
my_checkboxes: &mut [impl WidgetExt],
) {
// Does not require a manual redraw.
frame0.hide();
apply_clone.show();
for checkbox in my_checkboxes {
checkbox.show();
}
}

if my_checkboxes[5].is_checked() {
disable_defender_and_smartscreen::run()
.expect("disable_defender_and_smartscreen::run failed");
}
let mut apply_clone = apply.clone();

apply.set_callback( move |_| {
let choice = dialog::choice2(
center().0,
center().1,
"Are you sure you want to apply W11Boost?",
"&Yes",
"&No",
"",
);
if choice == Some(0) {
hide_elements(
&mut *frame0_clone.borrow_mut(),
&mut *apply_clone.borrow_mut(),
&mut *my_checkboxes.borrow_mut(),
);
// Has to be first!
if my_checkboxes[2].is_checked() {
create_system_restore_point::run()
.expect("create_system_restore_point::run failed");
}

if my_checkboxes[6].is_checked() {
disable_sleep::run().expect("disable_sleep::run failed");
}
if my_checkboxes[0].is_checked() {
reduce_forensics::run().expect("reduce_forensics::run failed");
}
if my_checkboxes[1].is_checked() {
reduce_online_data_collection::run()
.expect("reduce_online_data_collection::run failed");
}
if my_checkboxes[3].is_checked() {
Command::new("wsreset.exe")
.output()
.expect("wsreset.exe failed to execute");
}
if my_checkboxes[4].is_checked() {
appx_support::install().expect("appx_support::install failed");
}

if my_checkboxes[7].is_checked() {
disable_vbs::run().expect("disable_vbs::run failed");
}
if my_checkboxes[5].is_checked() {
disable_defender_and_smartscreen::run()
.expect("disable_defender_and_smartscreen::run failed");
}

if my_checkboxes[6].is_checked() {
disable_sleep::run().expect("disable_sleep::run failed");
}

if my_checkboxes[8].is_checked() {
defaults::run().expect("defaults::run failed");
if my_checkboxes[7].is_checked() {
disable_vbs::run().expect("disable_vbs::run failed");
}

if my_checkboxes[8].is_checked() {
defaults::run().expect("defaults::run failed");
}

if my_checkboxes.iter().all(|checkbox| !checkbox.is_checked()) {
dialog::message(
center().0,
center().1,
"No options were selected, therefore nothing has changed.",
);
} else {
dialog::message(
center().0,
center().1,
"W11Boost applied your preferences successfully, please reboot.",
);
}

show_elements(
&mut *frame0_clone.borrow_mut(),
&mut *apply_clone.borrow_mut(),
&mut *my_checkboxes.borrow_mut(),
);
}
});

if my_checkboxes.iter().all(|checkbox| !checkbox.is_checked()) {
dialog::message(center().0, center().1, "No options were selected, therefore nothing has changed.");
} else {
dialog::message(center().0, center().1, "W11Boost applied your preferences successfully, please reboot.");
}
remove.set_callback(move |_| {
let choice = dialog::choice2(
center().0,
center().1,
"Are you sure you want to remove W11Boost?",
"&Yes",
"&No",
"",
);
if choice == Some(0) {
hide_elements(
&mut *frame0_clone.borrow_mut(),
&mut apply_clone,
&mut my_checkboxes,
);
if let Ok(_) = remove_w11boost::run() {
dialog::message(
center().0,
center().1,
"W11Boost applied your preferences successfully, please reboot.",
);
} else {
eprintln!("remove_w11boost::run failed");
}

// Does not require a manual redraw.
frame0.hide();
clone_apply.show();
for checkbox in &mut my_checkboxes {
checkbox.show();
show_elements(
&mut *frame0_clone.borrow_mut(),
&mut apply_clone,
&mut my_checkboxes,
);
}
});

Expand Down
26 changes: 26 additions & 0 deletions src/gui/remove_w11boost.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use std::error::Error;
use winsafe::{prelude::advapi_Hkey, HKEY};
use crate::common::*;

pub fn run() -> Result<(), Box<dyn Error>> {
let hklm = HKEY::LOCAL_MACHINE;
remove_subkey(&hklm, r"SYSTEM\CurrentControlSet\Control\Power\HibernateEnabledDefault")?;

remove_subkey(&hklm, r"Software\Policies\Microsoft\Power\PowerSettings\94ac6d29-73ce-41a6-809f-6363ba21b47e\DCSettingIndex")?;
remove_subkey(&hklm, r"Software\Policies\Microsoft\Power\PowerSettings\94ac6d29-73ce-41a6-809f-6363ba21b47e\ACSettingIndex")?;

remove_subkey(&hklm, r"Software\Policies\Microsoft\Power\PowerSettings\29F6C1DB-86DA-48C5-9FDB-F2B67B1F44DA\DCSettingIndex")?;
remove_subkey(&hklm, r"Software\Policies\Microsoft\Power\PowerSettings\29F6C1DB-86DA-48C5-9FDB-F2B67B1F44DA\ACSettingIndex")?;

remove_subkey(&hklm, r"Software\Policies\Microsoft\Power\PowerSettings\9D7815A6-7EE4-497E-8888-515A05F02364\DCSettingIndex")?;
remove_subkey(&hklm, r"Software\Policies\Microsoft\Power\PowerSettings\9D7815A6-7EE4-497E-8888-515A05F02364\ACSettingIndex")?;

remove_subkey(&hklm, r"Software\Policies\Microsoft\Power\PowerSettings\7bc4a2f9-d8fc-4469-b07b-33eb785aaca0\DCSettingIndex")?;
remove_subkey(&hklm, r"Software\Policies\Microsoft\Power\PowerSettings\7bc4a2f9-d8fc-4469-b07b-33eb785aaca0\ACSettingIndex")?;

remove_subkey(&hklm, r"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FlyoutMenuSettings\ShowHibernateOption")?;
remove_subkey(&hklm, r"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FlyoutMenuSettings\ShowSleepOption")?;


Ok(())
}

0 comments on commit 7e1e60e

Please sign in to comment.