From b2823a8f84fab34d3c367ff48abb73a97bfab252 Mon Sep 17 00:00:00 2001 From: wherewhere Date: Wed, 21 Feb 2024 17:26:03 +0800 Subject: [PATCH] Release v3.1.10 --- .github/ISSUE_TEMPLATE/bug_report.yaml | 2 ++ .../AdvancedSharpAdbClient.Tests.csproj | 6 ++--- .../DeviceCommands/DeviceClient.Async.cs | 26 +++++++++++++++++++ .../DeviceCommands/DeviceClient.cs | 20 ++++++++++++++ .../DeviceCommands/DeviceExtensions.Async.cs | 12 +++------ .../DeviceCommands/DeviceExtensions.cs | 12 +++------ .../DeviceCommands/Models/Element.cs | 8 +++--- .../Models/InstallProgress.EventArgs.cs | 8 +++++- README.md | 6 ++--- 9 files changed, 73 insertions(+), 27 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yaml b/.github/ISSUE_TEMPLATE/bug_report.yaml index f84ff81..f2f916d 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yaml +++ b/.github/ISSUE_TEMPLATE/bug_report.yaml @@ -32,6 +32,7 @@ body: description: Specify the version of AdvancedSharpAdbClient you're using. options: - "Latest Source" + - "3.1.10" - "3.0.9" - "2.5.8" - "2.5.7" @@ -103,6 +104,7 @@ body: - "MonoDevelop 5.x" - "MonoDevelop 4.x" - "MonoDevelop 3.x" + - "Rider 2024" - "Rider 2023" - "Rider 2022" - "Rider 2021" diff --git a/AdvancedSharpAdbClient.Tests/AdvancedSharpAdbClient.Tests.csproj b/AdvancedSharpAdbClient.Tests/AdvancedSharpAdbClient.Tests.csproj index 2ffe849..ce41458 100644 --- a/AdvancedSharpAdbClient.Tests/AdvancedSharpAdbClient.Tests.csproj +++ b/AdvancedSharpAdbClient.Tests/AdvancedSharpAdbClient.Tests.csproj @@ -24,13 +24,13 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive - - + + runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/AdvancedSharpAdbClient/DeviceCommands/DeviceClient.Async.cs b/AdvancedSharpAdbClient/DeviceCommands/DeviceClient.Async.cs index 87c6b8d..4bf8a9e 100644 --- a/AdvancedSharpAdbClient/DeviceCommands/DeviceClient.Async.cs +++ b/AdvancedSharpAdbClient/DeviceCommands/DeviceClient.Async.cs @@ -458,6 +458,32 @@ public async Task SendTextAsync(string text, CancellationToken cancellationToken } } + /// + /// Asynchronously clear the input text. The input should be in focus. Use if the element isn't focused. + /// + /// The length of text to clear. + /// A which can be used to cancel the asynchronous operation. + /// A which represents the asynchronous operation. + public async Task ClearInputAsync(int charCount, CancellationToken cancellationToken = default) + { + await SendKeyEventAsync("KEYCODE_MOVE_END", cancellationToken).ConfigureAwait(false); + await SendKeyEventAsync(StringExtensions.Join(" ", Enumerable.Repeat("KEYCODE_DEL", charCount)), cancellationToken).ConfigureAwait(false); + } + + /// + /// Asynchronously click BACK button. + /// + /// A which can be used to cancel the asynchronous operation. + /// A which represents the asynchronous operation. + public Task ClickBackButtonAsync(CancellationToken cancellationToken = default) => SendKeyEventAsync("KEYCODE_BACK", cancellationToken); + + /// + /// Asynchronously click HOME button. + /// + /// A which can be used to cancel the asynchronous operation. + /// A which represents the asynchronous operation. + public Task ClickHomeButtonAsync(CancellationToken cancellationToken = default) => SendKeyEventAsync("KEYCODE_HOME", cancellationToken); + /// /// Start an Android application on device asynchronously. /// diff --git a/AdvancedSharpAdbClient/DeviceCommands/DeviceClient.cs b/AdvancedSharpAdbClient/DeviceCommands/DeviceClient.cs index b88c67c..dfcdd37 100644 --- a/AdvancedSharpAdbClient/DeviceCommands/DeviceClient.cs +++ b/AdvancedSharpAdbClient/DeviceCommands/DeviceClient.cs @@ -378,6 +378,26 @@ public void SendText(string text) } } + /// + /// Clear the input text. The input should be in focus. Use if the element isn't focused. + /// + /// The length of text to clear. + public void ClearInput(int charCount) + { + SendKeyEvent("KEYCODE_MOVE_END"); + SendKeyEvent(StringExtensions.Join(" ", Enumerable.Repeat("KEYCODE_DEL", charCount))); + } + + /// + /// Click BACK button. + /// + public void ClickBackButton() => SendKeyEvent("KEYCODE_BACK"); + + /// + /// Click HOME button. + /// + public void ClickHomeButton() => SendKeyEvent("KEYCODE_HOME"); + /// /// Start an Android application on device. /// diff --git a/AdvancedSharpAdbClient/DeviceCommands/DeviceExtensions.Async.cs b/AdvancedSharpAdbClient/DeviceCommands/DeviceExtensions.Async.cs index 83ce456..7a1c644 100644 --- a/AdvancedSharpAdbClient/DeviceCommands/DeviceExtensions.Async.cs +++ b/AdvancedSharpAdbClient/DeviceCommands/DeviceExtensions.Async.cs @@ -150,12 +150,8 @@ public static Task SendTextAsync(this IAdbClient client, DeviceData device, stri /// The length of text to clear. /// A which can be used to cancel the asynchronous operation. /// A which represents the asynchronous operation. - public static async Task ClearInputAsync(this IAdbClient client, DeviceData device, int charCount, CancellationToken cancellationToken = default) - { - DeviceClient deviceClient = new(client, device); - await deviceClient.SendKeyEventAsync("KEYCODE_MOVE_END", cancellationToken).ConfigureAwait(false); - await deviceClient.SendKeyEventAsync(StringExtensions.Join(" ", Enumerable.Repeat("KEYCODE_DEL", charCount)), cancellationToken).ConfigureAwait(false); - } + public static Task ClearInputAsync(this IAdbClient client, DeviceData device, int charCount, CancellationToken cancellationToken = default) => + new DeviceClient(client, device).ClearInputAsync(charCount, cancellationToken); /// /// Asynchronously click BACK button. @@ -165,7 +161,7 @@ public static async Task ClearInputAsync(this IAdbClient client, DeviceData devi /// A which can be used to cancel the asynchronous operation. /// A which represents the asynchronous operation. public static Task ClickBackButtonAsync(this IAdbClient client, DeviceData device, CancellationToken cancellationToken = default) => - new DeviceClient(client, device).SendKeyEventAsync("KEYCODE_BACK", cancellationToken); + new DeviceClient(client, device).ClickBackButtonAsync(cancellationToken); /// /// Asynchronously click HOME button. @@ -175,7 +171,7 @@ public static Task ClickBackButtonAsync(this IAdbClient client, DeviceData devic /// A which can be used to cancel the asynchronous operation. /// A which represents the asynchronous operation. public static Task ClickHomeButtonAsync(this IAdbClient client, DeviceData device, CancellationToken cancellationToken = default) => - new DeviceClient(client, device).SendKeyEventAsync("KEYCODE_HOME", cancellationToken); + new DeviceClient(client, device).ClickHomeButtonAsync(cancellationToken); /// /// Asynchronously start an Android application on device. diff --git a/AdvancedSharpAdbClient/DeviceCommands/DeviceExtensions.cs b/AdvancedSharpAdbClient/DeviceCommands/DeviceExtensions.cs index 94fcffa..2f5e24a 100644 --- a/AdvancedSharpAdbClient/DeviceCommands/DeviceExtensions.cs +++ b/AdvancedSharpAdbClient/DeviceCommands/DeviceExtensions.cs @@ -133,12 +133,8 @@ public static void SendText(this IAdbClient client, DeviceData device, string te /// An instance of a class that implements the interface. /// The device on which to clear the input text. /// The length of text to clear. - public static void ClearInput(this IAdbClient client, DeviceData device, int charCount) - { - DeviceClient deviceClient = new(client, device); - deviceClient.SendKeyEvent("KEYCODE_MOVE_END"); - deviceClient.SendKeyEvent(StringExtensions.Join(" ", Enumerable.Repeat("KEYCODE_DEL", charCount))); - } + public static void ClearInput(this IAdbClient client, DeviceData device, int charCount)=> + new DeviceClient(client, device).ClearInput(charCount); /// /// Click BACK button. @@ -146,7 +142,7 @@ public static void ClearInput(this IAdbClient client, DeviceData device, int cha /// An instance of a class that implements the interface. /// The device on which to click BACK button. public static void ClickBackButton(this IAdbClient client, DeviceData device) => - new DeviceClient(client, device).SendKeyEvent("KEYCODE_BACK"); + new DeviceClient(client, device).ClickBackButton(); /// /// Click HOME button. @@ -154,7 +150,7 @@ public static void ClickBackButton(this IAdbClient client, DeviceData device) => /// An instance of a class that implements the interface. /// The device on which to click HOME button. public static void ClickHomeButton(this IAdbClient client, DeviceData device) => - new DeviceClient(client, device).SendKeyEvent("KEYCODE_HOME"); + new DeviceClient(client, device).ClickHomeButton(); /// /// Start an Android application on device. diff --git a/AdvancedSharpAdbClient/DeviceCommands/Models/Element.cs b/AdvancedSharpAdbClient/DeviceCommands/Models/Element.cs index 6a02682..8cbd578 100644 --- a/AdvancedSharpAdbClient/DeviceCommands/Models/Element.cs +++ b/AdvancedSharpAdbClient/DeviceCommands/Models/Element.cs @@ -268,13 +268,13 @@ public void SendText(string text) } /// - /// Clear the input text. Use if the element is focused. + /// Clear the input text. Use if the element is focused. /// [MemberNotNull(nameof(Text))] public void ClearInput() => ClearInput(Text!.Length); /// - /// Clear the input text. Use if the element is focused. + /// Clear the input text. Use if the element is focused. /// /// The length of text to clear. public void ClearInput(int charCount) @@ -331,7 +331,7 @@ public async Task SendTextAsync(string text, CancellationToken cancellationToken } /// - /// Asynchronously clear the input text. Use if the element is focused. + /// Asynchronously clear the input text. Use if the element is focused. /// /// A which can be used to cancel the asynchronous operation. /// A which represents the asynchronous operation. @@ -340,7 +340,7 @@ public Task ClearInputAsync(CancellationToken cancellationToken = default) => ClearInputAsync(Text!.Length, cancellationToken); /// - /// Asynchronously clear the input text. Use if the element is focused. + /// Asynchronously clear the input text. Use if the element is focused. /// /// The length of text to clear. /// A which can be used to cancel the asynchronous operation. diff --git a/AdvancedSharpAdbClient/Models/InstallProgress.EventArgs.cs b/AdvancedSharpAdbClient/Models/InstallProgress.EventArgs.cs index 0f9773a..7710713 100644 --- a/AdvancedSharpAdbClient/Models/InstallProgress.EventArgs.cs +++ b/AdvancedSharpAdbClient/Models/InstallProgress.EventArgs.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Runtime.InteropServices; using System.Text; namespace AdvancedSharpAdbClient.Models @@ -87,7 +88,12 @@ public override string ToString() split.Add(c); } - StringBuilder builder = new(new string(split.ToArray())); + StringBuilder builder = +#if NET + new StringBuilder().Append(CollectionsMarshal.AsSpan(split)); +#else + new(new string(split.ToArray())); +#endif if (PackageRequired > 0) { diff --git a/README.md b/README.md index 5f2527c..130c6bd 100644 --- a/README.md +++ b/README.md @@ -246,7 +246,7 @@ The text field should be in focus static void Main(string[] args) { ... - adbClient.ClearInput(deviceData, 25); // The second argument is to specify the maximum number of characters to be erased + deviceClient.ClearInput(25); // The argument is to specify the maximum number of characters to be erased ... } ``` @@ -294,9 +294,9 @@ catch (Exception ex) static void Main(string[] args) { ... - adbClient.ClickBackButton(device); // Click Back button + deviceClient.ClickBackButton(); // Click Back button ... - adbClient.ClickHomeButton(device); // Click Home button + deviceClient.ClickHomeButton(); // Click Home button ... } ```