diff --git a/STranslate/Helper/GetWordsHelper.cs b/STranslate/Helper/GetWordsHelper.cs
index 52d99c1..692f726 100644
--- a/STranslate/Helper/GetWordsHelper.cs
+++ b/STranslate/Helper/GetWordsHelper.cs
@@ -9,7 +9,8 @@ namespace STranslate.Helper
public static String Get()
{
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();
}
diff --git a/STranslate/Model/ConfigModel.cs b/STranslate/Model/ConfigModel.cs
index 113701c..4e109e0 100644
--- a/STranslate/Model/ConfigModel.cs
+++ b/STranslate/Model/ConfigModel.cs
@@ -17,6 +17,7 @@ namespace STranslate.Model
{
return new ConfigModel
{
+ WordPickupInterval = 200,
IsBright = true,
SourceLanguage = LanguageEnum.AUTO.GetDescription(),
TargetLanguage = LanguageEnum.AUTO.GetDescription(),
@@ -42,6 +43,11 @@ namespace STranslate.Model
};
}
+ ///
+ /// 是否亮色模式
+ ///
+ [JsonProperty("wordPickupInterval")]
+ public double WordPickupInterval { get; set; }
///
/// 是否亮色模式
///
diff --git a/STranslate/Properties/AssemblyInfo.cs b/STranslate/Properties/AssemblyInfo.cs
index a2e0723..f3795bf 100644
--- a/STranslate/Properties/AssemblyInfo.cs
+++ b/STranslate/Properties/AssemblyInfo.cs
@@ -47,6 +47,6 @@ using System.Windows;
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("0.1.8.0")]
-[assembly: AssemblyFileVersion("0.1.8.0")]
+[assembly: AssemblyVersion("0.1.9.0")]
+[assembly: AssemblyFileVersion("0.1.9.0")]
[assembly: Guid("CE252DD8-179F-4544-9989-453F5DEA378D")]
\ No newline at end of file
diff --git a/STranslate/STranslate.csproj b/STranslate/STranslate.csproj
index c3dde3d..8485ea9 100644
--- a/STranslate/STranslate.csproj
+++ b/STranslate/STranslate.csproj
@@ -106,9 +106,13 @@
+
ScreenShotWindow.xaml
+
+ SettingsWindow.xaml
+
MSBuild:Compile
Designer
@@ -157,6 +161,10 @@
Designer
MSBuild:Compile
+
+ Designer
+ MSBuild:Compile
+
diff --git a/STranslate/View/MainWindow.xaml b/STranslate/View/MainWindow.xaml
index 1684d89..fe3953f 100644
--- a/STranslate/View/MainWindow.xaml
+++ b/STranslate/View/MainWindow.xaml
@@ -3,10 +3,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
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:vm="clr-namespace:STranslate.ViewModel"
- xmlns:local="clr-namespace:STranslate.View"
mc:Ignorable="d"
x:Name="Mwin"
Background="Transparent"
@@ -73,7 +70,13 @@
ItemsSource="{Binding TranslationInterface}"
SelectedItem="{Binding SelectedTranslationInterface, Mode=TwoWay, NotifyOnSourceUpdated=True}"
DisplayMemberPath="Name"
- HorizontalAlignment="Right"/>
+ HorizontalAlignment="Right">
+
+
+
+
+
+
diff --git a/STranslate/View/MainWindow.xaml.cs b/STranslate/View/MainWindow.xaml.cs
index 3fbd424..4c9a851 100644
--- a/STranslate/View/MainWindow.xaml.cs
+++ b/STranslate/View/MainWindow.xaml.cs
@@ -61,17 +61,13 @@ namespace STranslate.View
private MainVM vm = MainVM.Instance;
- private string _version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
-
-
public readonly NotifyIcon NotifyIcon = new NotifyIcon();
#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} {SettingsVM.Instance.Version}";
var stream = Application
.GetResourceStream(new Uri("Images/translate.ico", UriKind.Relative))?.Stream;
if (stream != null)
@@ -95,13 +91,8 @@ namespace STranslate.View
var openMainWinBtn = new MenuItem("显示主界面\tAlt+G");
openMainWinBtn.Click += OpenMainWin_Click;
- var checkUpdateBtn = new MenuItem("检查更新");
- checkUpdateBtn.Click += CheckUpdateBTN_Click;
-
- var autoStartBtn = new MenuItem("开机自启");
- autoStartBtn.Click += AutoStart_Click;
-
- autoStartBtn.Checked = StartupHelper.IsStartup();
+ var preferenceBtn = new MenuItem("首选项");
+ preferenceBtn.Click += Preference_Click;
var exitBtn = new MenuItem("退出");
exitBtn.Click += Exit_Click;
@@ -111,66 +102,35 @@ namespace STranslate.View
screenshotTranslateMenuItemBtn,
crossWordTranslateMenuItemBtn,
openMainWinBtn,
- checkUpdateBtn,
- autoStartBtn,
+ preferenceBtn,
exitBtn,
};
NotifyIcon.ContextMenu = new ContextMenu(items);
}
///
- /// 同步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
+ /// 设置
///
///
///
- 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,
- "Updater.exe");
- var updaterCacheExePath = Path.Combine(
- AppDomain.CurrentDomain.BaseDirectory,
- "Updater",
- "Updater.exe");
- var updateDirPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Updater");
- if (!Directory.Exists(updateDirPath))
+ if (item is SettingsWindow)
{
- 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)
{
-
- MessageBox.Show($"无法正确启动检查更新程序\n{ex.Message}");
+ window = new SettingsWindow();
+ window.Show();
+ window.Activate();
}
}
@@ -184,13 +144,6 @@ namespace STranslate.View
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)
{
vm.ExitApp(0);
diff --git a/STranslate/View/SettingsWindow.xaml b/STranslate/View/SettingsWindow.xaml
new file mode 100644
index 0000000..f3fdcdf
--- /dev/null
+++ b/STranslate/View/SettingsWindow.xaml
@@ -0,0 +1,341 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/STranslate/View/SettingsWindow.xaml.cs b/STranslate/View/SettingsWindow.xaml.cs
new file mode 100644
index 0000000..404f505
--- /dev/null
+++ b/STranslate/View/SettingsWindow.xaml.cs
@@ -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
+{
+ ///
+ /// SettingsWindow.xaml 的交互逻辑
+ ///
+ public partial class SettingsWindow : Window
+ {
+ public SettingsWindow()
+ {
+ InitializeComponent();
+
+ DataContext = ViewModel.SettingsVM.Instance;
+ }
+ }
+}
diff --git a/STranslate/ViewModel/MainVM.cs b/STranslate/ViewModel/MainVM.cs
index f1bb44a..52ee0ec 100644
--- a/STranslate/ViewModel/MainVM.cs
+++ b/STranslate/ViewModel/MainVM.cs
@@ -173,9 +173,23 @@ namespace STranslate.ViewModel
///
public void ScreenShotTranslate()
{
- var screen = new ScreenShotWindow();
- screen.Show();
- screen.Activate();
+ ScreenShotWindow window = null;
+ foreach (Window item in Application.Current.Windows)
+ {
+ if (item is ScreenShotWindow)
+ {
+ window = (ScreenShotWindow)item;
+ window.WindowState = WindowState.Normal;
+ window.Activate();
+ break;
+ }
+ }
+ if (window == null)
+ {
+ window = new ScreenShotWindow();
+ window.Show();
+ window.Activate();
+ }
}
///
/// 截屏翻译Ex
@@ -217,6 +231,10 @@ namespace STranslate.ViewModel
{
_globalConfig = ConfigHelper.Instance.ReadConfig();
+ //读取间隔
+ 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);
@@ -253,6 +271,7 @@ namespace STranslate.ViewModel
{
ConfigHelper.Instance.WriteConfig(new ConfigModel
{
+ WordPickupInterval = SettingsVM.Instance.WordPickupInterval,
IsBright = Application.Current.Resources.MergedDictionaries[0].Source.ToString() == ThemeDefault ? true : false,
SourceLanguage = InputComboSelected,
TargetLanguage = OutputComboSelected,
diff --git a/STranslate/ViewModel/SettingsVM.cs b/STranslate/ViewModel/SettingsVM.cs
new file mode 100644
index 0000000..c23dcf7
--- /dev/null
+++ b/STranslate/ViewModel/SettingsVM.cs
@@ -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}");
+ }
+ });
+ }
+
+
+ ///
+ /// 同步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;
+ }
+
+
+ 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());
+
+ ///
+ /// 是否开机自启
+ ///
+ private bool _isStartup;
+ public bool IsStartup { get => _isStartup; set => UpdateProperty(ref _isStartup, value); }
+
+ ///
+ /// 版本
+ ///
+ private string _version;
+ public string Version { get => _version; set => UpdateProperty(ref _version, value); }
+
+ ///
+ /// 取词间隔
+ ///
+ private double _wordPickupInterval;
+ public double WordPickupInterval { get => _wordPickupInterval; set => UpdateProperty(ref _wordPickupInterval, value); }
+
+ }
+}
diff --git a/Updater/MainWindow.xaml b/Updater/MainWindow.xaml
index ec30920..1087a8d 100644
--- a/Updater/MainWindow.xaml
+++ b/Updater/MainWindow.xaml
@@ -6,6 +6,7 @@
xmlns:local="clr-namespace:Updater"
mc:Ignorable="d"
WindowStartupLocation="CenterScreen"
+ Icon="update.ico"
Title="STranslate 升级程序" ResizeMode="NoResize" Height="300" Width="420">
diff --git a/Updater/Updater.csproj b/Updater/Updater.csproj
index e1f6b28..0baadba 100644
--- a/Updater/Updater.csproj
+++ b/Updater/Updater.csproj
@@ -40,6 +40,9 @@
4
false
+
+ update.ico
+
..\packages\Newtonsoft.Json.13.0.2\lib\net45\Newtonsoft.Json.dll
@@ -109,5 +112,8 @@
+
+
+
\ No newline at end of file
diff --git a/Updater/update.ico b/Updater/update.ico
new file mode 100644
index 0000000..c603275
Binary files /dev/null and b/Updater/update.ico differ