Пример #1
0
        public WindowsPlatform(Form form)
            : base(new WindowsPreferences())
        {
            MainForm       = form;
            MainForm.Load += delegate {
                ApplicationLaunched.Raise(this);
            };
            Application.ApplicationExit += delegate {
                ApplicationWillQuit.Raise(this);
            };

            SystemEvents.PowerModeChanged += PowerModeChanged;
        }
Пример #2
0
 void HandleNSApplicationSharedApplicationDidFinishLaunching(object sender, EventArgs e)
 {
     ApplicationLaunched.Raise(this);
 }
        private void Watcher_DoWork(object sender, DoWorkEventArgs e)
        {
            while (!e.Cancel && !Watcher.CancellationPending)
            {
                bool hasChanged = false;
                int  left       = 50 + (ListedProcesses.Count * (40 + 5));

                Dictionary <uint[], string> chromeWindows = new Dictionary <uint[], string>();
                chromeWindows.Add(WindowsByClassFinder.WindowTitlesForClass("Chrome_WidgetWin_0"), WindowsByClassFinder.WindowTitlesForClass("Chrome_WidgetWin_1"));

                Process[] procs = Process.GetProcesses(".");

                try
                {
                    foreach (Process proc in procs)
                    {
                        try
                        {
                            if (proc.MainWindowTitle == "" || ExcludedApplicationNames.Contains(proc.MainWindowTitle.ToLower()) || !proc.Responding)
                            {
                                continue;
                            }

                            ProcessInfo exists = Exists(proc.MainWindowHandle);

                            if (exists != null)
                            {
                                if (exists.Title != proc.MainWindowTitle)
                                {
                                    UpdateTitle(exists);
                                }
                                continue;
                            }

                            uint threadID = proc.MainWindowHandle.GetThreadProcessId();

                            if (ListedProcesses.ContainsThreadID(threadID))
                            {
                                continue;
                            }

                            ProcessInfo pi = new ProcessInfo()
                            {
                                Location     = proc.MainModule.FileName,
                                MainHandle   = proc.MainWindowHandle,
                                ThreadID     = threadID,
                                Name         = proc.ProcessName,
                                TargetHandle = IntPtr.Zero,
                                Title        = proc.MainWindowTitle
                            };

                            GenerateItem(new Point(left, 0), pi, proc.MainModule.FileName);
                            hasChanged = true;

                            if (!firstRun)
                            {
                                ApplicationLaunched?.Invoke(pi, null);
                            }

                            left += ITEM_WIDTH + 5;

                            ListedProcesses.Add(pi);
                        }
                        catch (Win32Exception wex)
                        {
                        }
                    }
                }
                finally
                {
                    foreach (Process proc in procs)
                    {
                        proc.Dispose();
                    }
                    procs = null;
                }

                foreach (KeyValuePair <uint[], string> window in chromeWindows)
                {
                    if (!string.IsNullOrWhiteSpace(window.Value))
                    {
                        try
                        {
                            ProcessInfo exists = Exists(new IntPtr(window.Key[0]));

                            if (exists != null)
                            {
                                if (exists.Title != window.Value)
                                {
                                    UpdateTitle(exists);
                                }
                                continue;
                            }

                            Process proc = Process.GetProcessById((int)window.Key[1]);

                            ProcessInfo pi = new ProcessInfo()
                            {
                                Location     = proc.MainModule.FileName,
                                MainHandle   = new IntPtr(window.Key[0]),
                                Name         = proc.ProcessName,
                                TargetHandle = new IntPtr(window.Key[1]),
                                Title        = window.Value
                            };

                            GenerateItem(new Point(left, 0), pi, proc.MainModule.FileName, window.Value);
                            hasChanged = true;

                            if (!firstRun)
                            {
                                ApplicationLaunched?.Invoke(pi, null);
                            }

                            left += ITEM_WIDTH + 5;

                            ListedProcesses.Add(pi);
                        }
                        catch (Win32Exception wex)
                        {
                        }
                    }
                }

                foreach (Controls.Taskbar.TaskbarItem item in TargetContainer.Controls.OfType <Controls.Taskbar.TaskbarItem>())
                {
                    if (!IsOpen(item.ProcessInformation.Name, item.ProcessInformation.TargetHandle == IntPtr.Zero ? item.ProcessInformation.MainHandle : IntPtr.Zero, item.ProcessInformation.ThreadID))
                    {
                        ListedProcesses.Remove(item.ProcessInformation);
                        TargetContainer.Invoke(new MethodInvoker(() =>
                        {
                            item.Dispose();
                        }));
                        hasChanged = true;
                    }
                    else if (item.ProcessInformation.MainHandle.GetWindowState() == WindowExtensions.WindowState.Minimized)
                    {
                        item.ProcessInformation.MainHandle.SendToBack();
                    }
                }

                if (hasChanged)
                {
                    Reposition();
                }

                if (firstRun)
                {
                    firstRun = false;
                }

                System.Threading.Thread.Sleep(500);
            }
        }