From a4afdd90da80a30fef41f24bda01a4d6be7b9184 Mon Sep 17 00:00:00 2001 From: pdone <617941447@qq.com> Date: Fri, 13 Oct 2023 15:20:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E7=89=B9=E6=80=A7=E5=92=8C=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E4=BF=AE=E5=A4=8D=201.=E5=A2=9E=E5=8A=A0=E6=97=A0?= =?UTF-8?q?=E7=BA=BF=E8=AE=BF=E9=97=AE=E8=AE=B0=E5=BD=95=E5=8E=86=E5=8F=B2?= =?UTF-8?q?IP=202.=E4=BF=AE=E5=A4=8D=E4=B8=80=E4=BA=9Bbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FreeControl.sln | 6 - FreeControl/Controller.Designer.cs | 1 + FreeControl/Controller.cs | 102 +---------- FreeControl/FreeControl.csproj | 29 +-- FreeControl/Main.Designer.cs | 98 +++++----- FreeControl/Main.cs | 188 +++++++++++--------- FreeControl/Main.resx | 70 ++++---- FreeControl/Properties/AssemblyInfo.cs | 4 +- FreeControl/Properties/Settings.Designer.cs | 26 --- FreeControl/Properties/Settings.settings | 7 - FreeControl/Setting.cs | 2 + FreeControl/Utils/ADB.cs | 4 +- FreeControl/Utils/Extend.cs | 44 +++++ FreeControl/Utils/MoveListener.cs | 139 +++++++++++++++ FreeControl/Utils/SysEnvironment.cs | 17 -- README.md | 46 ++++- 16 files changed, 435 insertions(+), 348 deletions(-) delete mode 100644 FreeControl/Properties/Settings.Designer.cs delete mode 100644 FreeControl/Properties/Settings.settings create mode 100644 FreeControl/Utils/Extend.cs create mode 100644 FreeControl/Utils/MoveListener.cs diff --git a/FreeControl.sln b/FreeControl.sln index 6a1d72c..0705f49 100644 --- a/FreeControl.sln +++ b/FreeControl.sln @@ -8,19 +8,13 @@ EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU - Debug|x86 = Debug|x86 Release|Any CPU = Release|Any CPU - Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {EF7540E1-F2E7-4682-80AB-92354C55A4C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {EF7540E1-F2E7-4682-80AB-92354C55A4C6}.Debug|Any CPU.Build.0 = Debug|Any CPU - {EF7540E1-F2E7-4682-80AB-92354C55A4C6}.Debug|x86.ActiveCfg = Debug|x86 - {EF7540E1-F2E7-4682-80AB-92354C55A4C6}.Debug|x86.Build.0 = Debug|x86 {EF7540E1-F2E7-4682-80AB-92354C55A4C6}.Release|Any CPU.ActiveCfg = Release|Any CPU {EF7540E1-F2E7-4682-80AB-92354C55A4C6}.Release|Any CPU.Build.0 = Release|Any CPU - {EF7540E1-F2E7-4682-80AB-92354C55A4C6}.Release|x86.ActiveCfg = Release|x86 - {EF7540E1-F2E7-4682-80AB-92354C55A4C6}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/FreeControl/Controller.Designer.cs b/FreeControl/Controller.Designer.cs index 14e7427..94be295 100644 --- a/FreeControl/Controller.Designer.cs +++ b/FreeControl/Controller.Designer.cs @@ -191,6 +191,7 @@ private void InitializeComponent() this.Padding = new System.Windows.Forms.Padding(2, 0, 2, 2); this.ShowDragStretch = true; this.ShowInTaskbar = false; + this.ShowRadius = false; this.ShowTitle = false; this.Text = "控制器"; this.TopMost = true; diff --git a/FreeControl/Controller.cs b/FreeControl/Controller.cs index 893ae23..c2e3237 100644 --- a/FreeControl/Controller.cs +++ b/FreeControl/Controller.cs @@ -1,92 +1,31 @@ using FreeControl.Utils; using Sunny.UI; using System; -using System.Diagnostics; using System.Drawing; -using System.Runtime.InteropServices; -using System.Timers; using System.Windows.Forms; namespace FreeControl { public partial class Controller : UIForm { - [DllImport("user32.dll")] - public static extern bool GetWindowRect(IntPtr hWnd, out Rect lpRect); - - [StructLayout(LayoutKind.Sequential)] - public struct Rect - { - public int Left; - public int Top; - public int Right; - public int Bottom; - } - - /// - /// 监听scrcpy窗体移动后的坐标 - /// - private readonly System.Timers.Timer timer; - /// - /// scrcpy句柄 - /// - private IntPtr scrcpyWindow = IntPtr.Zero; - /// - /// 进程名称 - /// - private const string scrcpyWindowName = "scrcpy"; - /// - /// 上一个有效的scrcpy坐标 - /// - private Rect lastRect = new Rect(); - public Controller() { InitializeComponent(); InitButton(); InitFormSizeAndLocation(); - - timer = new System.Timers.Timer - { - Interval = 15 - }; - timer.Elapsed += OnTimedEvent; - timer.Enabled = true; - Disposed += (s, e) => - { - Main._Setting.ScrcpyPointX = lastRect.Left; - Main._Setting.ScrcpyPointY = lastRect.Top; - }; } - public void StopTimer() - { - timer.Stop(); - timer.Enabled = false; - } - - private void OnTimedEvent(Object source, ElapsedEventArgs e) + /// + /// 更新控制器位置 + /// + public void UpdateLocation() { Action action = () => { - if (scrcpyWindow == IntPtr.Zero) - { - Process[] processes = Process.GetProcessesByName(scrcpyWindowName); - scrcpyWindow = processes[0].MainWindowHandle; - } - GetWindowRect(scrcpyWindow, out Rect rect); - if (rect.Top == lastRect.Top && rect.Left == lastRect.Left) - return; - if (rect.Left + rect.Top > 0) - { - rect.Left += 8; - rect.Top += 31; - lastRect = rect; - Location = new Point(rect.Left - 57, rect.Top); - } + // 减去控制器自身默认宽度 + Location = new Point(Main._Setting.ScrcpyPointX - 57, Main._Setting.ScrcpyPointY); }; - if (InvokeRequired) - Invoke(action); + Invoke(action); } /// @@ -108,7 +47,6 @@ void InitFormSizeAndLocation() } if (Main._Setting.ScrcpyPointX + Main._Setting.ScrcpyPointY > 0) { - // Location = new Point(Main._Setting.ControllerStartPointX, Main._Setting.ControllerStartPointY); StartPosition = FormStartPosition.Manual; Location = new Point(Main._Setting.ScrcpyPointX - 57, Main._Setting.ScrcpyPointY); } @@ -116,18 +54,11 @@ void InitFormSizeAndLocation() { StartPosition = FormStartPosition.CenterScreen; } - // LocationChanged += (sender, e) => - // { - // Main._Setting.ControllerStartPointX = Location.X; - // Main._Setting.ControllerStartPointY = Location.Y; - // }; SizeChanged += (sender, e) => { Main._Setting.ControllerStartWidth = Width; Main._Setting.ControllerStartHeight = Height; }; - // MouseDown += (s, e) => DragWindow(); - // flowPanel.FlowLayoutPanel.MouseDown += (s, e) => DragWindow(); } /// @@ -159,24 +90,5 @@ void InitButton() } } } - - #region 拖动窗口 - [DllImport("user32.dll")]//拖动无窗体的控件 - public static extern bool ReleaseCapture(); - [DllImport("user32.dll")] - public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam); - public const int WM_SYSCOMMAND = 0x0112; - public const int SC_MOVE = 0xF010; - public const int HTCAPTION = 0x0002; - - /// - /// 拖动窗体 - /// - public void DragWindow() - { - ReleaseCapture(); - SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0); - } - #endregion } } diff --git a/FreeControl/FreeControl.csproj b/FreeControl/FreeControl.csproj index 2a83c02..5786f96 100644 --- a/FreeControl/FreeControl.csproj +++ b/FreeControl/FreeControl.csproj @@ -69,24 +69,6 @@ app.manifest - - true - bin\x86\Debug\ - DEBUG;TRACE - full - x86 - 7.3 - prompt - - - bin\x86\Release\ - TRACE - true - pdbonly - x86 - 7.3 - prompt - False @@ -142,9 +124,11 @@ + + @@ -165,15 +149,6 @@ Resources.Designer.cs - - SettingsSingleFileGenerator - Settings.Designer.cs - - - True - Settings.settings - True - diff --git a/FreeControl/Main.Designer.cs b/FreeControl/Main.Designer.cs index b35c241..d0dc5b1 100644 --- a/FreeControl/Main.Designer.cs +++ b/FreeControl/Main.Designer.cs @@ -34,14 +34,15 @@ private void InitializeComponent() this.navImgList = new System.Windows.Forms.ImageList(this.components); this.navTab = new Sunny.UI.UITabControlMenu(); this.tabHome = new System.Windows.Forms.TabPage(); + this.tbxIp = new Sunny.UI.UITextBox(); this.linkIssues = new Sunny.UI.UILinkLabel(); this.tbxPort = new Sunny.UI.UITextBox(); this.cbxUseWireless = new Sunny.UI.UICheckBox(); - this.tbxAddress = new Sunny.UI.UITextBox(); this.linkSetPort = new Sunny.UI.UILinkLabel(); this.linkEnabledADB = new Sunny.UI.UILinkLabel(); this.uiLabel1 = new Sunny.UI.UILabel(); this.btnStart = new Sunny.UI.UISymbolButton(); + this.comboIp = new Sunny.UI.UIComboBox(); this.tabSetting = new System.Windows.Forms.TabPage(); this.uiLabel6 = new Sunny.UI.UILabel(); this.comboPx = new Sunny.UI.UIComboBox(); @@ -70,7 +71,6 @@ private void InitializeComponent() this.uDarkMode = new Sunny.UI.UILabel(); this.switchDarkMode = new Sunny.UI.UISwitch(); this.cbxAllFPS = new Sunny.UI.UICheckBox(); - this.lbTitle = new System.Windows.Forms.Label(); this.btnClose = new Sunny.UI.UIButton(); this.btnMini = new Sunny.UI.UIButton(); this.navTab.SuspendLayout(); @@ -112,6 +112,7 @@ private void InitializeComponent() this.navTab.Controls.Add(this.tabHome); this.navTab.Controls.Add(this.tabSetting); this.navTab.DrawMode = System.Windows.Forms.TabDrawMode.OwnerDrawFixed; + this.navTab.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(242)))), ((int)(((byte)(242)))), ((int)(((byte)(244))))); this.navTab.Font = new System.Drawing.Font("微软雅黑", 12F); this.navTab.ImageList = this.navImgList; this.navTab.ItemSize = new System.Drawing.Size(50, 50); @@ -122,7 +123,7 @@ private void InitializeComponent() this.navTab.SelectedIndex = 0; this.navTab.Size = new System.Drawing.Size(658, 278); this.navTab.SizeMode = System.Windows.Forms.TabSizeMode.Fixed; - this.navTab.Style = Sunny.UI.UIStyle.Custom; + this.navTab.Style = Sunny.UI.UIStyle.Gray; this.navTab.TabBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(250)))), ((int)(((byte)(250)))), ((int)(((byte)(250))))); this.navTab.TabIndex = 6; this.navTab.TabSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(240)))), ((int)(((byte)(240)))), ((int)(((byte)(240))))); @@ -131,20 +132,43 @@ private void InitializeComponent() // tabHome // this.tabHome.BackColor = System.Drawing.Color.Transparent; + this.tabHome.Controls.Add(this.tbxIp); this.tabHome.Controls.Add(this.linkIssues); this.tabHome.Controls.Add(this.tbxPort); this.tabHome.Controls.Add(this.cbxUseWireless); - this.tabHome.Controls.Add(this.tbxAddress); this.tabHome.Controls.Add(this.linkSetPort); this.tabHome.Controls.Add(this.linkEnabledADB); this.tabHome.Controls.Add(this.uiLabel1); this.tabHome.Controls.Add(this.btnStart); + this.tabHome.Controls.Add(this.comboIp); this.tabHome.ImageIndex = 0; this.tabHome.Location = new System.Drawing.Point(51, 0); this.tabHome.Name = "tabHome"; this.tabHome.Size = new System.Drawing.Size(607, 278); this.tabHome.TabIndex = 0; // + // tbxIp + // + this.tbxIp.Cursor = System.Windows.Forms.Cursors.IBeam; + this.tbxIp.FillColor = System.Drawing.Color.White; + this.tbxIp.Font = new System.Drawing.Font("微软雅黑", 11F); + this.tbxIp.Location = new System.Drawing.Point(206, 229); + this.tbxIp.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.tbxIp.Maximum = 2147483647D; + this.tbxIp.Minimum = -2147483648D; + this.tbxIp.MinimumSize = new System.Drawing.Size(1, 1); + this.tbxIp.Name = "tbxIp"; + this.tbxIp.Padding = new System.Windows.Forms.Padding(5); + this.tbxIp.RadiusSides = ((Sunny.UI.UICornerRadiusSides)((Sunny.UI.UICornerRadiusSides.LeftTop | Sunny.UI.UICornerRadiusSides.LeftBottom))); + this.tbxIp.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140))))); + this.tbxIp.RectDisableColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140))))); + this.tbxIp.Size = new System.Drawing.Size(129, 29); + this.tbxIp.Style = Sunny.UI.UIStyle.Custom; + this.tbxIp.StyleCustomMode = true; + this.tbxIp.TabIndex = 24; + this.tbxIp.TextAlignment = System.Drawing.ContentAlignment.MiddleLeft; + this.tbxIp.Watermark = "输入IP地址"; + // // linkIssues // this.linkIssues.ActiveLinkColor = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(155)))), ((int)(((byte)(40))))); @@ -170,7 +194,7 @@ private void InitializeComponent() this.tbxPort.Cursor = System.Windows.Forms.Cursors.IBeam; this.tbxPort.FillColor = System.Drawing.Color.White; this.tbxPort.Font = new System.Drawing.Font("微软雅黑", 11F); - this.tbxPort.Location = new System.Drawing.Point(363, 229); + this.tbxPort.Location = new System.Drawing.Point(373, 229); this.tbxPort.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.tbxPort.Maximum = 2147483647D; this.tbxPort.Minimum = -2147483648D; @@ -179,7 +203,7 @@ private void InitializeComponent() this.tbxPort.Padding = new System.Windows.Forms.Padding(5); this.tbxPort.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140))))); this.tbxPort.RectDisableColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140))))); - this.tbxPort.Size = new System.Drawing.Size(67, 27); + this.tbxPort.Size = new System.Drawing.Size(67, 29); this.tbxPort.Style = Sunny.UI.UIStyle.Custom; this.tbxPort.StyleCustomMode = true; this.tbxPort.TabIndex = 26; @@ -200,27 +224,6 @@ private void InitializeComponent() this.cbxUseWireless.TabIndex = 25; this.cbxUseWireless.Text = "无线访问"; // - // tbxAddress - // - this.tbxAddress.Cursor = System.Windows.Forms.Cursors.IBeam; - this.tbxAddress.FillColor = System.Drawing.Color.White; - this.tbxAddress.Font = new System.Drawing.Font("微软雅黑", 11F); - this.tbxAddress.Location = new System.Drawing.Point(210, 229); - this.tbxAddress.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); - this.tbxAddress.Maximum = 2147483647D; - this.tbxAddress.Minimum = -2147483648D; - this.tbxAddress.MinimumSize = new System.Drawing.Size(1, 1); - this.tbxAddress.Name = "tbxAddress"; - this.tbxAddress.Padding = new System.Windows.Forms.Padding(5); - this.tbxAddress.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140))))); - this.tbxAddress.RectDisableColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140))))); - this.tbxAddress.Size = new System.Drawing.Size(145, 27); - this.tbxAddress.Style = Sunny.UI.UIStyle.Custom; - this.tbxAddress.StyleCustomMode = true; - this.tbxAddress.TabIndex = 24; - this.tbxAddress.TextAlignment = System.Drawing.ContentAlignment.MiddleLeft; - this.tbxAddress.Watermark = "输入IP地址"; - // // linkSetPort // this.linkSetPort.ActiveLinkColor = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(155)))), ((int)(((byte)(40))))); @@ -297,6 +300,23 @@ private void InitializeComponent() this.btnStart.TabIndex = 0; this.btnStart.Text = "启动"; // + // comboIp + // + this.comboIp.DropDownStyle = Sunny.UI.UIDropDownStyle.DropDownList; + this.comboIp.FillColor = System.Drawing.Color.White; + this.comboIp.Font = new System.Drawing.Font("微软雅黑", 12F); + this.comboIp.Location = new System.Drawing.Point(206, 229); + this.comboIp.Margin = new System.Windows.Forms.Padding(0); + this.comboIp.MinimumSize = new System.Drawing.Size(63, 0); + this.comboIp.Name = "comboIp"; + this.comboIp.Padding = new System.Windows.Forms.Padding(0, 0, 30, 2); + this.comboIp.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140))))); + this.comboIp.Size = new System.Drawing.Size(159, 29); + this.comboIp.Style = Sunny.UI.UIStyle.Gray; + this.comboIp.TabIndex = 28; + this.comboIp.TextAlignment = System.Drawing.ContentAlignment.MiddleLeft; + this.comboIp.Watermark = ""; + // // tabSetting // this.tabSetting.BackColor = System.Drawing.Color.Transparent; @@ -731,16 +751,6 @@ private void InitializeComponent() this.cbxAllFPS.Text = "全帧渲染"; this.cbxAllFPS.Visible = false; // - // lbTitle - // - this.lbTitle.AutoSize = true; - this.lbTitle.Font = new System.Drawing.Font("微软雅黑", 21.75F); - this.lbTitle.Location = new System.Drawing.Point(280, 19); - this.lbTitle.Name = "lbTitle"; - this.lbTitle.Size = new System.Drawing.Size(187, 38); - this.lbTitle.TabIndex = 8; - this.lbTitle.Text = "Free Control"; - // // btnClose // this.btnClose.Cursor = System.Windows.Forms.Cursors.Hand; @@ -768,25 +778,24 @@ private void InitializeComponent() // Main // this.AllowShowTitle = false; - this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; + this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140))))); this.ClientSize = new System.Drawing.Size(658, 340); this.Controls.Add(this.btnMini); this.Controls.Add(this.ledTitle); this.Controls.Add(this.btnClose); - this.Controls.Add(this.lbTitle); this.Controls.Add(this.navTab); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.MaximizeBox = false; this.Name = "Main"; this.Padding = new System.Windows.Forms.Padding(0); - this.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(130)))), ((int)(((byte)(130)))), ((int)(((byte)(130))))); + this.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140))))); this.ShowRect = false; this.ShowTitle = false; this.ShowTitleIcon = true; this.Style = Sunny.UI.UIStyle.Custom; this.Text = ""; - this.TitleColor = System.Drawing.Color.FromArgb(((int)(((byte)(130)))), ((int)(((byte)(130)))), ((int)(((byte)(130))))); + this.TitleColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140))))); this.TitleHeight = 63; this.navTab.ResumeLayout(false); this.tabHome.ResumeLayout(false); @@ -798,7 +807,6 @@ private void InitializeComponent() this.uiGroupBox1.ResumeLayout(false); this.cbxOtherSetting.ResumeLayout(false); this.ResumeLayout(false); - this.PerformLayout(); } @@ -824,7 +832,7 @@ private void InitializeComponent() private Sunny.UI.UILinkLabel linkSetPort; private Sunny.UI.UITextBox tbxPort; private Sunny.UI.UICheckBox cbxUseWireless; - private Sunny.UI.UITextBox tbxAddress; + private Sunny.UI.UITextBox tbxIp; private Sunny.UI.UIGroupBox uiGroupBox1; private Sunny.UI.UILabel uiLabel4; private Sunny.UI.UILabel uiLabel3; @@ -835,7 +843,6 @@ private void InitializeComponent() private Sunny.UI.UILinkLabel linkIssues; private Sunny.UI.UIRadioButtonGroup rbtnShortcuts; private Sunny.UI.UILabel lbAllShortcut; - private System.Windows.Forms.Label lbTitle; private Sunny.UI.UIButton btnClose; private Sunny.UI.UIButton btnMini; private Sunny.UI.UIComboBox comboMaxFPS; @@ -846,6 +853,7 @@ private void InitializeComponent() private Sunny.UI.UIComboBox comboPx; private Sunny.UI.UICheckBox cbxControllerEnabled; private Sunny.UI.UICheckBox cbxAudioEnabled; + private Sunny.UI.UIComboBox comboIp; } } diff --git a/FreeControl/Main.cs b/FreeControl/Main.cs index 420bc4a..143f3bf 100644 --- a/FreeControl/Main.cs +++ b/FreeControl/Main.cs @@ -44,11 +44,35 @@ public partial class Main : UIForm /// /// 控制器 /// - private static Controller _Controller = null; + public static Controller _Controller = null; /// /// 启动参数 /// private List StartParameters = new List(); + /// + /// 是否是初始化 + /// + private bool IsInit = true; + + public class Info + { + /// + /// 程序名称 不带空格 + /// + public static readonly string Name = "FreeControl"; + /// + /// 程序名称 带空格 + /// + public static readonly string Name2 = "Free Control"; + /// + /// scrcpy标题 + /// + public static readonly string ScrcpyTitle = "FreeControlScrcpy"; + /// + /// 程序名称 带版本号 + /// + public static string NameVersion { get; set; } + } #endregion #region 构造函数 @@ -59,6 +83,7 @@ public Main() { InitializeComponent(); InitPdone(); + IsInit = false; } #endregion @@ -70,7 +95,7 @@ public static string UserDataPath { get { - return Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "FreeControl"); + return Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Info.Name); } } /// @@ -152,10 +177,10 @@ public void InitPdone() }; FormClosed += (sender, e) => Application.Exit(); // 窗口拖动 - MouseDown += (sender, e) => DragWindow(); - ledTitle.MouseDown += (sender, e) => DragWindow(); - tabHome.MouseDown += (sender, e) => DragWindow(); - tabSetting.MouseDown += (sender, e) => DragWindow(); + MouseDown += (sender, e) => Extend.DragWindow(Handle); + ledTitle.MouseDown += (sender, e) => Extend.DragWindow(Handle); + tabHome.MouseDown += (sender, e) => Extend.DragWindow(Handle); + tabSetting.MouseDown += (sender, e) => Extend.DragWindow(Handle); // 关闭按钮和最小化按钮 btnClose.Click += (sender, e) => Close(); btnMini.Click += (sender, e) => WindowState = FormWindowState.Minimized; @@ -171,8 +196,10 @@ public void InitPdone() comboPx.SelectedValueChanged += ComboPx_SelectedValueChanged; comboMbps.SelectedValueChanged += ComboMbps_SelectedValueChanged; comboMaxFPS.SelectedValueChanged += ComboMaxFPS_SelectedValueChanged; + comboIp.SelectedIndexChanged += (sender, e) => tbxIp.Text = comboIp.SelectedItem as string; + LoadHistoryIPs(); // 文本框 - tbxAddress.TextChanged += TbxAddress_TextChanged; + tbxIp.TextChanged += TbxAddress_TextChanged; tbxPort.TextChanged += TbxPort_TextChanged; // CheckBox cbxUseWireless.ValueChanged += CbxUseWireless_ValueChanged; @@ -190,11 +217,9 @@ public void InitPdone() #endregion #region 设置标题和图标 - Text = $"Free Control v{fvi.ProductVersion}"; - lbTitle.Visible = false; - lbTitle.Text = Text; - lbTitle.ForeColor = Color.FromArgb(250, 240, 230); - ledTitle.Text = Text; + Info.NameVersion = $"Free Control v{fvi.ProductVersion}"; + Text = Info.NameVersion; + ledTitle.Text = Info.NameVersion; ledTitle.CharCount = 19; Icon = Properties.Resources.pcm; #endregion @@ -219,7 +244,8 @@ public void InitPdone() comboMaxFPS.SelectedIndex = _Setting.MaxFPSIndex; rbtnShortcuts.SelectedIndex = _Setting.ShortcutsIndex; switchDarkMode.Active = _Setting.DarkMode; - tbxAddress.Text = _Setting.IPAddress; + tbxIp.Text = _Setting.IPAddress; + comboIp.Text = _Setting.IPAddress; tbxPort.Text = _Setting.Port; updownHeight.Value = _Setting.WindowHeight; updownWidth.Value = _Setting.WindowWidth; @@ -299,7 +325,7 @@ private void StartButtonClick(object sender, EventArgs e) StartParameters.Add($"--window-x={_Setting.ScrcpyPointX} --window-y={_Setting.ScrcpyPointY}"); } // 设置标题 - StartParameters.Add($"--window-title \"{ledTitle.Text}\""); + StartParameters.Add($"--window-title \"{Info.ScrcpyTitle}\""); // 设置为文本注入 StartParameters.Add($"--prefer-text"); // 设置为按键注入 @@ -386,6 +412,11 @@ private void ADBConnectCallback(IAsyncResult ar) ShowMessage(result); return; } + if (!_Setting.IPAddress.IsNullOrWhiteSpace() + && !_Setting.HistoryIPs.Contains(_Setting.IPAddress)) + { + _Setting.HistoryIPs.Add(_Setting.IPAddress); + } RunScrcpy(); } @@ -412,9 +443,13 @@ private void RunScrcpy() RedirectStandardError = true, RedirectStandardInput = true, }; + Logger.Info(args); Process scrcpy = Process.Start(processStartInfo); scrcpy.EnableRaisingEvents = true; + // 监听Scrcpy窗口移动 + MoveListener.StartListening(scrcpy, !_Setting.UseWireless); + var tempOutput = ""; scrcpy.OutputDataReceived += (ss, ee) => { @@ -437,8 +472,10 @@ private void RunScrcpy() }; scrcpy.Exited += (ss, ee) => { + MoveListener.StopListening(); FromHandle(false); ButtonHandle(false); + LoadHistoryIPs(true); ShowMessage("已退出"); }; scrcpy.BeginErrorReadLine(); @@ -502,13 +539,33 @@ private void FromHandle(bool isStart) } else { - _Controller?.StopTimer(); _Controller?.Dispose(); Show(); + Activate(); } }; Invoke(action); } + + /// + /// 加载历史IP + /// + /// + void LoadHistoryIPs(bool isReload = false) + { + Action action = () => + { + comboIp.Items.Clear(); + _Setting.HistoryIPs.ForEach(ip => + { + comboIp.Items.Add(ip); + }); + }; + if (isReload) + Invoke(action); + else + action(); + } #endregion #region 配置项改变事件 @@ -519,18 +576,24 @@ private void FromHandle(bool isStart) /// private void SwitchDarkMode_ValueChanged(object sender, bool value) { - var tabBackColor = Color.Transparent; - var foreColor = Color.Transparent; - if (value) + UpdateStyle(value); + _Setting.DarkMode = switchDarkMode.Active; + } + + void UpdateStyle(bool isDark) + { + Color tabBackColor; + Color foreColor; + UIStyle curStyle; + if (isDark) { tabBackColor = Color.FromArgb(24, 24, 24); foreColor = Color.FromArgb(192, 192, 192); - UIStyles.SetStyle(UIStyle.Black); - tabHome.BackColor = tabBackColor; - tabSetting.BackColor = tabBackColor; + curStyle = UIStyle.Black; + UIStyles.SetStyle(curStyle); navTab.MenuStyle = UIMenuStyle.Black; - btnStart.SetStyle(UIStyle.Black); + btnStart.SetStyle(curStyle); tabHome.ImageIndex = 1; tabSetting.ImageIndex = 3; @@ -539,12 +602,11 @@ private void SwitchDarkMode_ValueChanged(object sender, bool value) { tabBackColor = Color.FromArgb(242, 242, 244); foreColor = Color.FromArgb(48, 48, 48); - UIStyles.SetStyle(UIStyle.Gray); - tabHome.BackColor = tabBackColor; - tabSetting.BackColor = tabBackColor; + curStyle = UIStyle.Gray; + UIStyles.SetStyle(curStyle); navTab.MenuStyle = UIMenuStyle.White; - btnStart.SetStyle(UIStyle.Gray); + btnStart.SetStyle(curStyle); tabHome.ImageIndex = 0; tabSetting.ImageIndex = 2; @@ -555,25 +617,33 @@ private void SwitchDarkMode_ValueChanged(object sender, bool value) navTab.TabBackColor = Color.FromArgb(222, 222, 222); } - tbxAddress.FillColor = tabBackColor; + tabHome.BackColor = tabBackColor; + tabSetting.BackColor = tabBackColor; + + tbxPort.FillColor = tabBackColor; - tbxAddress.ForeColor = foreColor; - tbxPort.ForeColor = foreColor; + tbxIp.FillColor = tabBackColor; comboPx.FillColor = tabBackColor; comboMbps.FillColor = tabBackColor; comboMaxFPS.FillColor = tabBackColor; + comboIp.FillColor = tabBackColor; + + + + tbxPort.ForeColor = foreColor; + tbxIp.ForeColor = foreColor; comboPx.ForeColor = foreColor; comboMbps.ForeColor = foreColor; comboMaxFPS.ForeColor = foreColor; + comboIp.ForeColor = foreColor; + BackColor = Color.FromArgb(140, 140, 140); btnClose.Style = UIStyle.Gray; btnClose.ForeColor = Color.FromArgb(250, 240, 230); btnMini.Style = UIStyle.Gray; btnMini.ForeColor = Color.FromArgb(250, 240, 230); - - _Setting.DarkMode = switchDarkMode.Active; } private void ComboMaxFPS_SelectedValueChanged(object sender, EventArgs e) @@ -671,43 +741,11 @@ private void CbxUseLog_ValueChanged(object sender, bool value) private void CbxUseWireless_ValueChanged(object sender, bool value) { _Setting.UseWireless = value; - // tbxAddress.Enabled = !value; - // tbxPort.Enabled = !value; - - var foreColor = Color.Transparent; - var tabBackColor = Color.Transparent; - - var tempColor = Color.Transparent; - if (_Setting.DarkMode) - { - tabBackColor = Color.FromArgb(24, 24, 24); - foreColor = Color.FromArgb(192, 192, 192); - } - else - { - tabBackColor = Color.FromArgb(242, 242, 244); - foreColor = Color.FromArgb(48, 48, 48); - } - - if (_Setting.UseWireless) - { - tbxAddress.FillDisableColor = tabBackColor; - tbxPort.FillDisableColor = tabBackColor; - tbxAddress.ForeDisableColor = foreColor; - tbxPort.ForeDisableColor = foreColor; - } - else - { - tbxAddress.FillColor = tabBackColor; - tbxPort.FillColor = tabBackColor; - tbxAddress.ForeColor = foreColor; - tbxPort.ForeColor = foreColor; - } } private void TbxAddress_TextChanged(object sender, EventArgs e) { - _Setting.IPAddress = tbxAddress.Text.Trim(); + _Setting.IPAddress = tbxIp.Text.Trim(); } private void TbxPort_TextChanged(object sender, EventArgs e) @@ -767,7 +805,8 @@ private void CommonCbx_ValueChanged(object sender, bool value) _Setting.ShowTouches = value; break; } - Logger.Info(temp.Text + ":" + value); + if (IsInit == false) + Logger.Info(temp.Text + ":" + value); } private void RbtnShortcuts_ValueChanged(object sender, int index, string text) @@ -794,25 +833,6 @@ private void cbxAudioEnabled_ValueChanged(object sender, bool value) } #endregion - #region 拖动窗口 - [DllImport("user32.dll")]// 拖动无窗体的控件 - public static extern bool ReleaseCapture(); - [DllImport("user32.dll")] - public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam); - public const int WM_SYSCOMMAND = 0x0112; - public const int SC_MOVE = 0xF010; - public const int HTCAPTION = 0x0002; - - /// - /// 拖动窗体 - /// - public void DragWindow() - { - ReleaseCapture(); - SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0); - } - #endregion - #region 文本跳转链接设置 private void linkEnabledADB_Click(object sender, EventArgs e) { diff --git a/FreeControl/Main.resx b/FreeControl/Main.resx index ef30454..613992f 100644 --- a/FreeControl/Main.resx +++ b/FreeControl/Main.resx @@ -125,7 +125,7 @@ AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0 ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAADG - GgAAAk1TRnQBSQFMAgEBBAEAAfABAQHwAQEBHgEAAR4BAAT/ASEBAAj/AUIBTQE2BwABNgMAASgDAAF4 + GgAAAk1TRnQBSQFMAgEBBAEAASABAgEgAQIBHgEAAR4BAAT/ASEBAAj/AUIBTQE2BwABNgMAASgDAAF4 AwABPAMAAQEBAAEgBQABgAFw/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A /wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A/wD/AP8A /wD/AP8A/wD/AJ4AAzgBXQMaAf8DGgH/AxoB/wMaAf8DGgH/AxoB/wMa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YAAO/Af8DWgH1VAAEAgM1AVYDQAH9AxoB/wNTAfQDGgH/A1wB2wMNARFYAAQC - AzUBVgOoAf0DvwH/A2UB9AO/Af8DYAHbAw0BEVQAA0YBfwMaAf8DKwH8A1EB9wNaAfIDUwHwA1oB9QNN - AfoDGgH/A1oB9VAAA0YBfwO/Af8DYQH8A20B9wNnAfIDXgHwA1oB9QNSAfoDvwH/A1oB9WAAA1gBtwNY + BAJMAAMMAQ8DVwG0A78B/wNiAe8DNgFXBAADUQGeA78B/wNNAfoDOAFcBAJMAANGAX8DGgH/GAADGgH/ + A1oB9VAAA0YBfwO/Af8YAAO/Af8DWgH1VAAEAgM1AVYDQAH9AxoB/wNTAfQDGgH/A2AB2wMNARFYAAQC + AzUBVgOoAf0DvwH/A2UB9AO/Af8DYAHbAw0BEVQAA0YBfwMaAf8DKwH8A1EB9wNaAfIDWgHwA1oB9QNN + AfoDGgH/A1oB9VAAA0YBfwO/Af8DYQH8A20B9wNnAfIDXgHwA1oB9QNNAfoDvwH/A1oB9WAAA1gBtwNd AeoDNgFYbAADWAG3A10B6gM2AVhcAAMMARADMAFMA0UBfANUAasDXwHaA1MB9ANaAcQDTgGWAzwBZgMg AS1QAAMMARADMAFMA0UBfANWAasDYQHaA2UB9ANbAcQDTgGWAzwBZgMgAS0oAAFCAU0BPgcAAT4DAAEo AwABeAMAATwDAAEBAQABAQUAAcABAxYAA///AOIAAfgCAAE/AeACAAH/AfwBAAL/AfABAwH/AQAB8AIA diff --git a/FreeControl/Properties/AssemblyInfo.cs b/FreeControl/Properties/AssemblyInfo.cs index 3fbcaeb..defe7bc 100644 --- a/FreeControl/Properties/AssemblyInfo.cs +++ b/FreeControl/Properties/AssemblyInfo.cs @@ -33,5 +33,5 @@ //通过使用 "*",如下所示: // [assembly: AssemblyVersion("1.0.*")] //[assembly: AssemblyVersion("1.0.0")] -[assembly: AssemblyFileVersion("1.6.3")] -[assembly: AssemblyVersion("1.6.3")] +[assembly: AssemblyFileVersion("1.6.4")] +[assembly: AssemblyVersion("1.6.4")] diff --git a/FreeControl/Properties/Settings.Designer.cs b/FreeControl/Properties/Settings.Designer.cs deleted file mode 100644 index 2d1134b..0000000 --- a/FreeControl/Properties/Settings.Designer.cs +++ /dev/null @@ -1,26 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 此代码由工具生成。 -// 运行时版本:4.0.30319.42000 -// -// 对此文件的更改可能会导致不正确的行为,并且如果 -// 重新生成代码,这些更改将会丢失。 -// -//------------------------------------------------------------------------------ - -namespace FreeControl.Properties { - - - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.10.0.0")] - internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { - - private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); - - public static Settings Default { - get { - return defaultInstance; - } - } - } -} diff --git a/FreeControl/Properties/Settings.settings b/FreeControl/Properties/Settings.settings deleted file mode 100644 index 3964565..0000000 --- a/FreeControl/Properties/Settings.settings +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/FreeControl/Setting.cs b/FreeControl/Setting.cs index a232f0a..8909767 100644 --- a/FreeControl/Setting.cs +++ b/FreeControl/Setting.cs @@ -148,6 +148,8 @@ public class Setting /// public int ScrcpyPointY { get; set; } = 0; + public List HistoryIPs { get; set; } = new List(); + /// /// 已启用的按钮名称 修改位置可进行控制器按钮排序 /// diff --git a/FreeControl/Utils/ADB.cs b/FreeControl/Utils/ADB.cs index 5818f6f..f29eed9 100644 --- a/FreeControl/Utils/ADB.cs +++ b/FreeControl/Utils/ADB.cs @@ -39,7 +39,8 @@ public static string Execute(string command) Process = Process.Start(AdbProcessInfo); Process.StandardInput.WriteLine(command); string standardOutput = Process.StandardOutput.ReadToEnd(); - Logger.Info($"{standardOutput.Trim()}", "ADB"); + if (standardOutput.IsNullOrWhiteSpace() == false) + Logger.Info($"{standardOutput.Trim()}", "ADB"); Process.WaitForExit(); Process.Dispose(); return standardOutput; @@ -48,7 +49,6 @@ public static string Execute(string command) /// /// 执行截图命令 /// - /// /// public static bool Screenshot() { diff --git a/FreeControl/Utils/Extend.cs b/FreeControl/Utils/Extend.cs new file mode 100644 index 0000000..c5643a8 --- /dev/null +++ b/FreeControl/Utils/Extend.cs @@ -0,0 +1,44 @@ +using System; +using System.Runtime.InteropServices; + +namespace FreeControl.Utils +{ + public static class Extend + { + /// + /// 指示指定的字符串是 null、空还是仅由空白字符组成。 + /// + /// + /// + public static bool IsNullOrWhiteSpace(this string str) + { + if (string.IsNullOrWhiteSpace(str)) + { + return true; + } + else + { + return false; + } + } + + #region 拖动窗口 + [DllImport("user32.dll")]// 拖动无窗体的控件 + public static extern bool ReleaseCapture(); + [DllImport("user32.dll")] + public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam); + public const int WM_SYSCOMMAND = 0x0112; + public const int SC_MOVE = 0xF010; + public const int HTCAPTION = 0x0002; + + /// + /// 拖动窗体 + /// + public static void DragWindow(IntPtr handle) + { + ReleaseCapture(); + SendMessage(handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0); + } + #endregion + } +} diff --git a/FreeControl/Utils/MoveListener.cs b/FreeControl/Utils/MoveListener.cs new file mode 100644 index 0000000..440090f --- /dev/null +++ b/FreeControl/Utils/MoveListener.cs @@ -0,0 +1,139 @@ +using System; +using System.Diagnostics; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; +using System.Timers; + +namespace FreeControl.Utils +{ + public class MoveListener + { + #region WindowsAPi + public delegate void WinEventDelegate(IntPtr hWinEventHook, uint eventType, IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime); + + private const uint EVENT_OBJECT_LOCATIONCHANGE = 0x800B; + private const uint WINEVENT_OUTOFCONTEXT = 0; + private static IntPtr hWinEventHook = IntPtr.Zero; + + [DllImport("user32.dll")] + private static extern bool GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId); + + [DllImport("user32.dll")] + private static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect); + + [DllImport("user32.dll")] + private static extern IntPtr SetWinEventHook(uint eventMin, uint eventMax, IntPtr hmodWinEventProc, WinEventDelegate lpfnWinEventProc, uint idProcess, uint idThread, uint dwFlags); + + [DllImport("user32.dll")] + private static extern bool UnhookWinEvent(IntPtr hWinEventHook); + + [DllImport("user32.dll")] + private static extern IntPtr FindWindow(string lpClassName, string lpWindowName); + + [DllImport("user32.dll")] + private static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count); + + public static string GetWindowTitle(IntPtr hWnd) + { + const int nChars = 256; + StringBuilder sb = new StringBuilder(nChars); + GetWindowText(hWnd, sb, nChars); + return sb.ToString(); + } + + [StructLayout(LayoutKind.Sequential)] + private struct RECT + { + public int Left; + public int Top; + public int Right; + public int Bottom; + } + #endregion + + #region 钩子方式 + /// + /// 被监控的进程ID + /// + private static uint idProcess = 0; + + private static void WinEventCallback(IntPtr hWinEventHook, uint eventType, IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime) + { + if (eventType == EVENT_OBJECT_LOCATIONCHANGE) + { + GetWindowThreadProcessId(hwnd, out uint processId); + if (processId == idProcess) + { + UpdateLocation(hwnd); + } + } + } + + private static RECT lastRect; + + private static void UpdateLocation(IntPtr hwnd) + { + GetWindowRect(hwnd, out RECT rect); + if (lastRect.Left == rect.Left && lastRect.Top == rect.Top) + return; + if (rect.Left + rect.Top > 0) + { + Main._Setting.ScrcpyPointX = rect.Left + 8; + Main._Setting.ScrcpyPointY = rect.Top + 31; + + Main._Controller?.UpdateLocation(); + + lastRect = rect; + } + } + #endregion + + private static Timer timer; + + public static void StartListening(Process process, bool isHook = true) + { + if (isHook)// 使用钩子监控scrcpy窗口移动 + { + idProcess = (uint)process.Id; + hWinEventHook = SetWinEventHook(EVENT_OBJECT_LOCATIONCHANGE, EVENT_OBJECT_LOCATIONCHANGE, IntPtr.Zero, WinEventCallback, MoveListener.idProcess, 0, WINEVENT_OUTOFCONTEXT); + } + else// 无线时 使用钩子无法监控到scrcpy窗口移动 暂时使用主动查询方式实现控制器吸附 + { + // 根据名称获取句柄 + IntPtr hwnd = FindWindow(null, Main.Info.ScrcpyTitle); + // 最多重试20次 + int retryTimes = 20; + while (hwnd == IntPtr.Zero) + { + if (retryTimes == 0) break; + hwnd = FindWindow(null, Main.Info.ScrcpyTitle); + if (hwnd != IntPtr.Zero) break; + System.Threading.Thread.Sleep(500); + retryTimes--; + } + if (hwnd != IntPtr.Zero) + { + timer = new Timer(15); + timer.Elapsed += (sender, e) => + { + UpdateLocation(hwnd); + }; + timer.Start(); + } + } + } + + public static void StopListening() + { + if (hWinEventHook != IntPtr.Zero) + UnhookWinEvent(hWinEventHook); + + if (timer != null) + { + timer.Stop(); + timer.Dispose(); + } + } + } +} diff --git a/FreeControl/Utils/SysEnvironment.cs b/FreeControl/Utils/SysEnvironment.cs index 6288a4d..5ed4b53 100644 --- a/FreeControl/Utils/SysEnvironment.cs +++ b/FreeControl/Utils/SysEnvironment.cs @@ -143,23 +143,6 @@ public static void SetPath(string strHome) } - /// - /// 指示指定的字符串是 null、空还是仅由空白字符组成。 - /// - /// - /// - public static bool IsNullOrWhiteSpace(this string str) - { - if (string.IsNullOrWhiteSpace(str)) - { - return true; - } - else - { - return false; - } - } - /// /// 获取实体中指定成员Description特性值 /// diff --git a/README.md b/README.md index 239da57..9b5a952 100644 --- a/README.md +++ b/README.md @@ -117,5 +117,47 @@ Android 11 及更高版本支持使用 Android 调试桥 (adb) 从工作站以 - 对于 `Android 10` 或更早版本,无法捕获音频并自动禁用。 ## 更新日志 - -[点击查看](https://awaw.cc/assets/timeline/freecontrol.html) +
+点击查看 + +### Version 1.6.4 +- 增加无线访问记录历史IP +- 修复了一些bug +### Version 1.6.3 +- 增加控制器吸附scrcpy窗口 +- 增加scrcpy窗口位置记忆 +### Version 1.6.2 +- 修复了一些bug +### Version 1.6.1 +- 修复了一些bug +- 增加音频转发开关(默认启用) +### Version 1.6.0 +- 基于scrcpy v2.1.1(x64) +### Version 1.5.1 +- 基于scrcpy v1.25(x64) +### Version 1.5.0 +- 基于scrcpy v1.21(x64) +- 优化了代码 +### Version 1.4.1 +- 修复了一些bug +- 增加了程序入口处的异常捕获 便于定位问题 +### Version 1.4.0 +- 基于scrcpy v1.19 +- 增加虚拟按键(常用功能,记忆启动时位置和大小) +- 优化了代码 +### Version 1.3.1 +- 修复了一些bug +### Version 1.3.0 +- 基于scrcpy v1.18 +- 增加了一些设置项 +- 修复了一些bug +### Version 1.2.0 +- 基于scrcpy v1.17 +- 修复了一些bug +### Version 1.1.0 +- 基于scrcpy v1.16 +- 增加了设置端口号功能 +### Version 1.0.0 +- 基于scrcpy v1.14 +- 初始版本 +