Skip to content

Commit

Permalink
now can use custom icon (place icon.ico into same folder as exe) fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
unitycoder committed Nov 24, 2024
1 parent f7f3903 commit 1c85a01
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
2 changes: 1 addition & 1 deletion UnityLauncherPro/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
</ControlTemplate>
</Button.Template>
</Button>
<Image Source="Images/icon.png" RenderOptions.BitmapScalingMode="NearestNeighbor" HorizontalAlignment="Left" Width="16" Height="16" Margin="4,0,0,0" SnapsToDevicePixels="True" UseLayoutRounding="True" />
<Image Source="Images/icon.png" x:Name="IconImage" RenderOptions.BitmapScalingMode="NearestNeighbor" HorizontalAlignment="Left" Width="16" Height="16" Margin="4,0,0,0" SnapsToDevicePixels="True" UseLayoutRounding="True" />
<Label Content="UnityLauncherPro" IsHitTestVisible="False" Margin="19,0,0,-5" Foreground="{DynamicResource ThemeMainTitle}" FontSize="12" HorizontalAlignment="Left" />
<!-- minimize -->
<Button x:Name="btnMinimize" BorderThickness="0" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" HorizontalAlignment="Right" VerticalAlignment="Top" Height="23" Width="23" Background="Transparent" Click="BtnMinimize_Click" Margin="0,0,27,0" Padding="2,0,2,8" IsTabStop="False">
Expand Down
44 changes: 41 additions & 3 deletions UnityLauncherPro/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shell;
using UnityLauncherPro.Data;
using UnityLauncherPro.Helpers;
Expand All @@ -45,7 +47,7 @@ public partial class MainWindow : Window
const string githubURL = "https://github.com/unitycoder/UnityLauncherPro";
const string resourcesURL = "https://github.com/unitycoder/UnityResources";
const string defaultAdbLogCatArgs = "-s Unity ActivityManager PackageManager dalvikvm DEBUG -v color";
System.Windows.Forms.NotifyIcon notifyIcon;
System.Windows.Forms.NotifyIcon notifyIcon = new System.Windows.Forms.NotifyIcon();

UnityVersion[] updatesSource;
public static List<string> updatesAsStrings = new List<string>();
Expand Down Expand Up @@ -110,6 +112,8 @@ void Init()
{
lblVersion.Content = "Build: " + Version.Stamp;
}

CheckCustomIcon();
}

void Start()
Expand Down Expand Up @@ -160,8 +164,6 @@ void Start()
gridBuildReportData.Items.Clear();

// build notifyicon (using windows.forms)
notifyIcon = new System.Windows.Forms.NotifyIcon();
notifyIcon.Icon = new Icon(Application.GetResourceStream(new Uri("pack://application:,,,/Images/icon.ico")).Stream);
notifyIcon.MouseClick += new System.Windows.Forms.MouseEventHandler(NotifyIcon_MouseClick);

// get original colors
Expand Down Expand Up @@ -3756,7 +3758,43 @@ private void OnPipeConnection(IAsyncResult result)
}
}

private void CheckCustomIcon()
{
string customIconPath = Path.Combine(Environment.CurrentDirectory, "icon.ico");
Console.WriteLine(customIconPath);

if (File.Exists(customIconPath))
{
try
{
// Load the custom icon using System.Drawing.Icon
using (var icon = new System.Drawing.Icon(customIconPath))
{
// Convert the icon to a BitmapSource and assign it to the WPF window's Icon property
this.Icon = Imaging.CreateBitmapSourceFromHIcon(
icon.Handle,
Int32Rect.Empty,
BitmapSizeOptions.FromEmptyOptions() // Use BitmapSizeOptions here
);

// window icon
IconImage.Source = this.Icon;
// tray icon
notifyIcon.Icon = new Icon(customIconPath);
}
}
catch (Exception ex)
{
SetStatus("Failed to load custom icon: " + ex.Message, MessageType.Warning);
Debug.WriteLine($"Failed to load custom icon: {ex.Message}");
}
}
else // no custom icon found
{
notifyIcon.Icon = new Icon(Application.GetResourceStream(new Uri("pack://application:,,,/Images/icon.ico")).Stream);
//Debug.WriteLine("Custom icon not found. Using default.");
}
}
//private void menuProjectProperties_Click(object sender, RoutedEventArgs e)
//{
// var proj = GetSelectedProject();
Expand Down

0 comments on commit 1c85a01

Please sign in to comment.