chore: Upgrade Bevy to v0.13 and windows to v0.54.

This commit is contained in:
Nolan Darilek 2024-03-14 13:04:42 -05:00
parent 1e938d4222
commit 5a7b155a8c
2 changed files with 9 additions and 3 deletions

View File

@ -9,11 +9,11 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
bevy = { version = "0.12", default-features = false }
bevy = { version = "0.13", default-features = false }
ctrlc = "3"
[target.'cfg(windows)'.dependencies]
windows = { version = "0.52", features = [
windows = { version = "0.54", features = [
"Win32_Foundation",
"Win32_System_Power",
"Win32_System_Registry",

View File

@ -18,12 +18,15 @@ fn setup(mut commands: Commands) {
#[cfg(windows)]
unsafe {
let mut active: *mut GUID = std::ptr::null_mut();
Power::PowerGetActiveScheme(None, &mut active).expect("Failed to get active power scheme");
Power::PowerGetActiveScheme(None, &mut active)
.ok()
.expect("Failed to get active power scheme");
if let Some(active) = active.as_ref() {
let scheme = DefaultScheme(*active);
commands.insert_resource(scheme);
ctrlc::set_handler(move || {
Power::PowerSetActiveScheme(None, Some(active))
.ok()
.expect("Failed to set power scheme");
std::process::exit(1);
})
@ -45,6 +48,7 @@ fn focus_change(
#[cfg(windows)]
unsafe {
Power::PowerSetActiveScheme(None, Some(&GUID_MIN_POWER_SAVINGS))
.ok()
.expect("Failed to set power scheme");
}
} else {
@ -52,6 +56,7 @@ fn focus_change(
if config.restore_original_scheme_on_unfocus {
unsafe {
Power::PowerSetActiveScheme(None, Some(&**scheme))
.ok()
.expect("Failed to set power scheme");
}
}
@ -65,6 +70,7 @@ fn exit(mut exit: EventReader<AppExit>, scheme: Res<DefaultScheme>) {
#[cfg(windows)]
unsafe {
Power::PowerSetActiveScheme(None, Some(&**scheme))
.ok()
.expect("Failed to restore original power scheme");
}
}