dev_settings^2
DESKTOP-3BO4HSG\ksat 2 years ago
parent 999ed5c459
commit 655335d49f

@ -9,7 +9,7 @@ namespace STranslate.Helper
public static String Get()
{
SendCtrlC();
Thread.Sleep(200);
Thread.Sleep((int)STranslate.ViewModel.SettingsVM.Instance.WordPickupInterval);
return NativeMethodHelper.GetText();
}

@ -104,6 +104,7 @@
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Util\Util.cs" />
<Compile Include="ViewModel\BaseMainVM.cs" />
<Compile Include="ViewModel\MainVM.cs" />
<Compile Include="ViewModel\ScreenShotVM.cs" />
<Compile Include="ViewModel\SettingsVM.cs" />

@ -61,7 +61,6 @@ namespace STranslate.View
private MainVM vm = MainVM.Instance;
private string _version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
public readonly NotifyIcon NotifyIcon = new NotifyIcon();
@ -69,9 +68,8 @@ namespace STranslate.View
#region Initial TrayIcon
private void InitialTray()
{
_version = HandleVersion(_version);
var app = Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetEntryAssembly()?.Location);
NotifyIcon.Text = $@"{app} {_version}";
NotifyIcon.Text = $@"{app} {vm.Version}";
var stream = Application
.GetResourceStream(new Uri("Images/translate.ico", UriKind.Relative))?.Stream;
if (stream != null)
@ -134,19 +132,6 @@ namespace STranslate.View
setting.Activate();
}
/// <summary>
/// 同步Github版本命名
/// </summary>
/// <param name="version"></param>
/// <returns></returns>
private static string HandleVersion(string version)
{
var ret = string.Empty;
ret = version.Substring(0, version.Length - 2);
var location = ret.LastIndexOf('.');
ret = ret.Remove(location, 1);
return ret;
}
/// <summary>
/// 检查更新 by https://github.com/Planshit/Tai
@ -181,7 +166,7 @@ namespace STranslate.View
"Updater",
"Newtonsoft.Json.dll"), true);
ProcessHelper.Run(updaterCacheExePath, new string[] { _version });
ProcessHelper.Run(updaterCacheExePath, new string[] { vm.Version });
}
catch (Exception ex)
{

@ -1,18 +1,39 @@
<Window x:Class="STranslate.View.SettingsWindow"
<Window x:Name="window" x:Class="STranslate.View.SettingsWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:vm="clr-namespace:STranslate.ViewModel"
xmlns:local="clr-namespace:STranslate.View"
mc:Ignorable="d"
Topmost="True"
SizeToContent="Height"
WindowStartupLocation="CenterScreen"
Icon="/Images/translate.ico"
Title="设置" Height="450" Width="400">
<Window.DataContext>
<vm:SettingsVM/>
</Window.DataContext>
Title="STranslate 首选项" Height="450" Width="450">
<Window.Resources>
<ControlTemplate x:Key="buttonstyle"
TargetType="Button">
<Border x:Name="border"
CornerRadius="5"
Padding="4"
Background="#dedfde"
MaxHeight="25">
<TextBlock VerticalAlignment="Center"
HorizontalAlignment="Center"
Text="检查更新"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="border" Property="Background" Value="#c6e6fc"></Setter>
</Trigger>
<Trigger Property="IsPressed" Value="true">
<Setter TargetName="border" Property="Background" Value="#cce6f6"></Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Window.Resources>
<i:Interaction.Triggers>
<i:EventTrigger EventName="Loaded">
<i:InvokeCommandAction Command="{Binding}"/>
@ -21,9 +42,238 @@
<i:InvokeCommandAction Command="{Binding}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<Grid>
<Grid Margin="20">
<TabControl>
<TabItem Header="常规"
Padding="10,2">
<StackPanel Margin="20">
<GroupBox Header="开机启动">
<WrapPanel Margin="0,5,0,5">
<CheckBox Content="开机启动"
FontWeight="Bold"/>
</WrapPanel>
</GroupBox>
<GroupBox Header="取词间隔"
ToolTip="划词翻译实现原理是用户用鼠标划词后模拟Ctrl+C间隔一定时间后程序再从剪切板取词如果电脑反应慢可能会出现取不到词的问题将间隔调大可以适配一些老旧的机器">
<WrapPanel Margin="0,5,0,5">
<Slider Value="{Binding WordPickupInterval}"
Minimum="100"
Maximum="1000"
MinWidth="200"
TickFrequency="100"
TickPlacement="None"
IsSnapToTickEnabled="True">
<i:Interaction.Triggers>
<i:EventTrigger EventName="ValueChanged">
<i:InvokeCommandAction Command="{Binding ResetWordPickupIntervalCmd}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Slider>
<TextBlock Text="{Binding WordPickupInterval, StringFormat={}{0}ms}" Margin="10,0,0,0" />
</WrapPanel>
</GroupBox>
</StackPanel>
</TabItem>
<TabItem Header="控制"
Padding="10,2">
<StackPanel Margin="20">
<GroupBox Header="快捷键">
<Grid Margin="20,10,20,10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="100*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Label Content="划词翻译"
VerticalAlignment="Center"
Grid.Row="1"
Grid.Column="0"
Margin="0,5,0,0" />
<TextBox Cursor="Arrow"
Width="200"
Grid.Row="1"
Grid.Column="1"
Margin="0,5,0,0"
CaretBrush="Transparent"
VerticalContentAlignment="Center"
InputMethod.IsInputMethodEnabled="False">
<i:Interaction.Triggers>
<i:EventTrigger EventName="">
<i:InvokeCommandAction Command="{Binding }"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBox>
<Label Grid.Row="1"
Grid.Column="2"
Margin="0,5,0,0"
Content="热键冲突"
VerticalAlignment="Center"
Visibility="Hidden"
Foreground="Red" />
<Label Content="截图翻译"
VerticalAlignment="Center"
Grid.Row="2"
Grid.Column="0"
Margin="0,5,0,0" />
<TextBox Cursor="Arrow"
Width="200"
Grid.Row="2"
Grid.Column="1"
Margin="0,5,0,0"
CaretBrush="Transparent"
VerticalContentAlignment="Center"
InputMethod.IsInputMethodEnabled="False"/>
<Label Grid.Row="2"
Grid.Column="2"
Margin="0,5,0,0"
Content="热键冲突"
VerticalAlignment="Center"
Visibility="Hidden"
Foreground="Red" />
<Label Content="输入翻译"
VerticalAlignment="Center"
Grid.Row="3"
Grid.Column="0"
Margin="0,5,0,0" />
<TextBox Cursor="Arrow"
Width="200"
Grid.Row="3"
Grid.Column="1"
Margin="0,5,0,0"
CaretBrush="Transparent"
VerticalContentAlignment="Center"
InputMethod.IsInputMethodEnabled="False"/>
<Label Grid.Row="3"
Grid.Column="2"
Margin="0,5,0,0"
Content="热键冲突"
VerticalAlignment="Center"
Visibility="Hidden"
Foreground="Red" />
<Label Content="显示界面"
VerticalAlignment="Center"
Grid.Row="4"
Grid.Column="0"
Margin="0,5,0,0" />
<TextBox Cursor="Arrow"
Width="200"
Grid.Row="4"
Grid.Column="1"
Margin="0,5,0,0"
CaretBrush="Transparent"
VerticalContentAlignment="Center"
InputMethod.IsInputMethodEnabled="False"/>
<Label Grid.Row="4"
Grid.Column="2"
Margin="0,5,0,0"
Content="热键冲突"
VerticalAlignment="Center"
Visibility="Hidden"
Foreground="Red" />
<Button Content="恢复默认"
Template="{StaticResource buttonstyle}"
Width="80"
Grid.Row="5"
Margin="5"
Grid.Column="1"
Command="{Binding ResetHotKeysCmd}"/>
</Grid>
</GroupBox>
</StackPanel>
</TabItem>
<TabItem Header="关于"
IsSelected="True"
Padding="10,2">
<ScrollViewer VerticalScrollBarVisibility="Auto">
<StackPanel Margin="20">
<WrapPanel Orientation="Horizontal">
<Image Source="/Images/translate.ico" Width="30"/>
<TextBlock VerticalAlignment="Bottom"
FontSize="18"
Margin="5,0">
<Run Text="STranslate"
FontWeight="Black"/>
</TextBlock>
<!--<Border BorderBrush="Transparent"
Background="Black"
Margin="20,0,0,0"
Height="20"
CornerRadius="4">
<TextBlock VerticalAlignment="Center"
HorizontalAlignment="Right"
Foreground="WhiteSmoke"
Padding="5,0"
Text="Built with WPF"/>
</Border>-->
</WrapPanel>
<WrapPanel Margin="0,10,0,0">
<Label Content="版本"/>
<Label DataContext="https://github.com/zggsong/stranslate/releases"
Cursor="Hand"
Content="{Binding DataContext.Version, ElementName=window}"/>
<Button Content="检查更新"
Margin="40,0"
Template="{StaticResource buttonstyle}"
Command="{Binding UpdateCmd}">
</Button>
</WrapPanel>
<WrapPanel>
<Label Content="开源"/>
<Label Content="MIT License"
DataContext="https://en.wikipedia.org/wiki/MIT_License"
Cursor="Hand"/>
</WrapPanel>
<WrapPanel>
<Label Content="版权"/>
<Label Content="@2022 ZGGSONG"
DataContext="https://github.com/ZGGSONG"
Cursor="Hand"/>
</WrapPanel>
<WrapPanel>
<Label Content="联系"/>
<Label Content="zggsong@foxmail.com"
DataContext="zggsong@foxmail.com"
Cursor="Hand"/>
</WrapPanel>
<WrapPanel>
<Label Content="源码"/>
<Label Content="https://github.com/zggsong/stranslate"
DataContext="https://github.com/ZGGSONG/STranslate"
Cursor="Hand"/>
</WrapPanel>
<WrapPanel>
<Label Content="反馈"/>
<Label Content="https://github.com/zggsong/stranslate/issues"
DataContext="https://github.com/ZGGSONG/STranslate/issues"
Cursor="Hand"/>
</WrapPanel>
</StackPanel>
</ScrollViewer>
</TabItem>
</TabControl>
</Grid>
</Window>

@ -22,6 +22,8 @@ namespace STranslate.View
public SettingsWindow()
{
InitializeComponent();
DataContext = ViewModel.SettingsVM.Instance;
}
}
}

@ -0,0 +1,36 @@
using STranslate.Helper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace STranslate.ViewModel
{
public class BaseMainVM : BaseVM
{
public BaseMainVM()
{
Version = HandleVersion(System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString() ?? "1.0.0.0");
}
/// <summary>
/// 同步Github版本命名
/// </summary>
/// <param name="version"></param>
/// <returns></returns>
private static string HandleVersion(string version)
{
var ret = string.Empty;
ret = version.Substring(0, version.Length - 2);
var location = ret.LastIndexOf('.');
ret = ret.Remove(location, 1);
return ret;
}
private string _version;
public string Version { get => _version; set => UpdateProperty(ref _version, value); }
}
}

@ -13,7 +13,7 @@ using System.Windows.Controls;
namespace STranslate.ViewModel
{
public class MainVM : BaseVM
public class MainVM : BaseMainVM
{
public MainVM()
{

@ -1,14 +1,16 @@
using STranslate.Helper;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
namespace STranslate.ViewModel
{
public class SettingsVM : BaseVM
public class SettingsVM : BaseMainVM
{
public SettingsVM()
{
@ -16,12 +18,73 @@ namespace STranslate.ViewModel
{
Console.WriteLine("123");
});
ClosedCmd = new RelayCommand((_) => true, (_) =>
{
Console.WriteLine("123");
});
//重置快捷键
ResetHotKeysCmd = new RelayCommand((_) => true, (_) =>
{
Console.WriteLine("123");
});
//重置取词间隔
ResetWordPickupIntervalCmd = new RelayCommand((_) => true, (_) =>
{
System.Diagnostics.Debug.Print(WordPickupInterval.ToString());
});
//更新
UpdateCmd = new RelayCommand((_) => true, (_) =>
{
try
{
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))
{
MessageBox.Show("升级程序似乎已被删除,请手动前往发布页查看新版本");
return;
}
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[] { Version });
}
catch (Exception ex)
{
MessageBox.Show($"无法正确启动检查更新程序\n{ex.Message}");
}
});
}
public ICommand LoadedCmd { get; private set; }
public ICommand ClosedCmd { get; private set; }
public ICommand UpdateCmd { get; private set; }
public ICommand ResetHotKeysCmd { get; private set; }
public ICommand ResetWordPickupIntervalCmd { get; private set; }
private double _wordPickupInterval = 200;
public double WordPickupInterval { get => _wordPickupInterval; set => UpdateProperty(ref _wordPickupInterval, value); }
private static SettingsVM _instance;
public static SettingsVM Instance => _instance ?? (_instance = new SettingsVM());
}
}

Loading…
Cancel
Save