Skip to content

Commit

Permalink
fix: set gpu preference to high performance on windows by default
Browse files Browse the repository at this point in the history
  • Loading branch information
thewh1teagle committed Jun 24, 2024
1 parent cc86264 commit c7a5ac8
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
File renamed without changes.
27 changes: 27 additions & 0 deletions desktop/src-tauri/src/gpu_preference.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use eyre::ContextCompat;
use eyre::Result;
use std::env;
use winreg::enums::*;
use winreg::RegKey;

pub fn set_gpu_preference() -> Result<()> {
let hkcu = RegKey::predef(HKEY_CURRENT_USER);
let directx = hkcu.open_subkey_with_flags("Software\\Microsoft\\DirectX", KEY_ALL_ACCESS)?;

// Create the main key for the UserGpuPreferences if it doesn't exist
let user_gpu_preferences = directx.create_subkey("UserGpuPreferences")?;

// Get the current executable path
let program_path = env::current_exe()?;
let program_path_str = program_path.to_str().context("Failed to convert program path to string")?;

// Set the GPU preference for the current executable
// 0 = Auto ; 1 = Power Saving ; 2 = High
user_gpu_preferences.0.set_value(program_path_str, &"GpuPreference=2;")?;

log::debug!(
"GPU preference set for high performance successfully for the current executable ({}).",
program_path_str
);
Ok(())
}
5 changes: 4 additions & 1 deletion desktop/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ mod dock;
mod x86_features;

#[cfg(windows)]
mod register_custom_protocol;
mod custom_protocol;

#[cfg(windows)]
mod gpu_preference;

use tauri_plugin_window_state::StateFlags;

Expand Down
5 changes: 4 additions & 1 deletion desktop/src-tauri/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ pub fn setup(app: &App) -> Result<(), Box<dyn std::error::Error>> {

#[cfg(windows)]
{
if let Err(error) = crate::register_custom_protocol::register() {
if let Err(error) = crate::custom_protocol::register() {
log::error!("{:?}", error);
}
if let Err(error) = crate::gpu_preference::set_gpu_preference() {
log::error!("{:?}", error);
}
}
Expand Down

0 comments on commit c7a5ac8

Please sign in to comment.