18
18
using System . Windows . Controls ;
19
19
using System . Windows . Data ;
20
20
using System . Windows . Input ;
21
+ using System . Windows . Interop ;
21
22
using System . Windows . Media ;
23
+ using System . Windows . Media . Imaging ;
22
24
using System . Windows . Shell ;
23
25
using UnityLauncherPro . Data ;
24
26
using UnityLauncherPro . Helpers ;
@@ -45,7 +47,7 @@ public partial class MainWindow : Window
45
47
const string githubURL = "https://github.com/unitycoder/UnityLauncherPro" ;
46
48
const string resourcesURL = "https://github.com/unitycoder/UnityResources" ;
47
49
const string defaultAdbLogCatArgs = "-s Unity ActivityManager PackageManager dalvikvm DEBUG -v color" ;
48
- System . Windows . Forms . NotifyIcon notifyIcon ;
50
+ System . Windows . Forms . NotifyIcon notifyIcon = new System . Windows . Forms . NotifyIcon ( ) ;
49
51
50
52
UnityVersion [ ] updatesSource ;
51
53
public static List < string > updatesAsStrings = new List < string > ( ) ;
@@ -110,6 +112,8 @@ void Init()
110
112
{
111
113
lblVersion . Content = "Build: " + Version . Stamp ;
112
114
}
115
+
116
+ CheckCustomIcon ( ) ;
113
117
}
114
118
115
119
void Start ( )
@@ -160,8 +164,6 @@ void Start()
160
164
gridBuildReportData . Items . Clear ( ) ;
161
165
162
166
// build notifyicon (using windows.forms)
163
- notifyIcon = new System . Windows . Forms . NotifyIcon ( ) ;
164
- notifyIcon . Icon = new Icon ( Application . GetResourceStream ( new Uri ( "pack://application:,,,/Images/icon.ico" ) ) . Stream ) ;
165
167
notifyIcon . MouseClick += new System . Windows . Forms . MouseEventHandler ( NotifyIcon_MouseClick ) ;
166
168
167
169
// get original colors
@@ -3756,7 +3758,43 @@ private void OnPipeConnection(IAsyncResult result)
3756
3758
}
3757
3759
}
3758
3760
3761
+ private void CheckCustomIcon ( )
3762
+ {
3763
+ string customIconPath = Path . Combine ( Environment . CurrentDirectory , "icon.ico" ) ;
3764
+ Console . WriteLine ( customIconPath ) ;
3759
3765
3766
+ if ( File . Exists ( customIconPath ) )
3767
+ {
3768
+ try
3769
+ {
3770
+ // Load the custom icon using System.Drawing.Icon
3771
+ using ( var icon = new System . Drawing . Icon ( customIconPath ) )
3772
+ {
3773
+ // Convert the icon to a BitmapSource and assign it to the WPF window's Icon property
3774
+ this . Icon = Imaging . CreateBitmapSourceFromHIcon (
3775
+ icon . Handle ,
3776
+ Int32Rect . Empty ,
3777
+ BitmapSizeOptions . FromEmptyOptions ( ) // Use BitmapSizeOptions here
3778
+ ) ;
3779
+
3780
+ // window icon
3781
+ IconImage . Source = this . Icon ;
3782
+ // tray icon
3783
+ notifyIcon . Icon = new Icon ( customIconPath ) ;
3784
+ }
3785
+ }
3786
+ catch ( Exception ex )
3787
+ {
3788
+ SetStatus ( "Failed to load custom icon: " + ex . Message , MessageType . Warning ) ;
3789
+ Debug . WriteLine ( $ "Failed to load custom icon: { ex . Message } ") ;
3790
+ }
3791
+ }
3792
+ else // no custom icon found
3793
+ {
3794
+ notifyIcon . Icon = new Icon ( Application . GetResourceStream ( new Uri ( "pack://application:,,,/Images/icon.ico" ) ) . Stream ) ;
3795
+ //Debug.WriteLine("Custom icon not found. Using default.");
3796
+ }
3797
+ }
3760
3798
//private void menuProjectProperties_Click(object sender, RoutedEventArgs e)
3761
3799
//{
3762
3800
// var proj = GetSelectedProject();
0 commit comments