diff --git a/STranslate/Helper/GetWordsHelper.cs b/STranslate/Helper/GetWordsHelper.cs index 4350a2a..692f726 100644 --- a/STranslate/Helper/GetWordsHelper.cs +++ b/STranslate/Helper/GetWordsHelper.cs @@ -9,6 +9,7 @@ namespace STranslate.Helper public static String Get() { SendCtrlC(); + System.Diagnostics.Debug.Print(STranslate.ViewModel.SettingsVM.Instance.WordPickupInterval.ToString()); Thread.Sleep((int)STranslate.ViewModel.SettingsVM.Instance.WordPickupInterval); return NativeMethodHelper.GetText(); } diff --git a/STranslate/Model/ConfigModel.cs b/STranslate/Model/ConfigModel.cs index 113701c..4e109e0 100644 --- a/STranslate/Model/ConfigModel.cs +++ b/STranslate/Model/ConfigModel.cs @@ -17,6 +17,7 @@ namespace STranslate.Model { return new ConfigModel { + WordPickupInterval = 200, IsBright = true, SourceLanguage = LanguageEnum.AUTO.GetDescription(), TargetLanguage = LanguageEnum.AUTO.GetDescription(), @@ -42,6 +43,11 @@ namespace STranslate.Model }; } + /// + /// 是否亮色模式 + /// + [JsonProperty("wordPickupInterval")] + public double WordPickupInterval { get; set; } /// /// 是否亮色模式 /// diff --git a/STranslate/STranslate.csproj b/STranslate/STranslate.csproj index 17714fe..8485ea9 100644 --- a/STranslate/STranslate.csproj +++ b/STranslate/STranslate.csproj @@ -104,7 +104,6 @@ Resources.resx - diff --git a/STranslate/View/MainWindow.xaml.cs b/STranslate/View/MainWindow.xaml.cs index d57886a..4c9a851 100644 --- a/STranslate/View/MainWindow.xaml.cs +++ b/STranslate/View/MainWindow.xaml.cs @@ -61,15 +61,13 @@ namespace STranslate.View private MainVM vm = MainVM.Instance; - - public readonly NotifyIcon NotifyIcon = new NotifyIcon(); #region Initial TrayIcon private void InitialTray() { var app = Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetEntryAssembly()?.Location); - NotifyIcon.Text = $@"{app} {vm.Version}"; + NotifyIcon.Text = $@"{app} {SettingsVM.Instance.Version}"; var stream = Application .GetResourceStream(new Uri("Images/translate.ico", UriKind.Relative))?.Stream; if (stream != null) @@ -93,17 +91,9 @@ namespace STranslate.View var openMainWinBtn = new MenuItem("显示主界面\tAlt+G"); openMainWinBtn.Click += OpenMainWin_Click; - var checkUpdateBtn = new MenuItem("检查更新"); - checkUpdateBtn.Click += CheckUpdateBTN_Click; - - var autoStartBtn = new MenuItem("开机自启"); - autoStartBtn.Click += AutoStart_Click; - var preferenceBtn = new MenuItem("首选项"); preferenceBtn.Click += Preference_Click; - autoStartBtn.Checked = StartupHelper.IsStartup(); - var exitBtn = new MenuItem("退出"); exitBtn.Click += Exit_Click; @@ -112,8 +102,6 @@ namespace STranslate.View screenshotTranslateMenuItemBtn, crossWordTranslateMenuItemBtn, openMainWinBtn, - checkUpdateBtn, - autoStartBtn, preferenceBtn, exitBtn, }; @@ -127,51 +115,22 @@ namespace STranslate.View /// private void Preference_Click(object sender, EventArgs e) { - var setting = new SettingsWindow(); - setting.Show(); - setting.Activate(); - } - - - /// - /// 检查更新 by https://github.com/Planshit/Tai - /// - /// - /// - private void CheckUpdateBTN_Click(object sender, EventArgs e) - { - try + SettingsWindow window = null; + foreach (Window item in Application.Current.Windows) { - var updaterExePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, - "Updater.exe"); - var updaterCacheExePath = Path.Combine( - AppDomain.CurrentDomain.BaseDirectory, - "Updater", - "Updater.exe"); - var updateDirPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Updater"); - if (!Directory.Exists(updateDirPath)) - { - Directory.CreateDirectory(updateDirPath); - } - - if (!File.Exists(updaterExePath)) + if (item is SettingsWindow) { - MessageBox.Show("升级程序似乎已被删除,请手动前往发布页查看新版本"); - return; + window = (SettingsWindow)item; + window.WindowState = WindowState.Normal; + window.Activate(); + break; } - File.Copy(updaterExePath, updaterCacheExePath, true); - - File.Copy(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Newtonsoft.Json.dll"), Path.Combine( - AppDomain.CurrentDomain.BaseDirectory, - "Updater", - "Newtonsoft.Json.dll"), true); - - ProcessHelper.Run(updaterCacheExePath, new string[] { vm.Version }); } - catch (Exception ex) + if (window == null) { - - MessageBox.Show($"无法正确启动检查更新程序\n{ex.Message}"); + window = new SettingsWindow(); + window.Show(); + window.Activate(); } } @@ -185,13 +144,6 @@ namespace STranslate.View vm.OpenMainWin(); } - private void AutoStart_Click(object sender, EventArgs e) - { - if (StartupHelper.IsStartup()) StartupHelper.UnSetStartup(); - else StartupHelper.SetStartup(); - ((MenuItem)sender).Checked = StartupHelper.IsStartup(); - } - private void Exit_Click(object sender, EventArgs e) { vm.ExitApp(0); diff --git a/STranslate/View/SettingsWindow.xaml b/STranslate/View/SettingsWindow.xaml index dbdbf10..64161d8 100644 --- a/STranslate/View/SettingsWindow.xaml +++ b/STranslate/View/SettingsWindow.xaml @@ -6,7 +6,6 @@ xmlns:i="http://schemas.microsoft.com/xaml/behaviors" xmlns:local="clr-namespace:STranslate.View" mc:Ignorable="d" - Topmost="True" SizeToContent="Height" WindowStartupLocation="CenterScreen" Icon="/Images/translate.ico" @@ -33,7 +32,12 @@ - + + + + @@ -51,24 +55,29 @@ + IsChecked="{Binding IsStartup}" + FontWeight="Bold"> + + + + + + + + + - - - - - - @@ -77,6 +86,7 @@ + @@ -216,7 +226,7 @@ FontSize="18" Margin="5,0"> + FontWeight="Bold"/>