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]]
name = "auto_mute_tool"
version = "0.1.0"
version = "0.2.0"
dependencies = [
"windows",
]

View File

@@ -1,6 +1,6 @@
[package]
name = "auto_mute_tool"
version = "0.1.0"
version = "0.2.0"
edition = "2021"
# 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
teardown.exe
underrail.exe
valheim.exe
valheim.exe
Spotify.exe

View File

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

View File

@@ -8,7 +8,7 @@ use std::{
collections::HashSet,
error::Error,
ffi::OsString,
fs::File,
fs::{File, self},
io::{BufRead, BufReader},
path::Path,
ptr::null_mut,
@@ -22,7 +22,7 @@ use windows::{
core::{Interface},
Win32::{
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,
};
@@ -176,15 +176,20 @@ impl Drop for MuterThread {
}
}
fn load_mute_txt() -> HashSet<String> {
let file = File::open("mute.txt").unwrap();
fn load_mute_txt(file_name: &str) -> HashSet<String> {
let file = File::open(file_name).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 {
let md = fs::metadata(file_name)?.modified()?;
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()?;
Ok(())
}
@@ -194,10 +199,9 @@ fn main() {
unsafe {
CoInitializeEx(None, COINIT_MULTITHREADED).unwrap();
}
let mute_file = "mute.txt";
loop {
let mut _mt = MuterThread::new(load_mute_txt());
await_file_change().unwrap();
let mut _mt = MuterThread::new(load_mute_txt(mute_file));
await_file_change(mute_file).unwrap();
}
}

View File

@@ -27,9 +27,3 @@ impl<'a> IAudioSessionNotification_Impl for SessionNotification {
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::{
Foundation::{HINSTANCE, HWND, WPARAM, LPARAM},
UI::{
Accessibility::{SetWinEventHook, HWINEVENTHOOK},
Accessibility::{SetWinEventHook, HWINEVENTHOOK, UnhookWinEvent},
WindowsAndMessaging::{
DispatchMessageW, GetForegroundWindow, GetMessageW, GetWindowThreadProcessId,
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) {
*WIN_CHANGE_CALLBACK.lock().unwrap() = Some(callback);
unsafe {
SetWinEventHook(
let fg_event = SetWinEventHook(
EVENT_SYSTEM_FOREGROUND,
EVENT_SYSTEM_FOREGROUND,
HINSTANCE::default(),
@@ -62,7 +62,7 @@ pub fn await_win_change_events(callback: WinCallback) {
0,
WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS,
);
SetWinEventHook(
let min_event = SetWinEventHook(
EVENT_SYSTEM_MINIMIZEEND,
EVENT_SYSTEM_MINIMIZEEND,
HINSTANCE::default(),
@@ -77,6 +77,8 @@ pub fn await_win_change_events(callback: WinCallback) {
TranslateMessage(&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");
}
println!("Joined window change thread");
}
}