nefares / Background-Muter

Background Muter - Automatically Mute Background Applications
GNU General Public License v3.0
83 stars 8 forks source link

Minimizing window by clicking app icon on taskbar and then restoring it again by clicking on taskbar app icon does not unmute the app #14

Closed Rik-Kirtaniya closed 1 year ago

Rik-Kirtaniya commented 2 years ago

Reproduction: Run an application, then instead of minimizing it with the minimize button on it's title bar, minimize it using the app's icon on the taskbar. This causes Background Muter to successfully mute the app. However, when restoring the app window again by clicking on app icon on taskbar, it fails to unmute the app.

To make it work again, the app needs to be minimized using the title bar minimize button specifically, then restored using the taskbar app icon. Only then does it get unmuted again.

Would be nice if the former method also worked. :)

nefares commented 2 years ago

Thanks for the report. Good catch.

Unfortunately this is not straight forward to fix as it seems to be an issue with WinAPI SetWinEventHook function. The event EVENT_SYSTEM_FOREGROUND is NOT triggered for some reason when the app is restored by clicking on the app icon on the taskbar. This leads to it not being detect by BackgroundMuter since it relies on the that event to determine which window is on foreground.

The solution will probably involve looking for a better event which can also catch this case: https://docs.microsoft.com/en-us/windows/win32/winauto/event-constants

nefares commented 1 year ago

@Rik-Kirtaniya I implemented a new algorithm for checking foreground processes. Can you check if this issue is still there?

Rik-Kirtaniya commented 1 year ago

@nefares Yup works perfectly now as expected. :)

nefares commented 1 year ago

Thanks. Will close this issue.