11using System ;
22using System . Collections . Generic ;
3+ using System . Drawing ; // for notifyicon
34using System . Linq ;
45using System . Text ;
56using System . Threading . Tasks ;
@@ -20,6 +21,9 @@ namespace UnityLauncherPro
2021 /// </summary>
2122 public partial class MainWindow : Window
2223 {
24+
25+ private System . Windows . Forms . NotifyIcon notifyIcon ;
26+
2327 public MainWindow ( )
2428 {
2529 InitializeComponent ( ) ;
@@ -29,10 +33,39 @@ public MainWindow()
2933 void Start ( )
3034 {
3135 // test data
32- dataGrid . Items . Add ( new TestData { Project = "asdf" , Version = "5000" , Path = "A:/" , Modified = DateTime . Now , Arguments = "" , GITBranch = "-" } ) ;
33- dataGrid . Items . Add ( new TestData { Project = "asdf asd" , Version = "2" , Path = "C:/" , Modified = DateTime . Now , Arguments = "" , GITBranch = "-" } ) ;
34- dataGrid . Items . Add ( new TestData { Project = "kuykkyu" , Version = "23.23.23" , Path = "8,1" , Modified = DateTime . Now , Arguments = "" , GITBranch = "-" } ) ;
35- dataGrid . Items . Add ( new TestData { Project = "RT435y" , Version = "3333" , Path = "X:/" , Modified = DateTime . Now , Arguments = "" , GITBranch = "-" } ) ;
36+ dataGrid . Items . Add ( new Project { Title = "asdf" , Version = "5000" , Path = "A:/" , Modified = DateTime . Now , Arguments = "" , GITBranch = "-" } ) ;
37+ dataGrid . Items . Add ( new Project { Title = "asdf asd" , Version = "2" , Path = "C:/" , Modified = DateTime . Now , Arguments = "" , GITBranch = "-" } ) ;
38+ dataGrid . Items . Add ( new Project { Title = "kuykkyu" , Version = "23.23.23" , Path = "8,1" , Modified = DateTime . Now , Arguments = "" , GITBranch = "-" } ) ;
39+ dataGrid . Items . Add ( new Project { Title = "RT435y" , Version = "3333" , Path = "X:/" , Modified = DateTime . Now , Arguments = "" , GITBranch = "-" } ) ;
40+
41+ // build notifyicon
42+ notifyIcon = new System . Windows . Forms . NotifyIcon ( ) ;
43+ notifyIcon . Icon = new Icon ( System . Windows . Application . GetResourceStream ( new Uri ( "pack://application:,,,/Images/icon.ico" ) ) . Stream ) ;
44+ notifyIcon . MouseClick += new System . Windows . Forms . MouseEventHandler ( NotifyIcon_MouseClick ) ;
45+ }
46+
47+ void NotifyIcon_MouseClick ( object sender , System . Windows . Forms . MouseEventArgs e )
48+ {
49+ this . Show ( ) ;
50+ this . WindowState = WindowState . Normal ;
51+ notifyIcon . Visible = false ;
52+ }
53+
54+ private void Window_StateChanged ( object sender , EventArgs e )
55+ {
56+ if ( this . WindowState == WindowState . Minimized )
57+ {
58+ this . ShowInTaskbar = false ;
59+ notifyIcon . BalloonTipTitle = "Minimize Sucessful" ;
60+ notifyIcon . BalloonTipText = "Minimized the app " ;
61+ notifyIcon . ShowBalloonTip ( 400 ) ;
62+ notifyIcon . Visible = true ;
63+ }
64+ else if ( this . WindowState == WindowState . Normal )
65+ {
66+ notifyIcon . Visible = false ;
67+ this . ShowInTaskbar = true ;
68+ }
3669 }
3770
3871
@@ -65,7 +98,7 @@ private void BtnAddProjectFolder_Click(object sender, RoutedEventArgs e)
6598 // https://stackoverflow.com/a/50261723/5452781
6699 // Create a "Save As" dialog for selecting a directory (HACK)
67100 var dialog = new Microsoft . Win32 . SaveFileDialog ( ) ;
68- dialog . InitialDirectory = "c:" ; //textbox.Text; // Use current value for initial dir
101+ dialog . InitialDirectory = "c:" ; // Use current value for initial dir
69102 dialog . Title = "Select a Directory" ; // instead of default "Save As"
70103 dialog . Filter = "Project Folder|*.Folder" ; // Prevents displaying files
71104 dialog . FileName = "Project" ; // Filename will then be "select.this.directory"
@@ -81,7 +114,6 @@ private void BtnAddProjectFolder_Click(object sender, RoutedEventArgs e)
81114 System . IO . Directory . CreateDirectory ( path ) ;
82115 }
83116 // Our final value is in path
84- //textbox.Text = path;
85117 Console . WriteLine ( path ) ;
86118 }
87119 }
@@ -90,18 +122,13 @@ private void BtnClose_Click(object sender, RoutedEventArgs e)
90122 {
91123 this . Close ( ) ;
92124 }
93- }
94125
95- public struct TestData
96- {
97- public string Project { set ; get ; }
98- public string Version { set ; get ; }
99- public string Path { set ; get ; }
100- public DateTime Modified { set ; get ; }
101- public string Arguments { set ; get ; }
102- public string GITBranch { set ; get ; }
126+ private void BtnMinimize_Click ( object sender , RoutedEventArgs e )
127+ {
128+ // remove focus from minimize button
129+ dataGrid . Focus ( ) ;
130+ notifyIcon . Visible = true ;
131+ this . Hide ( ) ;
132+ }
103133 }
104-
105-
106-
107134}
0 commit comments