diff --git a/STranslate.Model/ConfigModel.cs b/STranslate.Model/ConfigModel.cs index 8886b2c9..a0042494 100644 --- a/STranslate.Model/ConfigModel.cs +++ b/STranslate.Model/ConfigModel.cs @@ -97,6 +97,41 @@ public partial class ConfigModel : ObservableObject /// public bool IsKeepTopmostAfterMousehook { get; set; } = false; + /// + /// 是否显示设置图标 + /// + public bool IsShowPreference { get; set; } = true; + + /// + /// 是否显示切换主题图标 + /// + public bool IsShowSwitchTheme { get; set; } = true; + + /// + /// 是否显示打开鼠标划词图标 + /// + public bool IsShowMousehook { get; set; } = false; + + /// + /// 是否显示截图翻译图标 + /// + public bool IsShowScreenshot { get; set; } = false; + + /// + /// 是否显示OCR图标 + /// + public bool IsShowOCR { get; set; } = false; + + /// + /// 是否显示静默OCR图标 + /// + public bool IsShowSilentOCR { get; set; } = false; + + /// + /// 是否显示识别二维码图标 + /// + public bool IsShowQRCode { get; set; } = false; + /// /// 服务 /// diff --git a/STranslate/Helper/ConfigHelper.cs b/STranslate/Helper/ConfigHelper.cs index fdad4507..90b8b96e 100644 --- a/STranslate/Helper/ConfigHelper.cs +++ b/STranslate/Helper/ConfigHelper.cs @@ -4,6 +4,7 @@ using STranslate.Log; using STranslate.Model; using STranslate.Util; +using STranslate.ViewModels; using STranslate.ViewModels.Preference; using STranslate.ViewModels.Preference.Services; using System; @@ -62,6 +63,9 @@ public void InitialOperate() //初始化代理设置 ProxyUtil.UpdateDynamicProxy(CurrentConfig?.IsDisableSystemProxy ?? false); + + //初始化首页图标 + Singleton.Instance.UpdateMainViewIcons(); } /// @@ -161,6 +165,14 @@ public bool WriteConfig(CommonViewModel model) CurrentConfig.DoubleTapTrayFunc = model.DoubleTapTrayFunc; CurrentConfig.CustomFont = model.CustomFont; CurrentConfig.IsKeepTopmostAfterMousehook = model.IsKeepTopmostAfterMousehook; + CurrentConfig.IsShowPreference = model.IsShowPreference; + CurrentConfig.IsShowSwitchTheme = model.IsShowSwitchTheme; + CurrentConfig.IsShowMousehook = model.IsShowMousehook; + CurrentConfig.IsShowScreenshot = model.IsShowScreenshot; + CurrentConfig.IsShowOCR = model.IsShowOCR; + CurrentConfig.IsShowSilentOCR = model.IsShowSilentOCR; + CurrentConfig.IsShowQRCode = model.IsShowQRCode; + Singleton.Instance.UpdateMainViewIcons(); WriteConfig(CurrentConfig); isSuccess = true; } @@ -259,6 +271,13 @@ private ConfigModel InitialConfig() DoubleTapTrayFunc = DoubleTapFuncEnum.InputFunc, CustomFont = ConstStr.DEFAULTFONTNAME, IsKeepTopmostAfterMousehook = false, + IsShowPreference = false, + IsShowSwitchTheme = false, + IsShowMousehook = false, + IsShowScreenshot = false, + IsShowOCR = false, + IsShowSilentOCR = false, + IsShowQRCode = false, SourceLanguage = LanguageEnum.AUTO.GetDescription(), TargetLanguage = LanguageEnum.AUTO.GetDescription(), Services = diff --git a/STranslate/ViewModels/MainViewModel.cs b/STranslate/ViewModels/MainViewModel.cs index ac53ddaa..97c68b36 100644 --- a/STranslate/ViewModels/MainViewModel.cs +++ b/STranslate/ViewModels/MainViewModel.cs @@ -289,5 +289,42 @@ private void SwitchTheme() { Singleton.Instance.IsBright = !Singleton.Instance.IsBright; } + + /// + /// 更新主界面图标显示 + /// + internal void UpdateMainViewIcons() + { + IsShowPreference = Singleton.Instance.CurrentConfig?.IsShowPreference ?? false; + IsShowSwitchTheme = Singleton.Instance.CurrentConfig?.IsShowSwitchTheme ?? false; + IsShowMousehook = Singleton.Instance.CurrentConfig?.IsShowMousehook ?? false; + IsShowScreenshot = Singleton.Instance.CurrentConfig?.IsShowScreenshot ?? false; + IsShowOCR = Singleton.Instance.CurrentConfig?.IsShowOCR ?? false; + IsShowSilentOCR = Singleton.Instance.CurrentConfig?.IsShowSilentOCR ?? false; + IsShowQRCode = Singleton.Instance.CurrentConfig?.IsShowQRCode ?? false; + } + + #region 显示图标 + [ObservableProperty] + private bool isShowPreference; + + [ObservableProperty] + private bool isShowSwitchTheme; + + [ObservableProperty] + private bool isShowMousehook; + + [ObservableProperty] + private bool isShowScreenshot; + + [ObservableProperty] + private bool isShowOCR; + + [ObservableProperty] + private bool isShowSilentOCR; + + [ObservableProperty] + private bool isShowQRCode; + #endregion 显示图标 } } \ No newline at end of file diff --git a/STranslate/ViewModels/NotifyIconViewModel.cs b/STranslate/ViewModels/NotifyIconViewModel.cs index 86a588c4..189844cc 100644 --- a/STranslate/ViewModels/NotifyIconViewModel.cs +++ b/STranslate/ViewModels/NotifyIconViewModel.cs @@ -220,21 +220,28 @@ internal void SilentOCRHandler() view.BitmapCallback += ( bitmap => { - var bytes = BitmapUtil.ConvertBitmap2Bytes(bitmap); - - var getText = Singleton.Instance.Execute(bytes).Trim(); - - //取词前移除换行 - getText = - Singleton.Instance.CurrentConfig?.IsRemoveLineBreakGettingWords ?? false && !string.IsNullOrEmpty(getText) - ? StringUtil.RemoveLineBreaks(getText) - : getText; - - //写入剪贴板 - Clipboard.SetDataObject(getText, true); - - var tmp = getText.Length >= 9 ? getText[..9] + "..." : getText; - OnShowBalloonTip?.Invoke($"OCR识别成功: {tmp}"); + try + { + var bytes = BitmapUtil.ConvertBitmap2Bytes(bitmap); + var getText = Singleton.Instance.Execute(bytes).Trim(); + + //取词前移除换行 + getText = + Singleton.Instance.CurrentConfig?.IsRemoveLineBreakGettingWords ?? false && !string.IsNullOrEmpty(getText) + ? StringUtil.RemoveLineBreaks(getText) + : getText; + + //写入剪贴板 + Clipboard.SetDataObject(getText, true); + + var tmp = getText.Length >= 9 ? getText[..9] + "..." : getText; + OnShowBalloonTip?.Invoke($"OCR识别成功: {tmp}"); + } + catch (Exception ex) + { + OnShowBalloonTip?.Invoke($"OCR识别失败: {ex.Message}"); + LogService.Logger.Error("静默OCR失败", ex); + } } ); } diff --git a/STranslate/ViewModels/Preference/CommonViewModel.cs b/STranslate/ViewModels/Preference/CommonViewModel.cs index b87daa17..dec98ddd 100644 --- a/STranslate/ViewModels/Preference/CommonViewModel.cs +++ b/STranslate/ViewModels/Preference/CommonViewModel.cs @@ -56,7 +56,13 @@ private void Reset() DoubleTapTrayFunc = Singleton.Instance.CurrentConfig?.DoubleTapTrayFunc ?? DoubleTapFuncEnum.InputFunc; CustomFont = Singleton.Instance.CurrentConfig?.CustomFont ?? ConstStr.DEFAULTFONTNAME; IsKeepTopmostAfterMousehook = Singleton.Instance.CurrentConfig?.IsKeepTopmostAfterMousehook ?? false; - + IsShowPreference = Singleton.Instance.CurrentConfig?.IsShowPreference ?? false; + IsShowSwitchTheme = Singleton.Instance.CurrentConfig?.IsShowSwitchTheme ?? false; + IsShowMousehook = Singleton.Instance.CurrentConfig?.IsShowMousehook ?? false; + IsShowScreenshot = Singleton.Instance.CurrentConfig?.IsShowScreenshot ?? false; + IsShowOCR = Singleton.Instance.CurrentConfig?.IsShowOCR ?? false; + IsShowSilentOCR = Singleton.Instance.CurrentConfig?.IsShowSilentOCR ?? false; + IsShowQRCode = Singleton.Instance.CurrentConfig?.IsShowQRCode ?? false; ToastHelper.Show("重置配置", WindowType.Preference); if (IsStartup) { @@ -217,5 +223,48 @@ public string CustomFont [ObservableProperty] private bool isKeepTopmostAfterMousehook = Singleton.Instance.CurrentConfig?.IsKeepTopmostAfterMousehook ?? false; + + + /// + /// 是否显示设置图标 + /// + [ObservableProperty] + private bool isShowPreference = Singleton.Instance.CurrentConfig?.IsShowPreference ?? false; + + /// + /// 是否显示切换主题图标 + /// + [ObservableProperty] + private bool isShowSwitchTheme = Singleton.Instance.CurrentConfig?.IsShowSwitchTheme ?? false; + + /// + /// 是否显示打开鼠标划词图标 + /// + [ObservableProperty] + private bool isShowMousehook = Singleton.Instance.CurrentConfig?.IsShowMousehook ?? false; + + /// + /// 是否显示截图翻译图标 + /// + [ObservableProperty] + private bool isShowScreenshot = Singleton.Instance.CurrentConfig?.IsShowScreenshot ?? false; + + /// + /// 是否显示OCR图标 + /// + [ObservableProperty] + private bool isShowOCR = Singleton.Instance.CurrentConfig?.IsShowOCR ?? false; + + /// + /// 是否显示静默OCR图标 + /// + [ObservableProperty] + private bool isShowSilentOCR = Singleton.Instance.CurrentConfig?.IsShowSilentOCR ?? false; + + /// + /// 是否显示识别二维码图标 + /// + [ObservableProperty] + private bool isShowQRCode = Singleton.Instance.CurrentConfig?.IsShowQRCode ?? false; } } diff --git a/STranslate/Views/HeaderView.xaml b/STranslate/Views/HeaderView.xaml index 37fe6e10..4229a642 100644 --- a/STranslate/Views/HeaderView.xaml +++ b/STranslate/Views/HeaderView.xaml @@ -12,32 +12,60 @@