Remove extraneous logging
Version bump
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -4,7 +4,7 @@ version = 3
|
||||
|
||||
[[package]]
|
||||
name = "auto_mute_tool"
|
||||
version = "0.1.0"
|
||||
version = "0.2.0"
|
||||
dependencies = [
|
||||
"windows",
|
||||
]
|
||||
|
||||
@@ -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
|
||||
|
||||
3
mute.txt
3
mute.txt
@@ -13,4 +13,5 @@ hollow_knight.exe
|
||||
sm64.us.f3dex2e.exe
|
||||
teardown.exe
|
||||
underrail.exe
|
||||
valheim.exe
|
||||
valheim.exe
|
||||
Spotify.exe
|
||||
@@ -50,9 +50,3 @@ impl IMMNotificationClient_Impl for DeviceNotificationClient {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for DeviceNotificationClient {
|
||||
fn drop(&mut self) {
|
||||
println!("DNC Drop");
|
||||
}
|
||||
}
|
||||
24
src/main.rs
24
src/main.rs
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -27,9 +27,3 @@ impl<'a> IAudioSessionNotification_Impl for SessionNotification {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Drop for SessionNotification {
|
||||
fn drop(&mut self) {
|
||||
println!("SN drop");
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user