コード例 #1
0
ファイル: Program.cs プロジェクト: alfeg/ScrCpyHelper
        private static void RestartAction(AdbManager client, DeviceData device)
        {
            client.Reboot(device);

            Task.Factory.StartNew(async() =>
            {
                while (true)
                {
                    await Task.Delay(TimeSpan.FromSeconds(1));
                    var targetDevice = client.GetDevices().SingleOrDefault(d => d.Serial == device.Serial);

                    if (targetDevice != null && targetDevice.State == DeviceState.Online)
                    {
                        await Task.Delay(TimeSpan.FromSeconds(5));
                        ViewDevice(targetDevice, false);
                        return;
                    }
                }
            });
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: alfeg/ScrCpyHelper
        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();
            }
        }