public void SetCategory()
        {
            string category;

            if (_applicationInfo != null && _applicationInfo.Category == null)
            {
                // if app was removed, category is null, so stop using that app
                _applicationInfo.PropertyChanged -= AppInfo_PropertyChanged;
                _applicationInfo = null;
            }
            category = ApplicationInfo?.Category?.DisplayName;

            if (category == null && WinFileName.ToLower().Contains("cairodesktop.exe"))
            {
                category = "Cairo";
            }
            else if (category == null && WinFileName.ToLower().Contains("\\windows\\") && !isUWP)
            {
                category = "Windows";
            }
            else if (category == null)
            {
                category = Localization.DisplayString.sAppGrabber_Uncategorized;
            }

            if (_category != category)
            {
                _category = category;
                OnPropertyChanged("Category");
            }
        }
Beispiel #2
0
        public string GetCategory(ApplicationWindow window)
        {
            var category = GetCategoryDisplayName(window);

            switch (category)
            {
            case null when window.WinFileName.ToLower().Contains("cairodesktop.exe"):
                category = "Cairo";

                break;

            case null when window.WinFileName.ToLower().Contains("\\windows\\") && !window.IsUWP:
                category = "Windows";

                break;

            case null:
                category = Localization.DisplayString.sAppGrabber_Uncategorized;
                break;
            }

            return(category);
        }
Beispiel #3
0
        public void SetIcon()
        {
            if (!_iconLoading)
            {
                _iconLoading = true;

                var thread = new Thread(() =>
                {
                    if (WinFileName.Contains("ApplicationFrameHost.exe") && !string.IsNullOrEmpty(AppUserModelID))
                    {
                        // UWP apps
                        try
                        {
                            BitmapImage img = new BitmapImage();
                            img.BeginInit();
                            img.UriSource   = new Uri(UWPInterop.StoreAppHelper.GetAppIcon(AppUserModelID, Configuration.Settings.TaskbarIconSize)[0], UriKind.Absolute);
                            img.CacheOption = BitmapCacheOption.OnLoad;
                            img.EndInit();
                            img.Freeze();
                            Icon = img;
                        }
                        catch
                        {
                            Icon = IconImageConverter.GetDefaultIcon();
                        }
                    }
                    else
                    {
                        // non-UWP apps
                        IntPtr hIco            = default(IntPtr);
                        uint WM_GETICON        = 0x007f;
                        IntPtr IDI_APPLICATION = new IntPtr(0x7F00);
                        int GCL_HICON          = -14;
                        int GCL_HICONSM        = -34;
                        int sizeSetting        = Configuration.Settings.TaskbarIconSize;

                        if (sizeSetting == 1)
                        {
                            NativeMethods.SendMessageTimeout(Handle, WM_GETICON, 2, 0, 2, 1000, ref hIco);
                            if (hIco == IntPtr.Zero)
                            {
                                NativeMethods.SendMessageTimeout(Handle, WM_GETICON, 0, 0, 2, 1000, ref hIco);
                            }
                        }
                        else
                        {
                            NativeMethods.SendMessageTimeout(Handle, WM_GETICON, 1, 0, 2, 1000, ref hIco);
                        }

                        if (hIco == IntPtr.Zero && sizeSetting == 1)
                        {
                            if (!Environment.Is64BitProcess)
                            {
                                hIco = NativeMethods.GetClassLong(Handle, GCL_HICONSM);
                            }
                            else
                            {
                                hIco = NativeMethods.GetClassLongPtr(Handle, GCL_HICONSM);
                            }
                        }

                        if (hIco == IntPtr.Zero)
                        {
                            if (!Environment.Is64BitProcess)
                            {
                                hIco = NativeMethods.GetClassLong(Handle, GCL_HICON);
                            }
                            else
                            {
                                hIco = NativeMethods.GetClassLongPtr(Handle, GCL_HICON);
                            }
                        }

                        if (hIco == IntPtr.Zero)
                        {
                            string winFileName = GetFileNameForWindow(Handle);
                            if (Shell.Exists(winFileName))
                            {
                                int size = 1;
                                if (sizeSetting != 1)
                                {
                                    size = 0;
                                }

                                hIco = Shell.GetIconByFilename(winFileName, size);
                            }
                        }

                        if (hIco != IntPtr.Zero)
                        {
                            ImageSource icon = IconImageConverter.GetImageFromHIcon(hIco);
                            icon.Freeze();
                            Icon = icon;
                        }
                        else if (iconTries == 0)
                        {
                            DispatcherTimer getIcon = new DispatcherTimer(DispatcherPriority.Background, Application.Current.Dispatcher);
                            getIcon.Interval        = new TimeSpan(0, 0, 2);
                            getIcon.Tick           += getIcon_Tick;
                            getIcon.Start();
                        }
                    }

                    _iconLoading = false;
                });
                thread.IsBackground = true;
                thread.SetApartmentState(ApartmentState.STA);
                thread.Start();
            }
        }
        private bool getShowInTaskbar()
        {
            // EnumWindows and ShellHook return UWP app windows that are 'cloaked', which should not be visible in the taskbar.
            if (EnvironmentHelper.IsWindows8OrBetter)
            {
                int cbSize = Marshal.SizeOf(typeof(uint));
                NativeMethods.DwmGetWindowAttribute(Handle, NativeMethods.DWMWINDOWATTRIBUTE.DWMWA_CLOAKED, out var cloaked, cbSize);

                if (cloaked > 0)
                {
                    ShellLogger.Debug($"ApplicationWindow: Cloaked ({cloaked}) window ({Title}) hidden from taskbar");
                    return(false);
                }

                // UWP shell windows that are not cloaked should be hidden from the taskbar, too.
                StringBuilder cName = new StringBuilder(256);
                NativeMethods.GetClassName(Handle, cName, cName.Capacity);
                string className = cName.ToString();
                if (className == "ApplicationFrameWindow" || className == "Windows.UI.Core.CoreWindow")
                {
                    if ((ExtendedWindowStyles & (int)NativeMethods.ExtendedWindowStyles.WS_EX_WINDOWEDGE) == 0)
                    {
                        ShellLogger.Debug($"ApplicationWindow: Hiding UWP non-window {Title}");
                        return(false);
                    }
                }
                else if (!EnvironmentHelper.IsWindows10OrBetter && (className == "ImmersiveBackgroundWindow" || className == "SearchPane" || className == "NativeHWNDHost" || className == "Shell_CharmWindow" || className == "ImmersiveLauncher") && WinFileName.ToLower().Contains("explorer.exe"))
                {
                    ShellLogger.Debug($"ApplicationWindow: Hiding immersive shell window {Title}");
                    return(false);
                }
            }

            return(CanAddToTaskbar);
        }