示例#1
0
        private static readonly float MIN_VOLUME = 0f; // might make this a really small decimal due to the potential of float errors

        //private static Guid guid = Guid.NewGuid();

        public static async void CheckForMuteConditions()
        {
            await Task.Run(() =>
            {
                int potentialAudioCount = 0;
                foreach (string wallpaper in WallpaperPathing.ActiveWallpapers)
                {
                    if (WallpaperManagerTools.IsSupportedVideoType(wallpaper))
                    {
                        potentialAudioCount++;
                    }
                }
                //?if (potentialAudioCount == 0) return; // there's no need to check for muting if no wallpapers that can be muted exist

                bool muted = false;

                void ProcessMute()
                {
                    MuteWallpapers();
                    muted = true;
                }

                if (OptionsData.ThemeOptions.VideoOptions.MuteIfApplicationFocused && !muted)
                {
                    Process activeWindow = WindowTools.GetActiveWindowProcess();
                    string windowName    = activeWindow.ProcessName;
                    if (windowName != Process.GetCurrentProcess().ProcessName&& windowName != "explorer")  //? explorer includes the desktop
                    {
                        WindowPlacementStyle windowStyle = WindowTools.GetWindowStyle(activeWindow);
                        if (windowStyle == WindowPlacementStyle.Normal || windowStyle == WindowPlacementStyle.Maximized)
                        {
                            ProcessMute();
                        }
                    }
                }

                if (OptionsData.ThemeOptions.VideoOptions.MuteIfApplicationMaximized && !muted) // every window needs to be checked for maximization
                {
                    //xStopwatch test = new Stopwatch();
                    //xtest.Start();
                    foreach (Process p in Process.GetProcesses()) //? has the potential to take up a decent CPU load, not noticeable on the thread but still impactful
                    {
                        WindowPlacementStyle windowStyle = WindowTools.GetWindowStyle(p);

                        if (windowStyle == WindowPlacementStyle.Maximized)
                        {
                            ProcessMute();
                            break;
                        }
                    }
                    //xtest.Stop();
                    //xDebug.WriteLine("Ms taken to check for maximized app: " + test.ElapsedMilliseconds);
                }

                if ((OptionsData.ThemeOptions.VideoOptions.MuteIfAudioPlaying || WallpaperData.WallpaperManagerForm.IsViewingInspector) && !muted)
                {
                    if (CheckForExternalAudio()) //? CheckForExternalAudio cannot be done on the UI thread | async doesn't fix this
                    {
                        ProcessMute();
                    }
                }

                if (IsWallpapersMuted && !muted)
                {
                    UnmuteWallpapers();
                }
            }).ConfigureAwait(false);

            //x while (thread.IsAlive) { /* do nothing | Thread.Join() will just freeze the application */ } << this is only needed if you're returning something
        }