-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5d7a88c
commit 4add6e4
Showing
4 changed files
with
213 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "Win-Set-AudioOUT" | ||
version = "1.0.0" | ||
edition = "2021" | ||
build = "build.rs" | ||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
tempfile = "3.3.0" | ||
|
||
[build-dependencies] | ||
winres = "0.1.12" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
fn main() { | ||
if cfg!(target_os = "windows") { | ||
let mut res = winres::WindowsResource::new(); | ||
res.set_icon("data\\audio-icon.ico"); | ||
res.compile().unwrap(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#![allow(non_snake_case)] | ||
#![windows_subsystem = "windows"] | ||
|
||
use tempfile::tempdir; | ||
use std::fs::File; | ||
use std::io::prelude::*; | ||
use std::io::Write; | ||
use std::process::Command; | ||
use std::{thread, time}; | ||
|
||
|
||
fn main() { | ||
let bundled_soundvolumeview = include_bytes!("../data/soundvolumeview-x64/SoundVolumeView.exe"); | ||
|
||
// Create a directory inside of `std::env::temp_dir()` | ||
let dir = tempdir().unwrap(); | ||
let soundvolumeview_path = dir.path().join("SoundVolumeView.exe"); | ||
let audioout_path = dir.path().join("audioout.txt"); | ||
let mut file = File::create(&soundvolumeview_path).unwrap(); | ||
file.write_all(bundled_soundvolumeview).unwrap(); | ||
drop(file); | ||
|
||
change_audio_device(soundvolumeview_path.to_str().unwrap(), audioout_path.to_str().unwrap()); | ||
|
||
drop(dir); | ||
} | ||
|
||
fn change_audio_device(soundvolumeview_path: &str, audioout_path: &str) { | ||
Command::new(soundvolumeview_path) | ||
.arg("/RunAsAdmin") | ||
.arg("/scomma") | ||
.arg(audioout_path) | ||
.status().unwrap(); | ||
|
||
thread::sleep(time::Duration::from_millis(500)); | ||
|
||
let mut audioout_file = File::open(audioout_path).unwrap(); | ||
let mut audioout_contents = String::new(); | ||
audioout_file.read_to_string(&mut audioout_contents).unwrap(); | ||
|
||
let mut default_audio_device = ""; | ||
for line in audioout_contents.trim().split('\n') { | ||
if line.contains("Render,Render") { | ||
default_audio_device = line.split(',').collect::<Vec<&str>>()[0]; | ||
} | ||
} | ||
|
||
match default_audio_device { | ||
"Headset" => { | ||
Command::new(soundvolumeview_path) | ||
.arg("/RunAsAdmin") | ||
.arg("/SetDefault") | ||
.arg("Speakers") | ||
.arg("all") | ||
.status().unwrap(); | ||
}, | ||
"Speakers" => { | ||
Command::new(soundvolumeview_path) | ||
.arg("/RunAsAdmin") | ||
.arg("/SetDefault") | ||
.arg("Headset") | ||
.arg("all") | ||
.status().unwrap(); | ||
}, | ||
_ => () | ||
} | ||
|
||
thread::sleep(time::Duration::from_millis(500)); | ||
} |