mirror of
https://github.com/lightsoutgames/bevy_full_throttle
synced 2024-11-23 12:25:56 +00:00
fix: Panic if power scheme operations fail. This shouldn't happen, but if it does then the actual failure cases should be logged.
This commit is contained in:
parent
a0875b7d5f
commit
4c3ba4d71c
14
src/lib.rs
14
src/lib.rs
|
@ -18,12 +18,13 @@ fn setup(mut commands: Commands) {
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut active: *mut GUID = std::ptr::null_mut();
|
let mut active: *mut GUID = std::ptr::null_mut();
|
||||||
Power::PowerGetActiveScheme(None, &mut active);
|
Power::PowerGetActiveScheme(None, &mut active).expect("Failed to get active power scheme");
|
||||||
if let Some(active) = active.as_ref() {
|
if let Some(active) = active.as_ref() {
|
||||||
let scheme = DefaultScheme(*active);
|
let scheme = DefaultScheme(*active);
|
||||||
commands.insert_resource(scheme);
|
commands.insert_resource(scheme);
|
||||||
ctrlc::set_handler(move || {
|
ctrlc::set_handler(move || {
|
||||||
Power::PowerSetActiveScheme(None, Some(active));
|
Power::PowerSetActiveScheme(None, Some(active))
|
||||||
|
.expect("Failed to set power scheme");
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
})
|
})
|
||||||
.expect("Failed to set exit handler");
|
.expect("Failed to set exit handler");
|
||||||
|
@ -43,13 +44,15 @@ fn focus_change(
|
||||||
if event.focused {
|
if event.focused {
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
unsafe {
|
unsafe {
|
||||||
Power::PowerSetActiveScheme(None, Some(&GUID_MIN_POWER_SAVINGS));
|
Power::PowerSetActiveScheme(None, Some(&GUID_MIN_POWER_SAVINGS))
|
||||||
|
.expect("Failed to set power scheme");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
if config.restore_original_scheme_on_unfocus {
|
if config.restore_original_scheme_on_unfocus {
|
||||||
unsafe {
|
unsafe {
|
||||||
Power::PowerSetActiveScheme(None, Some(&**scheme));
|
Power::PowerSetActiveScheme(None, Some(&**scheme))
|
||||||
|
.expect("Failed to set power scheme");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,7 +64,8 @@ fn exit(mut exit: EventReader<AppExit>, scheme: Res<DefaultScheme>) {
|
||||||
for event in exit.iter() {
|
for event in exit.iter() {
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
unsafe {
|
unsafe {
|
||||||
Power::PowerSetActiveScheme(None, Some(&**scheme));
|
Power::PowerSetActiveScheme(None, Some(&**scheme))
|
||||||
|
.expect("Failed to restore original power scheme");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user