33using System . Reflection ;
44using System . Threading ;
55using System . Windows . Forms ;
6+ using System . Diagnostics ;
67
78namespace FreshTools
89{
@@ -56,23 +57,38 @@ public void InitializeNotificationIcon()
5657 startIdlePreventionMenuItem = new MenuItem ( "Start Idle Prevention" ) ;
5758 stopIdlePreventionMenuItem = new MenuItem ( "Stop Idle Prevention" ) ;
5859
59- MenuItem windowHotKeysEnabledManagerMenuItem = new MenuItem ( "Window Control Hot Keys" ) ;
60- windowHotKeysEnabledManagerMenuItem . Checked = WindowManager . HotKeysEnabled ;
60+ MenuItem windowManagerHotKeysEnabledMenuItem = new MenuItem ( "Window Control Hot Keys" ) ;
61+ windowManagerHotKeysEnabledMenuItem . Checked = WindowManager . HotKeysEnabled ;
62+
63+ MenuItem windowManagerSaveWindowsMenuItem = new MenuItem ( "Save All Window Positions" ) ;
64+ MenuItem windowManagerRestoreWindowsMenuItem = new MenuItem ( "Restore All Window Positions" ) ;
65+ MenuItem windowManagerUndoRestoreWindowsMenuItem = new MenuItem ( "Restore All Window Positions (undo)" ) ;
66+
67+ MenuItem startupEnabledMenuItem = new MenuItem ( "Start With Windows" ) ;
68+ startupEnabledMenuItem . Checked = FreshArchives . IsApplicationInStartup ( ) ;
6169
6270 MenuItem quitMenuItem = new MenuItem ( "Quit" ) ;
6371
6472 ContextMenu contextMenu = new ContextMenu ( ) ;
6573 contextMenu . MenuItems . Add ( titleMenuItem ) ;
6674 contextMenu . MenuItems . Add ( breakMenuItem ) ;
6775 contextMenu . MenuItems . Add ( startIdlePreventionMenuItem ) ;
68- contextMenu . MenuItems . Add ( windowHotKeysEnabledManagerMenuItem ) ;
76+ contextMenu . MenuItems . Add ( windowManagerHotKeysEnabledMenuItem ) ;
77+ contextMenu . MenuItems . Add ( windowManagerSaveWindowsMenuItem ) ;
78+ contextMenu . MenuItems . Add ( windowManagerRestoreWindowsMenuItem ) ;
79+ contextMenu . MenuItems . Add ( windowManagerUndoRestoreWindowsMenuItem ) ;
80+ contextMenu . MenuItems . Add ( startupEnabledMenuItem ) ;
6981 contextMenu . MenuItems . Add ( quitMenuItem ) ;
7082 freshToolsNotifyIcon . ContextMenu = contextMenu ;
7183
7284 // Wire up menu items
7385 startIdlePreventionMenuItem . Click += startIdlePreventionMenuItem_Click ;
7486 stopIdlePreventionMenuItem . Click += stopIdlePreventionMenuItem_Click ;
75- windowHotKeysEnabledManagerMenuItem . Click += windowHotKeysEnabledMenuItem_Click ;
87+ windowManagerHotKeysEnabledMenuItem . Click += windowHotKeysEnabledMenuItem_Click ;
88+ windowManagerSaveWindowsMenuItem . Click += WindowManager . SaveAllWindowPositions ;
89+ windowManagerRestoreWindowsMenuItem . Click += WindowManager . RestoreAllWindowPositions ;
90+ windowManagerUndoRestoreWindowsMenuItem . Click += WindowManager . UndoRestoreAllWindowPositions ;
91+ startupEnabledMenuItem . Click += startupEnabledMenuItem_Click ;
7692 quitMenuItem . Click += quitMenuItem_Click ;
7793 }
7894
@@ -82,9 +98,24 @@ public void InitializeNotificationIcon()
8298 [ STAThread ]
8399 static void Main ( string [ ] args )
84100 {
85- Application . EnableVisualStyles ( ) ;
86- Application . SetCompatibleTextRenderingDefault ( false ) ;
87- Application . Run ( new FreshTools ( ) ) ;
101+ string mutex_id = "FreshTools" ;
102+ bool createdNew = true ;
103+ using ( Mutex mutex = new Mutex ( true , mutex_id , out createdNew ) )
104+ {
105+ if ( ! createdNew )
106+ {
107+ Process thisProccess = Process . GetCurrentProcess ( ) ;
108+ foreach ( var process in Process . GetProcessesByName ( thisProccess . ProcessName ) )
109+ {
110+ if ( process . Id != thisProccess . Id )
111+ process . Kill ( ) ;
112+ }
113+ //MessageBox.Show("Killed old process and started new!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
114+ }
115+ Application . EnableVisualStyles ( ) ;
116+ Application . SetCompatibleTextRenderingDefault ( false ) ;
117+ Application . Run ( new FreshTools ( ) ) ;
118+ }
88119 }
89120
90121 public void LoadConfig ( )
@@ -146,6 +177,16 @@ private void windowHotKeysEnabledMenuItem_Click(object sender, EventArgs e)
146177 WindowManager . HotKeysEnabled = i . Checked ;
147178 }
148179
180+ private void startupEnabledMenuItem_Click ( object sender , EventArgs e )
181+ {
182+ MenuItem i = ( MenuItem ) sender ;
183+ if ( FreshArchives . IsApplicationInStartup ( ) )
184+ FreshArchives . RemoveApplicationFromStartup ( ) ;
185+ else
186+ FreshArchives . AddApplicationToStartup ( ) ;
187+ i . Checked = FreshArchives . IsApplicationInStartup ( ) ;
188+ }
189+
149190 /// <summary>
150191 /// Close the application on click of 'quit' button on context menu
151192 /// </summary>
@@ -171,21 +212,31 @@ private static void RegisterHotkeys()
171212 //register hotkey(s)
172213 //GenericsClass.LogSystem("Registering Hotkeys");
173214 HotKeyManager . GenericHotKeyPressedHandler += new EventHandler < HotKeyEventArgs > ( GenericHotKeyPressed ) ;
174- HotKeyManager . RegisterHotKey ( ( KeyModifiers . NoRepeat | KeyModifiers . Control | KeyModifiers . Alt | KeyModifiers . Shift ) , Keys . Oemtilde ) ;
215+ //HotKeyManager.RegisterHotKey((KeyModifiers.NoRepeat | KeyModifiers.Control | KeyModifiers.Shift), Keys.C);
216+ //HotKeyManager.RegisterHotKey((KeyModifiers.NoRepeat | KeyModifiers.Control | KeyModifiers.Shift), Keys.X);
217+ //HotKeyManager.RegisterHotKey((KeyModifiers.NoRepeat | KeyModifiers.Control | KeyModifiers.Shift), Keys.Z);
175218 }
176219
177220 private static void GenericHotKeyPressed ( object sender , HotKeyEventArgs args )
178221 {
179222 try
180223 {
181- if ( args . Modifiers == ( KeyModifiers . NoRepeat | KeyModifiers . Control | KeyModifiers . Alt | KeyModifiers . Shift ) && args . Key == Keys . Oemtilde )
224+ if ( args . Modifiers == ( KeyModifiers . Control | KeyModifiers . Shift ) && args . Key == Keys . C )
225+ {
226+ //WindowManager.SaveAllWindowPositions();
227+ }
228+ else if ( args . Modifiers == ( KeyModifiers . Control | KeyModifiers . Shift ) && args . Key == Keys . X )
229+ {
230+ //WindowManager.RestoreAllWindowPositions();
231+ }
232+ else if ( args . Modifiers == ( KeyModifiers . Control | KeyModifiers . Shift ) && args . Key == Keys . Z )
182233 {
183- LogSystem . Log ( "FreshTools.HotKeyPressed() - Super Tilde - " + args . Modifiers + "+" + args . Key + "" ) ;
234+ //WindowManager.UndoRestoreAllWindowPositions( );
184235 }
185236 else //unknown hot key pressed
186237 {
187238 //uncaught hotkey
188- LogSystem . Log ( "FreshTools.HotKeyPressed() - UnActioned - " + args . Modifiers + "+" + args . Key + "" ) ;
239+ LogSystem . Log ( "UnActioned - " + args . Modifiers + "+" + args . Key + "" ) ;
189240 }
190241 }
191242 catch ( Exception e )
0 commit comments