Merge branch 'dev_settings'

dev_settings 0.19
DESKTOP-3BO4HSG\ksat 2 years ago
commit 4974e53bf1

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

@ -17,6 +17,7 @@ namespace STranslate.Model
{ {
return new ConfigModel return new ConfigModel
{ {
WordPickupInterval = 200,
IsBright = true, IsBright = true,
SourceLanguage = LanguageEnum.AUTO.GetDescription(), SourceLanguage = LanguageEnum.AUTO.GetDescription(),
TargetLanguage = LanguageEnum.AUTO.GetDescription(), TargetLanguage = LanguageEnum.AUTO.GetDescription(),
@ -42,6 +43,11 @@ namespace STranslate.Model
}; };
} }
/// <summary>
/// 是否亮色模式
/// </summary>
[JsonProperty("wordPickupInterval")]
public double WordPickupInterval { get; set; }
/// <summary> /// <summary>
/// 是否亮色模式 /// 是否亮色模式
/// </summary> /// </summary>

@ -47,6 +47,6 @@ using System.Windows;
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示: //通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.1.8.0")] [assembly: AssemblyVersion("0.1.9.0")]
[assembly: AssemblyFileVersion("0.1.8.0")] [assembly: AssemblyFileVersion("0.1.9.0")]
[assembly: Guid("CE252DD8-179F-4544-9989-453F5DEA378D")] [assembly: Guid("CE252DD8-179F-4544-9989-453F5DEA378D")]

@ -106,9 +106,13 @@
<Compile Include="Util\Util.cs" /> <Compile Include="Util\Util.cs" />
<Compile Include="ViewModel\MainVM.cs" /> <Compile Include="ViewModel\MainVM.cs" />
<Compile Include="ViewModel\ScreenShotVM.cs" /> <Compile Include="ViewModel\ScreenShotVM.cs" />
<Compile Include="ViewModel\SettingsVM.cs" />
<Compile Include="View\ScreenShotWindow.xaml.cs"> <Compile Include="View\ScreenShotWindow.xaml.cs">
<DependentUpon>ScreenShotWindow.xaml</DependentUpon> <DependentUpon>ScreenShotWindow.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="View\SettingsWindow.xaml.cs">
<DependentUpon>SettingsWindow.xaml</DependentUpon>
</Compile>
<Page Include="View\MainWindow.xaml"> <Page Include="View\MainWindow.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType> <SubType>Designer</SubType>
@ -157,6 +161,10 @@
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</Page> </Page>
<Page Include="View\SettingsWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Model\BaiduModel.cs" /> <Compile Include="Model\BaiduModel.cs" />

@ -3,10 +3,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:tb="http://www.hardcodet.net/taskbar"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors" xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:vm="clr-namespace:STranslate.ViewModel"
xmlns:local="clr-namespace:STranslate.View"
mc:Ignorable="d" mc:Ignorable="d"
x:Name="Mwin" x:Name="Mwin"
Background="Transparent" Background="Transparent"
@ -73,7 +70,13 @@
ItemsSource="{Binding TranslationInterface}" ItemsSource="{Binding TranslationInterface}"
SelectedItem="{Binding SelectedTranslationInterface, Mode=TwoWay, NotifyOnSourceUpdated=True}" SelectedItem="{Binding SelectedTranslationInterface, Mode=TwoWay, NotifyOnSourceUpdated=True}"
DisplayMemberPath="Name" DisplayMemberPath="Name"
HorizontalAlignment="Right"/> HorizontalAlignment="Right">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding SelectLangChangedCmd}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</ComboBox>
</Grid> </Grid>
<!--input--> <!--input-->

@ -61,17 +61,13 @@ namespace STranslate.View
private MainVM vm = MainVM.Instance; private MainVM vm = MainVM.Instance;
private string _version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
public readonly NotifyIcon NotifyIcon = new NotifyIcon(); public readonly NotifyIcon NotifyIcon = new NotifyIcon();
#region Initial TrayIcon #region Initial TrayIcon
private void InitialTray() private void InitialTray()
{ {
_version = HandleVersion(_version);
var app = Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetEntryAssembly()?.Location); var app = Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetEntryAssembly()?.Location);
NotifyIcon.Text = $@"{app} {_version}"; NotifyIcon.Text = $@"{app} {SettingsVM.Instance.Version}";
var stream = Application var stream = Application
.GetResourceStream(new Uri("Images/translate.ico", UriKind.Relative))?.Stream; .GetResourceStream(new Uri("Images/translate.ico", UriKind.Relative))?.Stream;
if (stream != null) if (stream != null)
@ -95,13 +91,8 @@ namespace STranslate.View
var openMainWinBtn = new MenuItem("显示主界面\tAlt+G"); var openMainWinBtn = new MenuItem("显示主界面\tAlt+G");
openMainWinBtn.Click += OpenMainWin_Click; openMainWinBtn.Click += OpenMainWin_Click;
var checkUpdateBtn = new MenuItem("检查更新"); var preferenceBtn = new MenuItem("首选项");
checkUpdateBtn.Click += CheckUpdateBTN_Click; preferenceBtn.Click += Preference_Click;
var autoStartBtn = new MenuItem("开机自启");
autoStartBtn.Click += AutoStart_Click;
autoStartBtn.Checked = StartupHelper.IsStartup();
var exitBtn = new MenuItem("退出"); var exitBtn = new MenuItem("退出");
exitBtn.Click += Exit_Click; exitBtn.Click += Exit_Click;
@ -111,66 +102,35 @@ namespace STranslate.View
screenshotTranslateMenuItemBtn, screenshotTranslateMenuItemBtn,
crossWordTranslateMenuItemBtn, crossWordTranslateMenuItemBtn,
openMainWinBtn, openMainWinBtn,
checkUpdateBtn, preferenceBtn,
autoStartBtn,
exitBtn, exitBtn,
}; };
NotifyIcon.ContextMenu = new ContextMenu(items); NotifyIcon.ContextMenu = new ContextMenu(items);
} }
/// <summary> /// <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
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void CheckUpdateBTN_Click(object sender, EventArgs e) private void Preference_Click(object sender, EventArgs e)
{ {
try SettingsWindow window = null;
foreach (Window item in Application.Current.Windows)
{ {
var updaterExePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, if (item is SettingsWindow)
"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); window = (SettingsWindow)item;
window.WindowState = WindowState.Normal;
window.Activate();
break;
} }
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) if (window == null)
{ {
window = new SettingsWindow();
MessageBox.Show($"无法正确启动检查更新程序\n{ex.Message}"); window.Show();
window.Activate();
} }
} }
@ -184,13 +144,6 @@ namespace STranslate.View
vm.OpenMainWin(); 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) private void Exit_Click(object sender, EventArgs e)
{ {
vm.ExitApp(0); vm.ExitApp(0);

@ -0,0 +1,341 @@
<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:local="clr-namespace:STranslate.View"
mc:Ignorable="d"
SizeToContent="Height"
WindowStartupLocation="CenterScreen"
Icon="/Images/translate.ico"
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>
<Window.InputBindings>
<KeyBinding Key="Esc"
Command="{Binding EscCmd}"
CommandParameter="{Binding ElementName=window, Mode=OneWay}"/>
</Window.InputBindings>
<i:Interaction.Triggers>
<i:EventTrigger EventName="Closed">
<i:InvokeCommandAction Command="{Binding ClosedCmd}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<Grid Margin="20">
<TabControl>
<TabItem Header="常规"
Padding="10,2">
<StackPanel Margin="20">
<GroupBox Header="开机启动">
<WrapPanel Margin="0,5,0,5">
<CheckBox Content="开机启动"
IsChecked="{Binding IsStartup}"
FontWeight="Bold">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Checked">
<i:InvokeCommandAction Command="{Binding StartupCmd}"/>
</i:EventTrigger>
<i:EventTrigger EventName="Unchecked">
<i:InvokeCommandAction Command="{Binding StartupCmd}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</CheckBox>
</WrapPanel>
</GroupBox>
<GroupBox Header="取词间隔"
ToolTip="划词翻译实现原理是用户用鼠标划词后模拟Ctrl+C间隔一定时间后程序再从剪切板取词如果电脑反应慢可能会出现取不到词的问题将间隔调大可以适配一些老旧的机器">
<WrapPanel Margin="0,5,0,5">
<Slider Value="{Binding DataContext.WordPickupInterval, ElementName=window}"
Minimum="100"
Maximum="1000"
MinWidth="200"
TickFrequency="100"
TickPlacement="None"
IsSnapToTickEnabled="True">
</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="服务"
Visibility="Collapsed"
Padding="10,2">
<GroupBox Header="DeepL API">
</GroupBox>
</TabItem>
<TabItem Header="关于"
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="Bold"/>
</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 x:Name="Label_Version"
DataContext="https://github.com/zggsong/stranslate/releases"
Cursor="Hand"
Content="{Binding DataContext.Version, ElementName=window}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseDown">
<i:InvokeCommandAction Command="{Binding DataContext.OpenUrlCmd, ElementName=window}"
CommandParameter="{Binding ElementName=Label_Version, Path=DataContext}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Label>
<Button Content="检查更新"
Margin="40,0"
Template="{StaticResource buttonstyle}"
Command="{Binding UpdateCmd}">
</Button>
</WrapPanel>
<WrapPanel>
<Label Content="开源"/>
<Label x:Name="Label_Lic"
Content="MIT License"
DataContext="https://github.com/ZGGSONG/STranslate/blob/main/LICENSE"
Cursor="Hand">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseDown">
<i:InvokeCommandAction Command="{Binding DataContext.OpenUrlCmd, ElementName=window}"
CommandParameter="{Binding ElementName=Label_Lic, Path=DataContext}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Label>
</WrapPanel>
<WrapPanel>
<Label Content="版权"/>
<Label x:Name="Label_Ccopyright"
Content="@2022 ZGGSONG"
DataContext="https://github.com/ZGGSONG"
Cursor="Hand">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseDown">
<i:InvokeCommandAction Command="{Binding DataContext.OpenUrlCmd, ElementName=window}"
CommandParameter="{Binding ElementName=Label_Ccopyright, Path=DataContext}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Label>
</WrapPanel>
<WrapPanel>
<Label Content="联系"/>
<Label x:Name="Label_Connect"
Content="zggsong@foxmail.com"
DataContext="zggsong@foxmail.com"
Cursor="Hand">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseDown">
<i:InvokeCommandAction Command="{Binding DataContext.OpenUrlCmd, ElementName=window}"
CommandParameter="{Binding ElementName=Label_Connect, Path=DataContext}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Label>
</WrapPanel>
<WrapPanel>
<Label Content="源码"/>
<Label x:Name="Label_Source" Content="https://github.com/zggsong/stranslate"
DataContext="https://github.com/ZGGSONG/STranslate"
Cursor="Hand">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseDown">
<i:InvokeCommandAction Command="{Binding DataContext.OpenUrlCmd, ElementName=window}"
CommandParameter="{Binding ElementName=Label_Source, Path=DataContext}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Label>
</WrapPanel>
<WrapPanel>
<Label Content="反馈"/>
<Label x:Name="Label_Feedback" Content="https://github.com/zggsong/stranslate/issues"
DataContext="https://github.com/ZGGSONG/STranslate/issues"
Cursor="Hand">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseDown">
<i:InvokeCommandAction Command="{Binding DataContext.OpenUrlCmd, ElementName=window}"
CommandParameter="{Binding ElementName=Label_Feedback, Path=DataContext}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Label>
</WrapPanel>
</StackPanel>
</ScrollViewer>
</TabItem>
</TabControl>
</Grid>
</Window>

@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace STranslate.View
{
/// <summary>
/// SettingsWindow.xaml 的交互逻辑
/// </summary>
public partial class SettingsWindow : Window
{
public SettingsWindow()
{
InitializeComponent();
DataContext = ViewModel.SettingsVM.Instance;
}
}
}

@ -173,9 +173,23 @@ namespace STranslate.ViewModel
/// </summary> /// </summary>
public void ScreenShotTranslate() public void ScreenShotTranslate()
{ {
var screen = new ScreenShotWindow(); ScreenShotWindow window = null;
screen.Show(); foreach (Window item in Application.Current.Windows)
screen.Activate(); {
if (item is ScreenShotWindow)
{
window = (ScreenShotWindow)item;
window.WindowState = WindowState.Normal;
window.Activate();
break;
}
}
if (window == null)
{
window = new ScreenShotWindow();
window.Show();
window.Activate();
}
} }
/// <summary> /// <summary>
/// 截屏翻译Ex /// 截屏翻译Ex
@ -217,6 +231,10 @@ namespace STranslate.ViewModel
{ {
_globalConfig = ConfigHelper.Instance.ReadConfig<ConfigModel>(); _globalConfig = ConfigHelper.Instance.ReadConfig<ConfigModel>();
//读取间隔
var tmp = _globalConfig.WordPickupInterval;
SettingsVM.Instance.WordPickupInterval = (tmp == 0 || tmp > 1000 || tmp < 100) ? 200 : tmp;
//配置读取主题 //配置读取主题
Application.Current.Resources.MergedDictionaries[0].Source = _globalConfig.IsBright ? new Uri(ThemeDefault) : new Uri(ThemeDark); Application.Current.Resources.MergedDictionaries[0].Source = _globalConfig.IsBright ? new Uri(ThemeDefault) : new Uri(ThemeDark);
@ -253,6 +271,7 @@ namespace STranslate.ViewModel
{ {
ConfigHelper.Instance.WriteConfig(new ConfigModel ConfigHelper.Instance.WriteConfig(new ConfigModel
{ {
WordPickupInterval = SettingsVM.Instance.WordPickupInterval,
IsBright = Application.Current.Resources.MergedDictionaries[0].Source.ToString() == ThemeDefault ? true : false, IsBright = Application.Current.Resources.MergedDictionaries[0].Source.ToString() == ThemeDefault ? true : false,
SourceLanguage = InputComboSelected, SourceLanguage = InputComboSelected,
TargetLanguage = OutputComboSelected, TargetLanguage = OutputComboSelected,

@ -0,0 +1,134 @@
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 SettingsVM()
{
IsStartup = StartupHelper.IsStartup();
Version = HandleVersion(System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString() ?? "1.0.0.0");
ClosedCmd = new RelayCommand((_) => true, (_) =>
{
Util.Util.FlushMemory();
});
//更新
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}");
}
});
StartupCmd = new RelayCommand((_) => true, (_) =>
{
if (StartupHelper.IsStartup()) StartupHelper.UnSetStartup();
else StartupHelper.SetStartup();
IsStartup = StartupHelper.IsStartup();
});
EscCmd = new RelayCommand((_) => true, (o) =>
{
(o as Window)?.Close();
});
OpenUrlCmd = new RelayCommand((_) => true, (o) =>
{
try
{
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = o.ToString();
proc.Start();
}
catch (Exception ex)
{
MessageBox.Show($"未找到默认应用\n{ex.Message}");
}
});
}
/// <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;
}
public ICommand ClosedCmd { get; private set; }
public ICommand OpenUrlCmd { get; private set; }
public ICommand UpdateCmd { get; private set; }
public ICommand StartupCmd { get; private set; }
public ICommand EscCmd { get; private set; }
private static SettingsVM _instance;
public static SettingsVM Instance => _instance ?? (_instance = new SettingsVM());
/// <summary>
/// 是否开机自启
/// </summary>
private bool _isStartup;
public bool IsStartup { get => _isStartup; set => UpdateProperty(ref _isStartup, value); }
/// <summary>
/// 版本
/// </summary>
private string _version;
public string Version { get => _version; set => UpdateProperty(ref _version, value); }
/// <summary>
/// 取词间隔
/// </summary>
private double _wordPickupInterval;
public double WordPickupInterval { get => _wordPickupInterval; set => UpdateProperty(ref _wordPickupInterval, value); }
}
}

@ -6,6 +6,7 @@
xmlns:local="clr-namespace:Updater" xmlns:local="clr-namespace:Updater"
mc:Ignorable="d" mc:Ignorable="d"
WindowStartupLocation="CenterScreen" WindowStartupLocation="CenterScreen"
Icon="update.ico"
Title="STranslate 升级程序" ResizeMode="NoResize" Height="300" Width="420"> Title="STranslate 升级程序" ResizeMode="NoResize" Height="300" Width="420">
<Grid Margin="10"> <Grid Margin="10">
<Grid.RowDefinitions> <Grid.RowDefinitions>

@ -40,6 +40,9 @@
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit> <Prefer32Bit>false</Prefer32Bit>
</PropertyGroup> </PropertyGroup>
<PropertyGroup>
<ApplicationIcon>update.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> <Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.2\lib\net45\Newtonsoft.Json.dll</HintPath> <HintPath>..\packages\Newtonsoft.Json.13.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
@ -109,5 +112,8 @@
<ItemGroup> <ItemGroup>
<None Include="App.config" /> <None Include="App.config" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Resource Include="update.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project> </Project>

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Loading…
Cancel
Save