Example #1
0
        public WindowViewModel( WindowInfo window )
        {
            Window = window;

            Process process = window.GetProcess();
            ProcessName = process?.ProcessName ?? "Not Found!";
            CompanyName = process?.MainModule.FileVersionInfo.CompanyName ?? "";
            ClassName = window.GetClassName();
            Title = window.GetTitle();
            IsVisible = window.IsVisible();
        }
Example #2
0
        ApplicationBehaviorsProcess GetProcessSettings( WindowInfo window )
        {
            // See whether settings are cached.
            if ( _accessDeniedWindows.Contains( window ) )
            {
                return _dontHandleProcess;
            }
            if ( _windowProcessBehaviors.ContainsKey( window ) )
            {
                return _windowProcessBehaviors[ window ];
            }

            // Prevent cached settings from being kept in memory when windows are destroyed.
            var deniedToRemove = _accessDeniedWindows.Where( w => w.IsDestroyed() ).ToArray();
            deniedToRemove.ForEach( w => _accessDeniedWindows.Remove( w ) );
            var processBehaviorsToRemove = _windowProcessBehaviors.Where( p => p.Key.IsDestroyed() ).ToArray();
            processBehaviorsToRemove.ForEach( p => _windowProcessBehaviors.Remove( p.Key ) );

            // Get settings.
            Process process = window.GetProcess();
            try
            {
                // Find matching settings based on process file info.
                var matches = _settings.Process.Where( p => new TargetProcess( p.Name, p.CompanyName, p.Version ).Matches( process ) ).ToList();

                // Select the most optimal match, or handle the process by default when no match found.
                ApplicationBehaviorsProcess processBehavior = matches.Count == 0
                    ? _handleProcess
                    : matches.MaxBy( p => p.Version?.Length ?? 0 );  // Longest version number that matches is most 'specific'.
                _windowProcessBehaviors[ window ] = processBehavior;

                return processBehavior;
            }
            catch ( Win32Exception )
            {
                _accessDeniedWindows.Add( window );
                return _dontHandleProcess;
            }
        }
Example #3
0
        public IEnumerable<WindowInfo> ToCut( WindowInfo windowInfo, VirtualDesktopManager desktopManager )
        {
            var windows = new List<WindowInfo>();

            switch ( Hide )
            {
                case ApplicationBehaviorsProcessHideBehaviorDefaultHide.SelectedWindow:
                {
                    windows.Add( windowInfo );
                    break;
                }
                case ApplicationBehaviorsProcessHideBehaviorDefaultHide.AllProcessWindows:
                {
                    var searchWindows = CutHelper.WindowsToSearchIn( desktopManager, ConsiderWindows );

                    var processWindows = searchWindows.Where( w =>
                    {
                        Process cutProcess = windowInfo.GetProcess();
                        Process otherProcess = w.GetProcess();
                        return
                            cutProcess != null && otherProcess != null &&
                            cutProcess.Id == otherProcess.Id;
                    } );
                    windows.AddRange( processWindows );
                    break;
                }
            }

            return windows;
        }