From d5e0dc98db16bf43276ac787fb41cc9c8d1ab319 Mon Sep 17 00:00:00 2001 From: BookerLiu Date: Thu, 1 Sep 2022 15:23:44 +0800 Subject: [PATCH] =?UTF-8?q?:white=5Fcheck=5Fmark:=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.config | 2 +- .../UserControls/Config/OtherControl.xaml.cs | 107 +++--- .../PannelCard/RightCardControl.xaml | 8 +- .../Windows/PixelColorPickerWindow.xaml.cs | 12 +- Control/Windows/ToDoWindow.xaml.cs | 2 - GeekDesk.csproj | 14 + MainWindow.xaml.cs | 12 +- MyThread/MouseHookThread.cs | 9 - Plugins/ShowSeconds/Common/Constants.cs | 39 +++ Plugins/ShowSeconds/SecondsWindow.xaml | 32 ++ Plugins/ShowSeconds/SecondsWindow.xaml.cs | 312 ++++++++++++++++++ .../ViewModel/SecondsDataContext.cs | 25 ++ Update.json | 6 +- app.manifest | 79 +++++ 14 files changed, 576 insertions(+), 83 deletions(-) create mode 100644 Plugins/ShowSeconds/Common/Constants.cs create mode 100644 Plugins/ShowSeconds/SecondsWindow.xaml create mode 100644 Plugins/ShowSeconds/SecondsWindow.xaml.cs create mode 100644 Plugins/ShowSeconds/ViewModel/SecondsDataContext.cs create mode 100644 app.manifest diff --git a/App.config b/App.config index d831df3..3b70a2d 100644 --- a/App.config +++ b/App.config @@ -10,7 +10,7 @@ - + diff --git a/Control/UserControls/Config/OtherControl.xaml.cs b/Control/UserControls/Config/OtherControl.xaml.cs index c6c2816..8f8a80c 100644 --- a/Control/UserControls/Config/OtherControl.xaml.cs +++ b/Control/UserControls/Config/OtherControl.xaml.cs @@ -2,7 +2,7 @@ using GeekDesk.MyThread; using GeekDesk.Util; using GeekDesk.ViewModel; -//using ShowSeconds; +using ShowSeconds; using System; using System.Diagnostics; using System.IO; @@ -121,21 +121,16 @@ namespace GeekDesk.Control.UserControls.Config private void ShowSeconds_Click(object sender, RoutedEventArgs e) { - //if (MainWindow.appData.AppConfig.SecondsWindow == true) - //{ - // //StartSecondsWindow(); - // //SecondsWindow.ShowWindow(); - // MouseHookThread.Dispose(); - // MouseHookThread.Hook(); - //} - //else - //{ - // MouseHookThread.Dispose(); - // MouseHookThread.Hook(); - //} - - MouseHookThread.Dispose(); - MouseHookThread.Hook(); + if (MainWindow.appData.AppConfig.SecondsWindow == true) + { + //StartSecondsWindow(); + SecondsWindow.ShowWindow(); + } + else + { + SecondsWindow.CloseWindow(); + //StopSecondsWindow(); + } } public static void StopSecondsWindow() @@ -149,47 +144,47 @@ namespace GeekDesk.Control.UserControls.Config } } - //public static void StartSecondsWindow() - //{ - // try - // { - // using (var objOS = new ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem")) - // { - // foreach (ManagementObject objMgmt in objOS.Get()) - // { - // if (objMgmt.Properties["Caption"].Value != null) - // { - // string caption = objMgmt.Properties["Caption"].Value.ToString(); ; - // LogUtil.WriteLog("获取的系统版本号为:" + caption); - // if (caption.Contains("Windows 11")) - // { - // //找到ShowSeconds插件 - // FileInfo fi = FileUtil.GetFileByNameWithDir("ShowSeconds.exe", Constants.PLUGINS_PATH); - // if (fi == null) - // { - // HandyControl.Controls.MessageBox.Show("未安装程序插件:ShowSeconds"); - // } - // else - // { - // //检查是否在运行 - // if (!MessageUtil.CheckWindowIsRuning("ShowSeconds_Main_" + Constants.MY_UUID)) - // { - // using (Process p = new Process()) - // { - // p.StartInfo.FileName = fi.FullName; - // p.StartInfo.WorkingDirectory = fi.FullName.Substring(0, fi.FullName.LastIndexOf("\\")); - // p.Start(); - // } - // } - // } + public static void StartSecondsWindow() + { + try + { + using (var objOS = new ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem")) + { + foreach (ManagementObject objMgmt in objOS.Get()) + { + if (objMgmt.Properties["Caption"].Value != null) + { + string caption = objMgmt.Properties["Caption"].Value.ToString(); ; + LogUtil.WriteLog("获取的系统版本号为:" + caption); + if (caption.Contains("Windows 11")) + { + //找到ShowSeconds插件 + FileInfo fi = FileUtil.GetFileByNameWithDir("ShowSeconds.exe", Constants.PLUGINS_PATH); + if (fi == null) + { + HandyControl.Controls.MessageBox.Show("未安装程序插件:ShowSeconds"); + } + else + { + //检查是否在运行 + if (!MessageUtil.CheckWindowIsRuning("ShowSeconds_Main_" + Constants.MY_UUID)) + { + using (Process p = new Process()) + { + p.StartInfo.FileName = fi.FullName; + p.StartInfo.WorkingDirectory = fi.FullName.Substring(0, fi.FullName.LastIndexOf("\\")); + p.Start(); + } + } + } - // } - // } - // } - // } - // } - // catch (Exception ex) { } - //} + } + } + } + } + } + catch (Exception ex) { } + } diff --git a/Control/UserControls/PannelCard/RightCardControl.xaml b/Control/UserControls/PannelCard/RightCardControl.xaml index 5409535..480bd9f 100644 --- a/Control/UserControls/PannelCard/RightCardControl.xaml +++ b/Control/UserControls/PannelCard/RightCardControl.xaml @@ -154,6 +154,7 @@ + VirtualizingPanel.IsVirtualizing="True" + VirtualizingPanel.IsContainerVirtualizable="True" + Margin="10" + > private void Window_MouseRightButtonDown(object sender, MouseButtonEventArgs e) { + Mouse.OverrideCursor = null; GlobalColorPickerWindow.ShowOrHide(); //关闭 this.Close(); diff --git a/Control/Windows/ToDoWindow.xaml.cs b/Control/Windows/ToDoWindow.xaml.cs index ea23153..3744b13 100644 --- a/Control/Windows/ToDoWindow.xaml.cs +++ b/Control/Windows/ToDoWindow.xaml.cs @@ -111,9 +111,7 @@ namespace GeekDesk.Control.Windows private static System.Windows.Window window = null; -#pragma warning disable CS0108 // “ToDoWindow.Show()”隐藏继承的成员“Window.Show()”。如果是有意隐藏,请使用关键字 new。 public static void Show() -#pragma warning restore CS0108 // “ToDoWindow.Show()”隐藏继承的成员“Window.Show()”。如果是有意隐藏,请使用关键字 new。 { if (window == null || !window.Activate()) { diff --git a/GeekDesk.csproj b/GeekDesk.csproj index 682d10a..e722a40 100644 --- a/GeekDesk.csproj +++ b/GeekDesk.csproj @@ -75,6 +75,9 @@ false + + app.manifest + packages\CommonServiceLocator.2.0.6\lib\net45\CommonServiceLocator.dll @@ -113,6 +116,7 @@ packages\System.Drawing.Common.6.0.0-preview.6.21352.12\lib\net461\System.Drawing.Common.dll + packages\System.Memory.4.5.4\lib\net461\System.Memory.dll @@ -267,6 +271,11 @@ + + + SecondsWindow.xaml + + @@ -429,6 +438,10 @@ MainWindow.xaml Code + + MSBuild:Compile + Designer + Designer MSBuild:Compile @@ -462,6 +475,7 @@ Resources.Designer.cs + diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index c25c25c..b41a749 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -10,7 +10,7 @@ using GeekDesk.ViewModel; using GeekDesk.ViewModel.Temp; using Microsoft.Win32; using NPinyin; -//using ShowSeconds; +using ShowSeconds; using System; using System.Collections.ObjectModel; using System.Diagnostics; @@ -181,8 +181,6 @@ namespace GeekDesk /// void Window_Loaded(object sender, RoutedEventArgs e) { - //SecondsWindow.ShowWindow(); - BGSettingUtil.BGSetting(); if (!appData.AppConfig.StartedShowPanel) { @@ -217,11 +215,17 @@ namespace GeekDesk } //注册鼠标监听事件 - if (appData.AppConfig.MouseMiddleShow || appData.AppConfig.SecondsWindow == true) + if (appData.AppConfig.MouseMiddleShow) { MouseHookThread.Hook(); } + //显秒插件 + if (appData.AppConfig.SecondsWindow == true) + { + SecondsWindow.ShowWindow(); + } + //更新线程开启 检测更新 UpdateThread.Update(); diff --git a/MyThread/MouseHookThread.cs b/MyThread/MouseHookThread.cs index 642c9dc..e2c69ed 100644 --- a/MyThread/MouseHookThread.cs +++ b/MyThread/MouseHookThread.cs @@ -3,7 +3,6 @@ using GeekDesk.Control.Windows; using GeekDesk.Util; using GeekDesk.ViewModel; using Gma.System.MouseKeyHook; -//using ShowSeconds; using System; using System.Drawing; using System.Threading; @@ -31,24 +30,16 @@ namespace GeekDesk.MyThread hook.OnMouseWheelUp += OnMouseWheelUp; } - //if (appConfig.SecondsWindow == true) - //{ - // hook.OnMouseLeftDown += OnMouseLeftDown; - // hook.OnMouseLeftUp += OnMouseLeftUp; - //} - hook.Start(true, false); })); } private static void OnMouseLeftDown(object sender, System.Windows.Forms.MouseEventArgs e) { - //SecondsWindow.SecondsBakColorFun(sender, e); } private static void OnMouseLeftUp(object sender, System.Windows.Forms.MouseEventArgs e) { - //SecondsWindow.SecondsHookSetFuc(sender, e); } private static void OnMouseWheelUp(object sender, System.Windows.Forms.MouseEventArgs e) diff --git a/Plugins/ShowSeconds/Common/Constants.cs b/Plugins/ShowSeconds/Common/Constants.cs new file mode 100644 index 0000000..227626a --- /dev/null +++ b/Plugins/ShowSeconds/Common/Constants.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShowSeconds.Common +{ + public class Constants + { + public readonly static string MY_UUID = "8400A17AEEF7C029"; + + //dark theam + public readonly static System.Windows.Media.SolidColorBrush darkBG + = new System.Windows.Media.SolidColorBrush + { + Color = System.Windows.Media.Color.FromRgb(46, 50, 54), + Opacity = 0.8 + }; + public readonly static System.Windows.Media.SolidColorBrush darkFont + = new System.Windows.Media.SolidColorBrush + { + Color = System.Windows.Media.Color.FromRgb(255, 255, 255) + }; + + //light theam + public readonly static System.Windows.Media.SolidColorBrush lightBG + = new System.Windows.Media.SolidColorBrush + { + Color = System.Windows.Media.Color.FromRgb(236, 244, 251), + Opacity = 1 + }; + public readonly static System.Windows.Media.SolidColorBrush lightFont + = new System.Windows.Media.SolidColorBrush + { + Color = System.Windows.Media.Color.FromRgb(65, 63, 61), + }; + } +} diff --git a/Plugins/ShowSeconds/SecondsWindow.xaml b/Plugins/ShowSeconds/SecondsWindow.xaml new file mode 100644 index 0000000..87719ff --- /dev/null +++ b/Plugins/ShowSeconds/SecondsWindow.xaml @@ -0,0 +1,32 @@ + + + + + + + + + + + diff --git a/Plugins/ShowSeconds/SecondsWindow.xaml.cs b/Plugins/ShowSeconds/SecondsWindow.xaml.cs new file mode 100644 index 0000000..cb4dc68 --- /dev/null +++ b/Plugins/ShowSeconds/SecondsWindow.xaml.cs @@ -0,0 +1,312 @@ +using GeekDesk.Util; +using Gma.System.MouseKeyHook; +using ShowSeconds.Common; +using GeekDesk.Util; +using ShowSeconds.ViewModel; +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using System.Timers; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; +using System.Windows.Threading; +using GeekDesk.MyThread; +using GeekDesk; +using System.Collections; + +namespace ShowSeconds +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class SecondsWindow : Window + { + + private System.Drawing.Color beforeColor; + private System.Drawing.Color topBeforeColor; + + private bool expandClock = true; //是否展开时钟 + private System.Windows.Forms.Timer timer; + + private static double lProportion = 0.82; + private static double tProportion = 0.03; + private static int sleepTime = 1000; + public SecondsWindow() + { + SecondsDataContext dc = new SecondsDataContext + { + Seconds = (DateTime.Now.Hour).ToString() + ":" + + FormatMS(DateTime.Now.Minute) + ":" + + FormatMS(DateTime.Now.Second) + }; + InitializeComponent(); + SolidColorBrush scb = new SolidColorBrush(System.Windows.Media.Color.FromArgb(255, 47, 52, 44)) + { + Opacity = 0.8 + }; + + + try + { + + Hashtable settings = (Hashtable)ConfigurationManager.GetSection("ShowSecondsSettings"); + + lProportion = Convert.ToDouble(settings["LProportion"]); + tProportion = Convert.ToDouble(settings["TProportion"]); + sleepTime = Convert.ToInt32(settings["DelayTime"]); + } + catch (Exception ex) + { + lProportion = 0.82; + tProportion = 0.03; + sleepTime = 1000; + } + + BGBorder.Background = scb; + this.DataContext = dc; + this.Topmost = true; + BGBorder.Visibility = Visibility.Collapsed; + this.Show(); + } + + + private void Window_Loaded(object sender, RoutedEventArgs e) + { + timer = new System.Windows.Forms.Timer(); + timer.Interval = 1000; + timer.Tick += Timer_Tick; + + Dispatcher secondsDP = DispatcherBuild.Build(); + IKeyboardMouseEvents secondsHook = Hook.GlobalEvents(); + secondsDP.Invoke((Action)(() => + { + secondsHook.MouseDownExt += SecondsBakColorFun; + secondsHook.MouseUpExt += SecondsHookSetFuc; + })); + + HideWindowUtil.HideAltTab(this); + } + + private void Timer_Tick(object sender, EventArgs e) + { + string str = (DateTime.Now.Hour).ToString() + ":" + + FormatMS(DateTime.Now.Minute) + ":" + + FormatMS(DateTime.Now.Second); + SecondsDataContext dc = this.DataContext as SecondsDataContext; + dc.Seconds = str; + } + + + + private static string FormatMS(int ms) + { + if (ms < 10) + { + return "0" + ms; + } + else + { + return ms.ToString(); + } + } + + private void SecondsHookSetFuc(object sender, MouseEventExtArgs e) + { + if (e.Button == System.Windows.Forms.MouseButtons.Left) + { + if (ScreenUtil.IsPrimaryFullScreen()) return; + + App.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Render, new Action(() => + { + int x = e.X; + int y = e.Y; + double w = 1920; + double h = 1080; + double width = SystemParameters.PrimaryScreenWidth; + double height = SystemParameters.PrimaryScreenHeight; + if (x > 1843 / w * width + && x < 1907 / w * width + && y > 1037 / h * height + && y < 1074 / h * height) + { + + System.Drawing.Color c; + int count = sleepTime; + do + { + c = GetBottomBeforeColor(); + if (c.A != beforeColor.A + || c.R != beforeColor.R + || c.G != beforeColor.G + || c.B != beforeColor.B) + { + break; + } + Thread.Sleep(50); + count -= 50; + } while (count > 0); + + if (c.A != beforeColor.A + || c.R != beforeColor.R + || c.G != beforeColor.G + || c.B != beforeColor.B) + { + //判断是否展开时钟 + System.Drawing.Color ct = GetTopBeforeColor(); + if (ct.A != topBeforeColor.A + || ct.R != topBeforeColor.R + || ct.G != topBeforeColor.G + || ct.B != topBeforeColor.B) + { + expandClock = true; + } + else + { + expandClock = false; + } + + if (!BGBorder.IsVisible) + { + + System.Drawing.Color theamColor = GetColor(1919, 1079); + if (CalculateLight(theamColor) > 255 / 2) + { + //light + BGBorder.Background = new SolidColorBrush(System.Windows.Media.Color.FromArgb(theamColor.A, theamColor.R, theamColor.G, theamColor.B)); + SecondsText.Foreground = Constants.lightFont; + } + else + { + // dark + //BGBorder.Background = new SolidColorBrush(System.Windows.Media.Color.FromArgb(theamColor.A, theamColor.R, theamColor.G, theamColor.B)); + BGBorder.Background = Constants.darkBG; + SecondsText.Foreground = Constants.darkFont; + } + + SecondsDataContext dc = this.DataContext as SecondsDataContext; + dc.Seconds = (DateTime.Now.Hour).ToString() + ":" + + FormatMS(DateTime.Now.Minute) + ":" + + FormatMS(DateTime.Now.Second); + + int sx = (int)(SystemParameters.PrimaryScreenWidth * lProportion); + int sMarginBottom = (int)(SystemParameters.WorkArea.Height * tProportion); + Left = sx - Width; + Top = SystemParameters.WorkArea.Height - Height; + BGBorder.Visibility = Visibility.Visible; + timer.Start(); + } + else + { + BGBorder.Visibility= Visibility.Collapsed; + timer.Stop(); + } + } + } + else if (true) + { + if ((expandClock && (x < 1574 / w * width + || x > 1906 / w * width + || y < 598 / h * height + || y > 1020 / h * height) + ) + || !expandClock && (x < 1574 / w * width + || x > 1906 / w * width + || y < 950 / h * height + || y > 1020 / h * height) + ) + { + BGBorder.Visibility = Visibility.Collapsed; + timer.Stop(); + } + } + })); + } + } + + + private static System.Windows.Window window = null; + public static void ShowWindow() + { + try + { + if (window == null || !window.Activate()) + { + window = new SecondsWindow(); + } + } catch (Exception e) + { + LogUtil.WriteErrorLog(e, "打开显秒窗口异常!"); + } + + } + + public static void CloseWindow() + { + try + { + window.Close(); + } catch (Exception e) + { + LogUtil.WriteErrorLog(e, "关闭显秒窗口异常!"); + } + } + + private void SecondsBakColorFun(object sender, MouseEventExtArgs e) + { + if (e.Button == System.Windows.Forms.MouseButtons.Left) + { + beforeColor = GetBottomBeforeColor(); + topBeforeColor = GetTopBeforeColor(); + } + } + + private static System.Drawing.Color GetBottomBeforeColor() + { + return GetColor(1760, 985); + } + + private static System.Drawing.Color GetTopBeforeColor() + { + return GetColor(1751, 693); + } + + private static System.Drawing.Color GetColor(int w2, int h2) + { + double w = 1920; + double h = 1080; + double width = SystemParameters.PrimaryScreenWidth; + double height = SystemParameters.PrimaryScreenHeight; + System.Drawing.Point p = new System.Drawing.Point((int)(w2 / w * width), (int)(h2 / h * height)); + return ScreenUtil.GetColorAt(p); + } + + + private static int CalculateLight(System.Drawing.Color color) + { + int[] colorArr = new int[] { color.R, color.G, color.B }; + + int max = 0; + int min = 255; + foreach (int i in colorArr) + { + max = Math.Max(max, i); + min = Math.Min(min, i); + } + int avg = (max + min) / 2; + return avg; + } + + } +} diff --git a/Plugins/ShowSeconds/ViewModel/SecondsDataContext.cs b/Plugins/ShowSeconds/ViewModel/SecondsDataContext.cs new file mode 100644 index 0000000..c98362a --- /dev/null +++ b/Plugins/ShowSeconds/ViewModel/SecondsDataContext.cs @@ -0,0 +1,25 @@ +using System.ComponentModel; + + +namespace ShowSeconds.ViewModel +{ + public class SecondsDataContext : INotifyPropertyChanged + { + private string seconds; + public string Seconds + { + set + { + seconds = value; + OnPropertyChanged("Seconds"); + } + get { return seconds; } + } + + public event PropertyChangedEventHandler PropertyChanged; + private void OnPropertyChanged(string propertyName) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + } +} diff --git a/Update.json b/Update.json index 0630b4d..2815df7 100644 --- a/Update.json +++ b/Update.json @@ -1,9 +1,9 @@ { "title": "GeekDesk版本更新", - "subTitle": "V2.5.11", + "subTitle": "V2.5.13", "msgTitle": "本次更新内容如下", - "msg": "['依旧耗费了我大量精力开发,希望大家去给我点个免费的Star', '这个版本有一些优化点, 大家可以自行探索, 另外征集新Logo的设计, 要求美观并能体现\\'极客\\'风格','本次重新打包了程序文件(文件目录更清爽了,注意,这次不要使用覆盖升级(2.5.10可覆盖)), 可以将旧版本根目录下的Data文件复制到新版本根目录, 然后使用新版本启动','修复了2.5.10版本部分相对路径创建导致启动崩溃的bug','增加可拖动图标到其它菜单的功能,取消了拖动时的动画','增加了列表展开动画的开关','增加了数据备份功能','优化大部分动画','优化搜索功能(达到了可只用键盘或只用鼠标启动所需目标)','增加了相对路径(实验性,可能有bug)','增加列表加密功能(实验性,可能有bug)','其它已知问题修复']", + "msg": "['求Star,求Star', '集成Win11显秒插件', '崩溃问题修复', '现在在右侧栏(快捷图标区域)也可以鼠标滚轮切换菜单了', '缩放屏幕截图问题修复(感谢@1062406901提的PR)', '其它已知问题修复']", "githubUrl": "https://github.com/BookerLiu/GeekDesk/releases", "giteeUrl": "https://gitee.com/BookerLiu/GeekDesk/releases", - "version": "2.5.11" + "version": "2.5.13" } \ No newline at end of file diff --git a/app.manifest b/app.manifest new file mode 100644 index 0000000..18555fc --- /dev/null +++ b/app.manifest @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + true + + + + + + + +