diff --git a/STranslate/Helper/GetWordsHelper.cs b/STranslate/Helper/GetWordsHelper.cs
index 52d99c1..4350a2a 100644
--- a/STranslate/Helper/GetWordsHelper.cs
+++ b/STranslate/Helper/GetWordsHelper.cs
@@ -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();
}
diff --git a/STranslate/STranslate.csproj b/STranslate/STranslate.csproj
index 8485ea9..17714fe 100644
--- a/STranslate/STranslate.csproj
+++ b/STranslate/STranslate.csproj
@@ -104,6 +104,7 @@
Resources.resx
+
diff --git a/STranslate/View/MainWindow.xaml.cs b/STranslate/View/MainWindow.xaml.cs
index a1d403f..d57886a 100644
--- a/STranslate/View/MainWindow.xaml.cs
+++ b/STranslate/View/MainWindow.xaml.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();
}
- ///
- /// 同步Github版本命名
- ///
- ///
- ///
- 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;
- }
///
/// 检查更新 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)
{
diff --git a/STranslate/View/SettingsWindow.xaml b/STranslate/View/SettingsWindow.xaml
index 8366213..dbdbf10 100644
--- a/STranslate/View/SettingsWindow.xaml
+++ b/STranslate/View/SettingsWindow.xaml
@@ -1,18 +1,39 @@
-
-
-
-
+ Title="STranslate 首选项" Height="450" Width="450">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -21,9 +42,238 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/STranslate/View/SettingsWindow.xaml.cs b/STranslate/View/SettingsWindow.xaml.cs
index 0d5da45..404f505 100644
--- a/STranslate/View/SettingsWindow.xaml.cs
+++ b/STranslate/View/SettingsWindow.xaml.cs
@@ -22,6 +22,8 @@ namespace STranslate.View
public SettingsWindow()
{
InitializeComponent();
+
+ DataContext = ViewModel.SettingsVM.Instance;
}
}
}
diff --git a/STranslate/ViewModel/BaseMainVM.cs b/STranslate/ViewModel/BaseMainVM.cs
new file mode 100644
index 0000000..3eca5d0
--- /dev/null
+++ b/STranslate/ViewModel/BaseMainVM.cs
@@ -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");
+ }
+
+
+ ///
+ /// 同步Github版本命名
+ ///
+ ///
+ ///
+ 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); }
+
+ }
+}
diff --git a/STranslate/ViewModel/MainVM.cs b/STranslate/ViewModel/MainVM.cs
index f1bb44a..e96ac46 100644
--- a/STranslate/ViewModel/MainVM.cs
+++ b/STranslate/ViewModel/MainVM.cs
@@ -13,7 +13,7 @@ using System.Windows.Controls;
namespace STranslate.ViewModel
{
- public class MainVM : BaseVM
+ public class MainVM : BaseMainVM
{
public MainVM()
{
diff --git a/STranslate/ViewModel/SettingsVM.cs b/STranslate/ViewModel/SettingsVM.cs
index 4ae8a41..07209f4 100644
--- a/STranslate/ViewModel/SettingsVM.cs
+++ b/STranslate/ViewModel/SettingsVM.cs
@@ -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());
}
}