Skip to content

Commit

Permalink
Added serial numbers to devices list. Added --no-control support
Browse files Browse the repository at this point in the history
  • Loading branch information
alfeg committed Aug 28, 2019
1 parent e23e53d commit 070303d
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 9 deletions.
2 changes: 2 additions & 0 deletions DeviceManager/AdbManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public List<DeviceData> GetDevices()
continue;
}

if(!line.Contains("device")) continue;

if(skipping) continue;

if(string.IsNullOrWhiteSpace(line)) continue;
Expand Down
2 changes: 1 addition & 1 deletion DeviceManager/DeviceManager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>1</ApplicationRevision>
<ApplicationVersion>1.1.0.%2a</ApplicationVersion>
<ApplicationVersion>1.3.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<PublishWizardCompleted>true</PublishWizardCompleted>
<BootstrapperEnabled>true</BootstrapperEnabled>
Expand Down
60 changes: 52 additions & 8 deletions DeviceManager/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using DeviceManager.Properties;
Expand Down Expand Up @@ -40,20 +41,29 @@ static void Main()
if (CanViewDevices())
{
var viewMenu = devices.Select(device =>
new MenuItem(device.Model, (o, _) => { ViewDevice(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)
{
ViewDevice(deviceData);
Thread.Sleep(1500);
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,
var restartMenu = devices.Select(device => new MenuItem(device.Model + " - " + device.Serial,
(o, eventArgs) => { RestartAction(client, device); })).ToArray();

menu.MenuItems.Add(new MenuItem("Restart", restartMenu));
Expand All @@ -70,6 +80,7 @@ static void Main()
}

};

// Show the system tray icon.
using (var pi = new ProcessIcon(menu))
{
Expand Down Expand Up @@ -126,7 +137,7 @@ private static void RestartAction(AdbManager client, DeviceData device)
if (targetDevice != null && targetDevice.State == DeviceState.Online)
{
await Task.Delay(TimeSpan.FromSeconds(5));
ViewDevice(targetDevice);
ViewDevice(targetDevice, false);
return;
}
}
Expand Down Expand Up @@ -161,16 +172,49 @@ private static bool CanViewDevices()
return File.Exists(scr);
}

private static void ViewDevice(DeviceData device)
private static void Log(string message)
{
File.AppendAllLines("log.log", new [] { message});
}

private static void ViewDevice(DeviceData device, bool mirror, int? bitrate = null)
{
var scr = Path.Combine(Settings.Default.ScrCpyPath, "scrcpy-noconsole.exe");
var processStartInfo = new ProcessStartInfo(scr, "-t -s " + device.Serial)

var args = new[]
{
UseShellExecute = false,
mirror ? "--no-control" : "",
"-s " + device.Serial,
//"--window-title \"" + device.Model + " - " + device.Serial + "\"",
bitrate == null ? "" : "-b " + bitrate
};

var arguments = string.Join(" ", args.Where(x => !string.IsNullOrWhiteSpace(x)));

var processStartInfo = new ProcessStartInfo(scr, arguments)
{
UseShellExecute = true,
WorkingDirectory = Settings.Default.ScrCpyPath
};

Process.Start(processStartInfo);
Log($"ViewDevice: {device.Model} - {device.Serial}. Args: {arguments}");

var process = Process.Start(processStartInfo);

if (process != null)
{
process.Exited += (sender, eventArgs) =>
{
//// only restart once, do not go crazy if device cannot be viewed
//if (bitrate == null)
//{
// if (process.ExitCode != 0)
// {
// ViewDevice(device, mirror, bitrate: 80000);
// }
//}
};
}
}

private static void RestoreConfig()
Expand Down

0 comments on commit 070303d

Please sign in to comment.