diff --git a/STranslate.Model/ConfigModel.cs b/STranslate.Model/ConfigModel.cs index a0042494..7faa7b5b 100644 --- a/STranslate.Model/ConfigModel.cs +++ b/STranslate.Model/ConfigModel.cs @@ -132,6 +132,15 @@ public partial class ConfigModel : ObservableObject /// public bool IsShowQRCode { get; set; } = false; + /// + /// 取词间隔 + /// + /// + /// 默认200,体验区别不大,主要是避免了福昕阅读器,复制时弹窗导致取词时间变长最终无法取词成功 + /// https://github.com/zggsong/stranslate/issues/13 + /// + public int WordPickingInterval { get; set; } = 200; + /// /// 服务 /// diff --git a/STranslate.Util/GetWordsUtil.cs b/STranslate.Util/GetWordsUtil.cs index 8ad7615e..29dd6753 100644 --- a/STranslate.Util/GetWordsUtil.cs +++ b/STranslate.Util/GetWordsUtil.cs @@ -6,19 +6,19 @@ namespace STranslate.Util { public class GetWordsUtil { - public static string Get() + public static string Get(int interval = 100) { SendCtrlC(); - System.Threading.Thread.Sleep(100); + System.Threading.Thread.Sleep(interval); return GetText(); } - public static string MouseSlidGet() + public static string MouseSlidGet(int interval = 100) { var oldTxt = GetText(); SendCtrlC(); - System.Threading.Thread.Sleep(100); + System.Threading.Thread.Sleep(interval); //为了鼠标划词做对比 var newTxt = GetText(); diff --git a/STranslate/Helper/ConfigHelper.cs b/STranslate/Helper/ConfigHelper.cs index 90b8b96e..9f172185 100644 --- a/STranslate/Helper/ConfigHelper.cs +++ b/STranslate/Helper/ConfigHelper.cs @@ -172,6 +172,7 @@ public bool WriteConfig(CommonViewModel model) CurrentConfig.IsShowOCR = model.IsShowOCR; CurrentConfig.IsShowSilentOCR = model.IsShowSilentOCR; CurrentConfig.IsShowQRCode = model.IsShowQRCode; + CurrentConfig.WordPickingInterval = model.WordPickingInterval; Singleton.Instance.UpdateMainViewIcons(); WriteConfig(CurrentConfig); isSuccess = true; @@ -278,6 +279,7 @@ private ConfigModel InitialConfig() IsShowOCR = false, IsShowSilentOCR = false, IsShowQRCode = false, + WordPickingInterval = 100, SourceLanguage = LanguageEnum.AUTO.GetDescription(), TargetLanguage = LanguageEnum.AUTO.GetDescription(), Services = diff --git a/STranslate/Helper/MouseHookHelper.cs b/STranslate/Helper/MouseHookHelper.cs index fc93a69c..bb583170 100644 --- a/STranslate/Helper/MouseHookHelper.cs +++ b/STranslate/Helper/MouseHookHelper.cs @@ -63,7 +63,7 @@ private void mouseHook_MouseUp(object? sender, MouseEventArgs e) } if (isDown && isMove) { - var content = GetWordsUtil.MouseSlidGet(); + var content = GetWordsUtil.MouseSlidGet(Singleton.Instance.CurrentConfig?.WordPickingInterval ?? 100); OnGetwordsHandler?.Invoke(content); } isDown = false; diff --git a/STranslate/ViewModels/NotifyIconViewModel.cs b/STranslate/ViewModels/NotifyIconViewModel.cs index 189844cc..0b2e6249 100644 --- a/STranslate/ViewModels/NotifyIconViewModel.cs +++ b/STranslate/ViewModels/NotifyIconViewModel.cs @@ -94,9 +94,12 @@ private void InputTranslate(Window view) [RelayCommand] private void CrossWordTranslate(Window view) { - var content = GetWordsUtil.Get(); + var content = GetWordsUtil.Get(Singleton.Instance.CurrentConfig?.WordPickingInterval ?? 100); if (string.IsNullOrWhiteSpace(content)) + { + LogService.Logger.Warn($"取词失败,取词内容为空,请尝试延长取词间隔..."); return; + } //取词前移除换行 if (Singleton.Instance.CurrentConfig?.IsRemoveLineBreakGettingWords ?? false) diff --git a/STranslate/ViewModels/Preference/CommonViewModel.cs b/STranslate/ViewModels/Preference/CommonViewModel.cs index dec98ddd..6c8c94fc 100644 --- a/STranslate/ViewModels/Preference/CommonViewModel.cs +++ b/STranslate/ViewModels/Preference/CommonViewModel.cs @@ -63,6 +63,7 @@ private void Reset() IsShowOCR = Singleton.Instance.CurrentConfig?.IsShowOCR ?? false; IsShowSilentOCR = Singleton.Instance.CurrentConfig?.IsShowSilentOCR ?? false; IsShowQRCode = Singleton.Instance.CurrentConfig?.IsShowQRCode ?? false; + WordPickingInterval = Singleton.Instance.CurrentConfig?.WordPickingInterval ?? 100; ToastHelper.Show("重置配置", WindowType.Preference); if (IsStartup) { @@ -266,5 +267,11 @@ public string CustomFont /// [ObservableProperty] private bool isShowQRCode = Singleton.Instance.CurrentConfig?.IsShowQRCode ?? false; + + /// + /// 取词时间间隔 + /// + [ObservableProperty] + private int wordPickingInterval = Singleton.Instance.CurrentConfig?.WordPickingInterval ?? 100; } } diff --git a/STranslate/Views/Preference/CommonPage.xaml b/STranslate/Views/Preference/CommonPage.xaml index e7b9ae7f..827f4f97 100644 --- a/STranslate/Views/Preference/CommonPage.xaml +++ b/STranslate/Views/Preference/CommonPage.xaml @@ -67,6 +67,22 @@ + + + + + + + + +