Skip to content

Commit

Permalink
Merge pull request #524 from Macro-Deck-App/improve-adb-server
Browse files Browse the repository at this point in the history
Add option to enable and disable ADB + Improve ADB service for USB connection
  • Loading branch information
manuelmayer-dev authored May 10, 2024
2 parents e125c44 + 7ea3758 commit cc9cbcf
Show file tree
Hide file tree
Showing 10 changed files with 367 additions and 164 deletions.
4 changes: 2 additions & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="AdvancedSharpAdbClient" Version="3.3.12" />
<PackageVersion Include="CommandLineParser" Version="2.9.1" />
<PackageVersion Include="Cottle" Version="2.0.10" />
<PackageVersion Include="Dax-FCTB" Version="2.16.26.120" />
Expand All @@ -11,10 +12,9 @@
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
<PackageVersion Include="Microsoft.Win32.Registry" Version="5.0.0" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="sharpadbclient" Version="2.3.23" />
<PackageVersion Include="sqlite-net-pcl" Version="1.8.116" />
<PackageVersion Include="System.Collections" Version="4.3.0" />
<PackageVersion Include="System.Drawing.Common" Version="8.0.0" />
<PackageVersion Include="System.Drawing.Common" Version="8.0.4" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
Expand Down
6 changes: 6 additions & 0 deletions MacroDeck/Configuration/MainConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ public class MainConfiguration
[JsonProperty("Update.InstallBeta")]
public bool UpdateBetaVersions { get; set; }

[JsonProperty("Connection.Adb.Enabled")]
public bool EnableAdbServer { get; set; } = true;

[JsonProperty("Connection.Adb.AutoStartApp")]
public bool EnableAdbAutoStartApp { get; set; } = true;

[JsonProperty("Connection.Ssl.Enabled")]
public bool EnableSsl { get; set; }

Expand Down
109 changes: 77 additions & 32 deletions MacroDeck/GUI/MainWindowViews/SettingsView.Designer.cs

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions MacroDeck/GUI/MainWindowViews/SettingsView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,22 @@ private void LoadNetworkConfiguration()
checkEnableSsl.Checked = MacroDeck.Configuration.EnableSsl;
certificatePath.Text = MacroDeck.Configuration.SslCertificatePath;
certificatePassword.Text = MacroDeck.Configuration.SslCertificatePassword;
checkEnableAdb.Checked = MacroDeck.Configuration.EnableAdbServer;
checkAutoStartUsb.Checked = MacroDeck.Configuration.EnableAdbAutoStartApp;
checkEnableAdb.CheckedChanged += CheckEnableAdb_CheckedChanged;
checkAutoStartUsb.CheckedChanged += CheckAutoStartUsb_CheckedChanged;
}

private void CheckAutoStartUsb_CheckedChanged(object? sender, EventArgs e)
{
MacroDeck.Configuration.EnableAdbAutoStartApp = checkAutoStartUsb.Checked;
MacroDeck.Configuration.Save(ApplicationPaths.MainConfigFilePath);
}

private void CheckEnableAdb_CheckedChanged(object? sender, EventArgs e)
{
MacroDeck.Configuration.EnableAdbServer = checkEnableAdb.Checked;
MacroDeck.Configuration.Save(ApplicationPaths.MainConfigFilePath);
}

private void LoadAutoStart()
Expand Down
64 changes: 62 additions & 2 deletions MacroDeck/GUI/MainWindowViews/SettingsView.resx
Original file line number Diff line number Diff line change
@@ -1,4 +1,64 @@
<root>
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
Expand Down Expand Up @@ -65,7 +125,7 @@
AAEAAAD/////AQAAAAAAAAAMAgAAAEZTeXN0ZW0uV2luZG93cy5Gb3JtcywgQ3VsdHVyZT1uZXV0cmFs
LCBQdWJsaWNLZXlUb2tlbj1iNzdhNWM1NjE5MzRlMDg5BQEAAAAmU3lzdGVtLldpbmRvd3MuRm9ybXMu
SW1hZ2VMaXN0U3RyZWFtZXIBAAAABERhdGEHAgIAAAAJAwAAAA8DAAAAfg4AAAJNU0Z0AUkBTAIBAQUB
AAGQAQABkAEAATABAAEwAQAE/wEFAQAI/wFCAU0BdgcAAXYDAAEoAwABwAMAAWADAAEBAQABBAYAASQY
AAGoAQABqAEAATABAAEwAQAE/wEFAQAI/wFCAU0BdgcAAXYDAAEoAwABwAMAAWADAAEBAQABBAYAASQY
AAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAA4ADAAH/AgAB/wMAAv8BAAH/AwAB/wEAAf8B
AAL/AgAD//8A/wD/AA0AAQ8C/10AAQ8D/1wAAQ8D/wHwWwABDwT/AfBaAAEPBf9aAAEPAv8B8AEPAf9a
AAEPAv8B8FwAAQ8C/wHwXQAD/10AA/9dAAP/XQAD/10AAQ8C/wHwXAABDwL/AfBcAAEPAv8B8FoAAQ8B
Expand Down
9 changes: 4 additions & 5 deletions MacroDeck/MacroDeck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ internal static void Start(StartParameters startParameters)
SearchNetworkInterfaces();
MacroDeckServer.Start(StartParameters.Port <= 0 ? Configuration.HostPort : StartParameters.Port);
BroadcastServer.Start();
ADBServerHelper.Initialize();
Task.Run(async () => await AdbServerHelper.Initialize());

ProfileManager.AddVariableChangedListener();
ProfileManager.AddWindowFocusChangedListener();
Expand All @@ -114,7 +114,7 @@ internal static void Start(StartParameters startParameters)
TrayIcon.SetupTrayIcon(TrayIconContextMenu,
ShowMainWindow,
() => RestartMacroDeck(string.Join(" ", StartParameters)),
Exit);
Exit);

using (_mainWindow = new MainWindow())
{
Expand Down Expand Up @@ -243,7 +243,7 @@ public static void RequestRestart()
using var msgBox = new GUI.CustomControls.MessageBox();
if (msgBox.ShowDialog(LanguageManager.Strings.MacroDeckNeedsARestart, LanguageManager.Strings.MacroDeckMustBeRestartedForTheChanges, MessageBoxButtons.YesNo) == DialogResult.Yes)
{
MacroDeck.RestartMacroDeck();
RestartMacroDeck();
}
}

Expand Down Expand Up @@ -318,7 +318,6 @@ private static void MainWindowLoadEvent(object? sender, EventArgs e)

public static void Exit()
{
ADBServerHelper.Kill();
Environment.Exit(0);
Application.Exit();
}
}
4 changes: 2 additions & 2 deletions MacroDeck/MacroDeck.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<Platforms>AnyCPU;x64</Platforms>
<SelfContained>true</SelfContained>
<OutputType>WinExe</OutputType>
<Nullable>disable</Nullable>
<Nullable>annotations</Nullable>
</PropertyGroup>

<ItemGroup>
Expand All @@ -40,6 +40,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="AdvancedSharpAdbClient" />
<PackageReference Include="CommandLineParser" />
<PackageReference Include="Cottle" />
<PackageReference Include="Dax-FCTB" />
Expand All @@ -48,7 +49,6 @@
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" />
<PackageReference Include="Microsoft.Win32.Registry" />
<PackageReference Include="Newtonsoft.Json" />
<PackageReference Include="sharpadbclient" />
<PackageReference Include="sqlite-net-pcl" />
<PackageReference Include="System.Collections" />
<PackageReference Include="System.Drawing.Common" />
Expand Down
4 changes: 3 additions & 1 deletion MacroDeck/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Diagnostics;
using System.Threading;
using System.Windows.Forms;
using SuchByte.MacroDeck.Server;

namespace SuchByte.MacroDeck;

Expand All @@ -19,6 +20,7 @@ private static void Main(string[] args)
// Register exception event handlers
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
Application.ThreadException += ApplicationThreadException;

AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;


Expand All @@ -29,7 +31,7 @@ private static void Main(string[] args)

MacroDeck.Start(startParameters);
}

private static void CheckRunningInstance(int ignoredPid)
{
var proc = Process.GetCurrentProcess();
Expand Down
120 changes: 0 additions & 120 deletions MacroDeck/Server/ADBServerHelper.cs

This file was deleted.

Loading

0 comments on commit cc9cbcf

Please sign in to comment.