예제 #1
0
        static void Main()
        {
            RestoreConfig();
            SetScrPath();
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var menu = new ContextMenu();

            menu.Popup += (sender, args) =>
            {
                var client  = new SharpAdbClient.AdbClient();
                var devices = client.GetDevices();

                menu.MenuItems.Clear();

                menu.MenuItems.Add(new MenuItem("Set srccpy path", (o, eventArgs) => { ChooseScrPath(); }));

                if (CanViewDevices())
                {
                    var viewMenu = devices.Select(device =>
                                                  new MenuItem(device.Model, (o, eventArgs) => { ViewDevice(device); }))
                                   .ToArray();

                    menu.MenuItems.Add(new MenuItem("View", viewMenu));
                }

                var restartMenu = devices.Select(device => new MenuItem(device.Model,
                                                                        (o, eventArgs) => { RestartAction(client, device); })).ToArray();

                menu.MenuItems.Add(new MenuItem("Restart", restartMenu));

                menu.MenuItems.Add(new MenuItem("Exit", (o, eventArgs) => { Application.Exit(); }));
            };
            // Show the system tray icon.
            using (var pi = new ProcessIcon(menu))
            {
                pi.Display();

                // Make sure the application runs!
                Application.Run();
            }
        }
예제 #2
0
        static void Main()
        {
            RestoreConfig();
            SetScrPath();
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var menu = new ContextMenu();

            menu.Popup += (sender, args) =>
            {
                var client = new AdbManager(Settings.Default.ScrCpyPath);

                menu.MenuItems.Clear();
                menu.MenuItems.Add(new MenuItem("Set scrcpy path", (o, eventArgs) => { ChooseScrPath(); }));

                try
                {
                    var devices = client.GetDevices();

                    if (CanViewDevices())
                    {
                        var viewMenu = devices.Select(device =>
                                                      new MenuItem(device.Model + " - " + device.Serial, (o, _) => { ViewDevice(device, false); }))
                                       .ToArray();

                        menu.MenuItems.Add(new MenuItem("View", viewMenu));
                        menu.MenuItems.Add(new MenuItem("View all", (o, _) =>
                        {
                            foreach (var deviceData in devices)
                            {
                                Thread.Sleep(1500);
                                client.WakeUp(deviceData);
                                ViewDevice(deviceData, false);
                            }
                        }));
                        menu.MenuItems.Add(new MenuItem("View all in mirror mode", (o, _) =>
                        {
                            foreach (var deviceData in devices)
                            {
                                Thread.Sleep(1500);
                                ViewDevice(deviceData, true);
                            }
                        }));
                    }

                    var restartMenu = devices.Select(device => new MenuItem(device.Model + " - " + device.Serial,
                                                                            (o, eventArgs) => { RestartAction(client, device); })).ToArray();

                    menu.MenuItems.Add(new MenuItem("Restart", restartMenu));
                }
                catch
                {
                    TryRestartAdb();

                    menu.MenuItems.Add(new MenuItem("Cannot connect to adb server", (o, eventArgs) => { }));
                }
                finally
                {
                    menu.MenuItems.Add(new MenuItem("Exit", (o, eventArgs) => { Application.Exit(); }));
                }
            };

            // Show the system tray icon.
            using (var pi = new ProcessIcon(menu))
            {
                pi.Display();

                // Make sure the application runs!
                Application.Run();
            }
        }