public void Run() { _logger.LogInformation(@"Copying keys.."); mKeyHelper = new KeyHelper(true); string adbFile = Path.Combine(Directory.GetCurrentDirectory(), "platform_tools", "adb.exe"); Uri apkStoreUri = new Uri(_secureSettings.ApkStoreHost != null ? _secureSettings.ApkStoreHost : "https://apks.netlyt.io/"); mPkgMgr = PackageManager.CreateWithUrlAndFetch(apkStoreUri, mPackages.ToArray()); mPackage = AskForPackageName(); mAdb = new AdbManager(adbFile); mAdb.ListenForDevices(); mAdb.DeviceConnected += async(sender, e) => { var d = e.Device; _logger.LogInformation($"Device connected: {d.Name}[{d.ToString()}]"); await CheckPrerequisites(d); await InstallPackage(d, mPackage); }; mAdb.DeviceDisconnected += (sender, e) => { var d = e.Device; _logger.LogInformation($"Device disconnected: {d.Name}[{d.ToString()}]"); }; installToCurrentDevices(mPackage).Wait(); while (true) { Console.ReadLine(); } }
private void StartListening() { mAdb.ListenForDevices(); mAdb.DeviceConnected += async(sender, e) => { var d = e.Device; string mPackage = GetSelectedPackage(); Console.WriteLine($"Device connected: {d.Model} {d.Name}[{d.ToString()}]"); Application.Current.Dispatcher?.Invoke(new Action(() => { lblStatus.Text = $"Device connected: {d.Name}[{d.ToString()}]"; var sp = GetSelectedPackage(); if (GetSelectedDevice() == null && sp != null) { lblIcon.Content = $"To install `{sp}`, select a device."; } UpdateDevices(d); })); if (mPackage == null) { return; } //Mark that we're installing Application.Current.Dispatcher?.Invoke(new Action(() => { var dlbl = $"{d.Model} [{d.Serial}]"; NotifyInstallStarted(mPackage, dlbl); lblIcon.Content = $"Installation started on {dlbl}"; })); await CheckPrerequisites(d); await InstallPackage(d, mPackage); }; mAdb.DeviceDisconnected += (sender, e) => { var d = e.Device; Console.WriteLine($"Device disconnected: {d.Name}[{d.ToString()}]"); Application.Current.Dispatcher?.Invoke(new Action(() => { UpdateDevices(d, true); lblStatus.Text = $"Device disconnected: {d.Name}[{d.ToString()}]"; })); }; }