Improve notify icon

pull/2295/head
2dust 2022-04-26 14:51:06 +08:00
parent 6f3fbdfe17
commit a7741a0b7d
11 changed files with 100 additions and 1163 deletions

View File

@ -7,7 +7,6 @@ namespace v2rayN.Forms
public partial class BaseForm : Form
{
protected static Config config;
protected static System.Drawing.Icon icon;
public BaseForm()
{
@ -19,16 +18,14 @@ namespace v2rayN.Forms
{
try
{
if (icon == null)
string file = Utils.GetPath(Global.CustomIconName);
if (System.IO.File.Exists(file))
{
string file = Utils.GetPath(Global.CustomIconName);
if (!System.IO.File.Exists(file))
{
return;
}
icon = new System.Drawing.Icon(file);
this.Icon = new System.Drawing.Icon(file);
return;
}
this.Icon = icon;
this.Icon = Properties.Resources.NotifyIcon1;
}
catch (Exception e)
{

File diff suppressed because it is too large Load Diff

View File

@ -1273,7 +1273,7 @@ namespace v2rayN.Forms
mainMsgControl.DisplayToolStatus(config);
notifyMain.Icon = MainFormHandler.Instance.GetNotifyIcon(config, this.Icon);
notifyMain.Icon = this.Icon = MainFormHandler.Instance.GetNotifyIcon(config, this.Icon);
}
#endregion

View File

@ -32,12 +32,59 @@ namespace v2rayN.Handler
{
try
{
int index = (int)config.sysProxyType;
//Load from routing setting
var createdIcon = GetNotifyIcon4Routing(config);
if (createdIcon != null)
{
return createdIcon;
}
//Load from local file
var fileName = Utils.GetPath($"NotifyIcon{index + 1}.ico");
if (File.Exists(fileName))
{
return new Icon(fileName);
}
switch (index)
{
case 0:
return Properties.Resources.NotifyIcon1;
case 1:
return Properties.Resources.NotifyIcon2;
case 2:
return Properties.Resources.NotifyIcon3;
}
return Properties.Resources.NotifyIcon1;
}
catch (Exception ex)
{
Utils.SaveLog(ex.Message, ex);
return def;
}
}
private Icon GetNotifyIcon4Routing(Config config)
{
try
{
if (!config.enableRoutingAdvanced)
{
return null;
}
var item = config.routings[config.routingIndex];
if (Utils.IsNullOrEmpty(item.customIcon) || !File.Exists(item.customIcon))
{
return null;
}
Color color = ColorTranslator.FromHtml("#3399CC");
int index = (int)config.sysProxyType;
if (index > 0)
{
color = (new Color[] { Color.Red, Color.Purple, Color.DarkGreen, Color.Orange, Color.DarkSlateBlue, Color.RoyalBlue })[index - 1];
//color = ColorTranslator.FromHtml(new string[] { "#CC0066", "#CC6600", "#99CC99", "#666699" }[index - 1]);
}
int width = 128;
@ -47,24 +94,8 @@ namespace v2rayN.Handler
Graphics graphics = Graphics.FromImage(bitmap);
SolidBrush drawBrush = new SolidBrush(color);
var customIcon = false;
if (config.enableRoutingAdvanced)
{
var item = config.routings[config.routingIndex];
if (!Utils.IsNullOrEmpty(item.customIcon) && File.Exists(item.customIcon))
{
graphics.FillRectangle(drawBrush, new Rectangle(0, 0, width, height));
graphics.DrawImage(new Bitmap(item.customIcon), 0, 0, width, height);
customIcon = true;
}
}
if (!customIcon)
{
graphics.FillEllipse(drawBrush, new Rectangle(0, 0, width, height));
int zoom = 16;
graphics.DrawImage(new Bitmap(Properties.Resources.notify, width - zoom, width - zoom), zoom / 2, zoom / 2);
}
graphics.FillRectangle(drawBrush, new Rectangle(0, 0, width, height));
graphics.DrawImage(new Bitmap(item.customIcon), 0, 0, width, height);
Icon createdIcon = Icon.FromHandle(bitmap.GetHicon());
drawBrush.Dispose();
@ -76,7 +107,7 @@ namespace v2rayN.Handler
catch (Exception ex)
{
Utils.SaveLog(ex.Message, ex);
return def;
return null;
}
}

View File

@ -110,6 +110,36 @@ namespace v2rayN.Properties {
}
}
/// <summary>
/// 查找类似于 (图标) 的 System.Drawing.Icon 类型的本地化资源。
/// </summary>
internal static System.Drawing.Icon NotifyIcon1 {
get {
object obj = ResourceManager.GetObject("NotifyIcon1", resourceCulture);
return ((System.Drawing.Icon)(obj));
}
}
/// <summary>
/// 查找类似于 (图标) 的 System.Drawing.Icon 类型的本地化资源。
/// </summary>
internal static System.Drawing.Icon NotifyIcon2 {
get {
object obj = ResourceManager.GetObject("NotifyIcon2", resourceCulture);
return ((System.Drawing.Icon)(obj));
}
}
/// <summary>
/// 查找类似于 (图标) 的 System.Drawing.Icon 类型的本地化资源。
/// </summary>
internal static System.Drawing.Icon NotifyIcon3 {
get {
object obj = ResourceManager.GetObject("NotifyIcon3", resourceCulture);
return ((System.Drawing.Icon)(obj));
}
}
/// <summary>
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
/// </summary>

View File

@ -157,4 +157,13 @@
<data name="share" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\resources\share.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="NotifyIcon1" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\NotifyIcon1.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="NotifyIcon2" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\NotifyIcon2.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="NotifyIcon3" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\NotifyIcon3.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

View File

@ -474,6 +474,9 @@
<None Include="Resources\minimize.png" />
</ItemGroup>
<ItemGroup>
<Content Include="Resources\NotifyIcon1.ico" />
<Content Include="Resources\NotifyIcon2.ico" />
<Content Include="Resources\NotifyIcon3.ico" />
<EmbeddedResource Include="Sample\SampleInbound.txt" />
<None Include="Resources\share.png" />
<None Include="Resources\promotion.png" />

Binary file not shown.

Before

Width:  |  Height:  |  Size: 66 KiB

After

Width:  |  Height:  |  Size: 60 KiB