feat: optimize the problem of blurred icons when switching resolution

perf: update restart application after upgrade
publish: 0.22
main
DESKTOP-3BO4HSG\ksat 2 years ago
parent 1f6b277c8e
commit e4c690f226

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Windows; using System.Windows;
using System.Windows.Interop; using System.Windows.Interop;
using WpfScreenHelper;
using static STranslate.Helper.NativeMethodHelper; using static STranslate.Helper.NativeMethodHelper;
namespace STranslate.Helper namespace STranslate.Helper
@ -46,6 +47,19 @@ namespace STranslate.Helper
{ {
keymap[id] = callBack; keymap[id] = callBack;
} }
/// <summary>
/// 屏幕分辨率以及文本显示比例变更对应的消息标志
/// </summary>
private const int WmDisplayChange = 0x007e;
/// <summary>
/// 文本显示比例变更消息标志
/// </summary>
private const int WmTextChange = 0x02E0;
/// <summary>
/// window消息定义的 注册的热键消息标志
/// </summary>
private const int WmHotkeys = 0x0312;
/// <summary> /// <summary>
/// 快捷键消息处理 /// 快捷键消息处理
/// </summary> /// </summary>
@ -53,7 +67,7 @@ namespace STranslate.Helper
{ {
switch (msg) switch (msg)
{ {
case 0x0312: //这个是window消息定义的 注册的热键消息 case WmHotkeys:
int id = wParam.ToInt32(); int id = wParam.ToInt32();
if (keymap.TryGetValue(id, out var callback)) if (keymap.TryGetValue(id, out var callback))
{ {

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

@ -20,6 +20,13 @@ namespace STranslate.View
vm.Mainwin = this; vm.Mainwin = this;
InitialTray(); InitialTray();
Microsoft.Win32.SystemEvents.DisplaySettingsChanged += SystemEvents_DisplaySettingsChanged;
}
private void SystemEvents_DisplaySettingsChanged(object sender, EventArgs e)
{
InitIcon();
} }
/// <summary> /// <summary>
@ -67,14 +74,24 @@ namespace STranslate.View
public readonly NotifyIcon NotifyIcon = new NotifyIcon(); public readonly NotifyIcon NotifyIcon = new NotifyIcon();
#region Initial TrayIcon #region Initial TrayIcon
private void InitialTray() private void InitIcon()
{ {
var app = Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetEntryAssembly()?.Location);
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 (NotifyIcon.Icon != null)
{
NotifyIcon.Icon.Dispose();
}
if (stream != null) if (stream != null)
{
NotifyIcon.Icon = new System.Drawing.Icon(stream); NotifyIcon.Icon = new System.Drawing.Icon(stream);
}
}
private void InitialTray()
{
var app = Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetEntryAssembly()?.Location);
NotifyIcon.Text = $@"{app} {SettingsVM.Instance.Version}";
InitIcon();
NotifyIcon.Visible = true; NotifyIcon.Visible = true;
NotifyIcon.BalloonTipText = $@"{app} already started..."; NotifyIcon.BalloonTipText = $@"{app} already started...";
NotifyIcon.ShowBalloonTip(500); NotifyIcon.ShowBalloonTip(500);

@ -144,14 +144,14 @@ namespace Updater
if (unresult) if (unresult)
{ {
SetStatus("更新完成!", false); SetStatus("更新完成!", false);
Process tai = new Process(); Process p = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo(System.IO.Path.Combine(unpath, "Tai.exe")); ProcessStartInfo startInfo = new ProcessStartInfo(System.IO.Path.Combine(unpath, "STranslate.exe"));
tai.StartInfo = startInfo; p.StartInfo = startInfo;
tai.Start(); p.Start();
} }
else else
{ {
SetStatus("解压文件时发生异常,请重试!通常情况可能是因为Tai主程序尚未退出。", false); SetStatus("解压文件时发生异常,请重试!通常情况可能是因为 STranslate 主程序尚未退出。", false);
UpdateBtn.Visibility = Visibility.Visible; UpdateBtn.Visibility = Visibility.Visible;
} }

@ -102,6 +102,7 @@
<EmbeddedResource Include="Properties\Resources.resx"> <EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator> <Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput> <LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource> </EmbeddedResource>
<None Include="packages.config" /> <None Include="packages.config" />
<None Include="Properties\Settings.settings"> <None Include="Properties\Settings.settings">

Loading…
Cancel
Save