Skip to content

Commit

Permalink
fix: Foxit Reader failed to pick up words #13
Browse files Browse the repository at this point in the history
  • Loading branch information
ZGGSONG committed Jan 22, 2024
1 parent 5c37003 commit 738063d
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 6 deletions.
9 changes: 9 additions & 0 deletions STranslate.Model/ConfigModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,15 @@ public partial class ConfigModel : ObservableObject
/// </summary>
public bool IsShowQRCode { get; set; } = false;

/// <summary>
/// 取词间隔
/// </summary>
/// <remarks>
/// 默认200,体验区别不大,主要是避免了福昕阅读器,复制时弹窗导致取词时间变长最终无法取词成功
/// https://github.com/zggsong/stranslate/issues/13
/// </remarks>
public int WordPickingInterval { get; set; } = 200;

/// <summary>
/// 服务
/// </summary>
Expand Down
8 changes: 4 additions & 4 deletions STranslate.Util/GetWordsUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions STranslate/Helper/ConfigHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<MainViewModel>.Instance.UpdateMainViewIcons();
WriteConfig(CurrentConfig);
isSuccess = true;
Expand Down Expand Up @@ -278,6 +279,7 @@ private ConfigModel InitialConfig()
IsShowOCR = false,
IsShowSilentOCR = false,
IsShowQRCode = false,
WordPickingInterval = 100,
SourceLanguage = LanguageEnum.AUTO.GetDescription(),
TargetLanguage = LanguageEnum.AUTO.GetDescription(),
Services =
Expand Down
2 changes: 1 addition & 1 deletion STranslate/Helper/MouseHookHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private void mouseHook_MouseUp(object? sender, MouseEventArgs e)
}
if (isDown && isMove)
{
var content = GetWordsUtil.MouseSlidGet();
var content = GetWordsUtil.MouseSlidGet(Singleton<ConfigHelper>.Instance.CurrentConfig?.WordPickingInterval ?? 100);
OnGetwordsHandler?.Invoke(content);
}
isDown = false;
Expand Down
5 changes: 4 additions & 1 deletion STranslate/ViewModels/NotifyIconViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,12 @@ private void InputTranslate(Window view)
[RelayCommand]
private void CrossWordTranslate(Window view)
{
var content = GetWordsUtil.Get();
var content = GetWordsUtil.Get(Singleton<ConfigHelper>.Instance.CurrentConfig?.WordPickingInterval ?? 100);
if (string.IsNullOrWhiteSpace(content))
{
LogService.Logger.Warn($"取词失败,取词内容为空,请尝试延长取词间隔...");
return;
}

//取词前移除换行
if (Singleton<ConfigHelper>.Instance.CurrentConfig?.IsRemoveLineBreakGettingWords ?? false)
Expand Down
7 changes: 7 additions & 0 deletions STranslate/ViewModels/Preference/CommonViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ private void Reset()
IsShowOCR = Singleton<ConfigHelper>.Instance.CurrentConfig?.IsShowOCR ?? false;
IsShowSilentOCR = Singleton<ConfigHelper>.Instance.CurrentConfig?.IsShowSilentOCR ?? false;
IsShowQRCode = Singleton<ConfigHelper>.Instance.CurrentConfig?.IsShowQRCode ?? false;
WordPickingInterval = Singleton<ConfigHelper>.Instance.CurrentConfig?.WordPickingInterval ?? 100;
ToastHelper.Show("重置配置", WindowType.Preference);
if (IsStartup)
{
Expand Down Expand Up @@ -266,5 +267,11 @@ public string CustomFont
/// </summary>
[ObservableProperty]
private bool isShowQRCode = Singleton<ConfigHelper>.Instance.CurrentConfig?.IsShowQRCode ?? false;

/// <summary>
/// 取词时间间隔
/// </summary>
[ObservableProperty]
private int wordPickingInterval = Singleton<ConfigHelper>.Instance.CurrentConfig?.WordPickingInterval ?? 100;
}
}
16 changes: 16 additions & 0 deletions STranslate/Views/Preference/CommonPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,22 @@
</StackPanel>
</DockPanel>

<DockPanel Margin="20,10">
<TextBlock Text="取词时间间隔" />
<TextBlock Style="{DynamicResource InfoTextBlock}" ToolTip="针对部分软件取词失败的情况,延长取词时间间隔" />
<StackPanel HorizontalAlignment="Right" DockPanel.Dock="Right" Orientation="Horizontal">
<Slider MinWidth="160"
Margin="0,0,30,0"
IsSnapToTickEnabled="True"
Maximum="2000"
Minimum="50"
TickFrequency="50"
TickPlacement="None"
Value="{Binding WordPickingInterval}" />
<TextBlock Margin="0,0,10,0" Text="{Binding WordPickingInterval}" />
</StackPanel>
</DockPanel>

<DockPanel Margin="20,10">
<TextBlock Text="双击托盘功能" />
<TextBlock Style="{DynamicResource InfoTextBlock}" ToolTip="鼠标左键双击头盘程序功能选择" />
Expand Down

0 comments on commit 738063d

Please sign in to comment.