|
|
@ -61,15 +61,13 @@ namespace STranslate.View
|
|
|
|
|
|
|
|
|
|
|
|
private MainVM vm = MainVM.Instance;
|
|
|
|
private MainVM vm = MainVM.Instance;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public readonly NotifyIcon NotifyIcon = new NotifyIcon();
|
|
|
|
public readonly NotifyIcon NotifyIcon = new NotifyIcon();
|
|
|
|
|
|
|
|
|
|
|
|
#region Initial TrayIcon
|
|
|
|
#region Initial TrayIcon
|
|
|
|
private void InitialTray()
|
|
|
|
private void InitialTray()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var app = Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetEntryAssembly()?.Location);
|
|
|
|
var app = Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetEntryAssembly()?.Location);
|
|
|
|
NotifyIcon.Text = $@"{app} {vm.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)
|
|
|
@ -93,17 +91,9 @@ 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("检查更新");
|
|
|
|
|
|
|
|
checkUpdateBtn.Click += CheckUpdateBTN_Click;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var autoStartBtn = new MenuItem("开机自启");
|
|
|
|
|
|
|
|
autoStartBtn.Click += AutoStart_Click;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var preferenceBtn = new MenuItem("首选项");
|
|
|
|
var preferenceBtn = new MenuItem("首选项");
|
|
|
|
preferenceBtn.Click += Preference_Click;
|
|
|
|
preferenceBtn.Click += Preference_Click;
|
|
|
|
|
|
|
|
|
|
|
|
autoStartBtn.Checked = StartupHelper.IsStartup();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var exitBtn = new MenuItem("退出");
|
|
|
|
var exitBtn = new MenuItem("退出");
|
|
|
|
exitBtn.Click += Exit_Click;
|
|
|
|
exitBtn.Click += Exit_Click;
|
|
|
|
|
|
|
|
|
|
|
@ -112,8 +102,6 @@ namespace STranslate.View
|
|
|
|
screenshotTranslateMenuItemBtn,
|
|
|
|
screenshotTranslateMenuItemBtn,
|
|
|
|
crossWordTranslateMenuItemBtn,
|
|
|
|
crossWordTranslateMenuItemBtn,
|
|
|
|
openMainWinBtn,
|
|
|
|
openMainWinBtn,
|
|
|
|
checkUpdateBtn,
|
|
|
|
|
|
|
|
autoStartBtn,
|
|
|
|
|
|
|
|
preferenceBtn,
|
|
|
|
preferenceBtn,
|
|
|
|
exitBtn,
|
|
|
|
exitBtn,
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -127,51 +115,22 @@ namespace STranslate.View
|
|
|
|
/// <param name="e"></param>
|
|
|
|
/// <param name="e"></param>
|
|
|
|
private void Preference_Click(object sender, EventArgs e)
|
|
|
|
private void Preference_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var setting = new SettingsWindow();
|
|
|
|
SettingsWindow window = null;
|
|
|
|
setting.Show();
|
|
|
|
foreach (Window item in Application.Current.Windows)
|
|
|
|
setting.Activate();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 检查更新 by https://github.com/Planshit/Tai
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
|
|
|
private void CheckUpdateBTN_Click(object sender, EventArgs e)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!File.Exists(updaterExePath))
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
MessageBox.Show("升级程序似乎已被删除,请手动前往发布页查看新版本");
|
|
|
|
window = (SettingsWindow)item;
|
|
|
|
return;
|
|
|
|
window.WindowState = WindowState.Normal;
|
|
|
|
|
|
|
|
window.Activate();
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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[] { vm.Version });
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
if (window == null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
window = new SettingsWindow();
|
|
|
|
MessageBox.Show($"无法正确启动检查更新程序\n{ex.Message}");
|
|
|
|
window.Show();
|
|
|
|
|
|
|
|
window.Activate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -185,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);
|
|
|
|