Remove extraneous logging

Version bump
This commit is contained in:
Your Name
2023-02-23 19:06:34 -05:00
parent 60b7b34708
commit 5d9c8b4d0c
7 changed files with 23 additions and 29 deletions

2
Cargo.lock generated
View File

@@ -4,7 +4,7 @@ version = 3
[[package]] [[package]]
name = "auto_mute_tool" name = "auto_mute_tool"
version = "0.1.0" version = "0.2.0"
dependencies = [ dependencies = [
"windows", "windows",
] ]

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "auto_mute_tool" name = "auto_mute_tool"
version = "0.1.0" version = "0.2.0"
edition = "2021" edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@@ -13,4 +13,5 @@ hollow_knight.exe
sm64.us.f3dex2e.exe sm64.us.f3dex2e.exe
teardown.exe teardown.exe
underrail.exe underrail.exe
valheim.exe valheim.exe
Spotify.exe

View File

@@ -50,9 +50,3 @@ impl IMMNotificationClient_Impl for DeviceNotificationClient {
Ok(()) Ok(())
} }
} }
impl Drop for DeviceNotificationClient {
fn drop(&mut self) {
println!("DNC Drop");
}
}

View File

@@ -8,7 +8,7 @@ use std::{
collections::HashSet, collections::HashSet,
error::Error, error::Error,
ffi::OsString, ffi::OsString,
fs::File, fs::{File, self},
io::{BufRead, BufReader}, io::{BufRead, BufReader},
path::Path, path::Path,
ptr::null_mut, ptr::null_mut,
@@ -22,7 +22,7 @@ use windows::{
core::{Interface}, core::{Interface},
Win32::{ Win32::{
Media::Audio::{IAudioSessionControl2, ISimpleAudioVolume}, Media::Audio::{IAudioSessionControl2, ISimpleAudioVolume},
System::{Com::{CoInitializeEx, COINIT_MULTITHREADED}, Threading::WaitForSingleObject, WindowsProgramming::INFINITE}, Storage::FileSystem::{FindFirstChangeNotificationW, FILE_NOTIFY_CHANGE_LAST_WRITE, FindCloseChangeNotification}, Foundation::HANDLE, System::{Com::{CoInitializeEx, COINIT_MULTITHREADED}, Threading::WaitForSingleObject, WindowsProgramming::INFINITE}, Storage::FileSystem::{FindFirstChangeNotificationW, FILE_NOTIFY_CHANGE_LAST_WRITE, FindCloseChangeNotification, FindNextChangeNotification}, Foundation::HANDLE,
}, w, }, w,
}; };
@@ -176,15 +176,20 @@ impl Drop for MuterThread {
} }
} }
fn load_mute_txt() -> HashSet<String> { fn load_mute_txt(file_name: &str) -> HashSet<String> {
let file = File::open("mute.txt").unwrap(); let file = File::open(file_name).unwrap();
return HashSet::from_iter(BufReader::new(file).lines().map(|line| line.unwrap())); return HashSet::from_iter(BufReader::new(file).lines().map(|line| line.unwrap()));
} }
fn await_file_change() -> Result<(), Box<dyn Error>> { fn await_file_change(file_name: &str) -> Result<(), Box<dyn Error>> {
unsafe { unsafe {
let md = fs::metadata(file_name)?.modified()?;
let handle = FindFirstChangeNotificationW(w!("."), false, FILE_NOTIFY_CHANGE_LAST_WRITE)?; let handle = FindFirstChangeNotificationW(w!("."), false, FILE_NOTIFY_CHANGE_LAST_WRITE)?;
WaitForSingleObject(HANDLE{0: handle.0}, INFINITE).ok()?; while md == fs::metadata(file_name)?.modified()? {
WaitForSingleObject(HANDLE{0: handle.0}, INFINITE).ok()?;
FindNextChangeNotification(handle);
}
println!("File change detected, restarting");
FindCloseChangeNotification(handle).ok()?; FindCloseChangeNotification(handle).ok()?;
Ok(()) Ok(())
} }
@@ -194,10 +199,9 @@ fn main() {
unsafe { unsafe {
CoInitializeEx(None, COINIT_MULTITHREADED).unwrap(); CoInitializeEx(None, COINIT_MULTITHREADED).unwrap();
} }
let mute_file = "mute.txt";
loop { loop {
let mut _mt = MuterThread::new(load_mute_txt()); let mut _mt = MuterThread::new(load_mute_txt(mute_file));
await_file_change().unwrap(); await_file_change(mute_file).unwrap();
} }
} }

View File

@@ -27,9 +27,3 @@ impl<'a> IAudioSessionNotification_Impl for SessionNotification {
Ok(()) Ok(())
} }
} }
impl<'a> Drop for SessionNotification {
fn drop(&mut self) {
println!("SN drop");
}
}

View File

@@ -3,7 +3,7 @@ use std::{sync::{Mutex, atomic::AtomicU32, Arc}, thread::{self, JoinHandle}};
use windows::Win32::{ use windows::Win32::{
Foundation::{HINSTANCE, HWND, WPARAM, LPARAM}, Foundation::{HINSTANCE, HWND, WPARAM, LPARAM},
UI::{ UI::{
Accessibility::{SetWinEventHook, HWINEVENTHOOK}, Accessibility::{SetWinEventHook, HWINEVENTHOOK, UnhookWinEvent},
WindowsAndMessaging::{ WindowsAndMessaging::{
DispatchMessageW, GetForegroundWindow, GetMessageW, GetWindowThreadProcessId, DispatchMessageW, GetForegroundWindow, GetMessageW, GetWindowThreadProcessId,
TranslateMessage, EVENT_SYSTEM_FOREGROUND, EVENT_SYSTEM_MINIMIZEEND, MSG, TranslateMessage, EVENT_SYSTEM_FOREGROUND, EVENT_SYSTEM_MINIMIZEEND, MSG,
@@ -53,7 +53,7 @@ type WinCallback = Box<dyn Fn(&str) + Send>;
pub fn await_win_change_events(callback: WinCallback) { pub fn await_win_change_events(callback: WinCallback) {
*WIN_CHANGE_CALLBACK.lock().unwrap() = Some(callback); *WIN_CHANGE_CALLBACK.lock().unwrap() = Some(callback);
unsafe { unsafe {
SetWinEventHook( let fg_event = SetWinEventHook(
EVENT_SYSTEM_FOREGROUND, EVENT_SYSTEM_FOREGROUND,
EVENT_SYSTEM_FOREGROUND, EVENT_SYSTEM_FOREGROUND,
HINSTANCE::default(), HINSTANCE::default(),
@@ -62,7 +62,7 @@ pub fn await_win_change_events(callback: WinCallback) {
0, 0,
WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS, WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS,
); );
SetWinEventHook( let min_event = SetWinEventHook(
EVENT_SYSTEM_MINIMIZEEND, EVENT_SYSTEM_MINIMIZEEND,
EVENT_SYSTEM_MINIMIZEEND, EVENT_SYSTEM_MINIMIZEEND,
HINSTANCE::default(), HINSTANCE::default(),
@@ -77,6 +77,8 @@ pub fn await_win_change_events(callback: WinCallback) {
TranslateMessage(&msg); TranslateMessage(&msg);
DispatchMessageW(&msg); DispatchMessageW(&msg);
} }
UnhookWinEvent(fg_event);
UnhookWinEvent(min_event);
} }
} }
@@ -98,7 +100,6 @@ impl Drop for WindowChangeMonitor {
join_handle.join().expect("Unable to terminate window change thread"); join_handle.join().expect("Unable to terminate window change thread");
} }
println!("Joined window change thread");
} }
} }