@@ -19,30 +19,56 @@ public class Program
1919
2020 public static Daemon . Daemon Background ;
2121 public static AppManager GUI ;
22+ public static IEnumerable < Process > ValidTopNotifyInstances ;
23+
24+ public static bool IsDaemonRunning => ValidTopNotifyInstances . Where ( ( p ) => {
25+ try
26+ {
27+ string commandLine ;
28+ ProcessCommandLine . Retrieve ( p , out commandLine , ProcessCommandLine . Parameter . CommandLine ) ;
29+ return ! commandLine . ToLower ( ) . Contains ( "--settings" ) ;
30+ }
31+ catch { }
32+ return false ;
33+ } ) . Any ( ) ;
34+
35+ public static bool IsGUIRunning => ValidTopNotifyInstances . Where ( ( p ) => {
36+ try
37+ {
38+ string commandLine ;
39+ ProcessCommandLine . Retrieve ( p , out commandLine , ProcessCommandLine . Parameter . CommandLine ) ;
40+ return commandLine . ToLower ( ) . Contains ( "--settings" ) ;
41+ }
42+ catch { }
43+ return false ;
44+ } ) . Any ( ) ;
2245
2346 [ STAThread ]
2447 public static void Main ( string [ ] args )
2548 {
49+ AppDomain . CurrentDomain . UnhandledException += ( object sender , UnhandledExceptionEventArgs e ) =>
50+ {
51+ NotificationTester . MessageBox ( "Something went wrong with TopNotify" , "Unfortunately, TopNotify has crashed. Details: " + e . ExceptionObject . ToString ( ) ) ;
52+ } ;
53+
2654 //By Default, The App Will Be Launched In Daemon Mode
2755 //Daemon Mode Is A Background Process That Handles Changing The Position Of Notifications
2856 //If The "--settings" Arg Is Used, Then The App Will Launch In Settings Mode
2957 //Settings Mode Shows A GUI That Can Be Used To Configure The App
3058 //These Mode Switches Ensure All Functions Of The App Use The Same Executable
3159
3260 //Find Other Instances Of TopNotify
33- var validTopNotifyInstances = Process . GetProcessesByName ( "TopNotify" ) . Where ( ( p ) => ! p . HasExited && p . Id != Process . GetCurrentProcess ( ) . Id ) ;
34-
35- var isGUIRunning = validTopNotifyInstances . Where ( ( p ) => {
36- string commandLine ;
37- ProcessCommandLine . Retrieve ( p , out commandLine , ProcessCommandLine . Parameter . CommandLine ) ;
38- return commandLine . ToLower ( ) . Contains ( "--settings" ) ;
39- } ) . Any ( ) ;
40-
41- var isDaemonRunning = validTopNotifyInstances . Where ( ( p ) => {
42- string commandLine ;
43- ProcessCommandLine . Retrieve ( p , out commandLine , ProcessCommandLine . Parameter . CommandLine ) ;
44- return ! commandLine . ToLower ( ) . Contains ( "--settings" ) ;
45- } ) . Any ( ) ;
61+ ValidTopNotifyInstances = Process . GetProcessesByName ( "TopNotify" ) . Where ( ( p ) => {
62+ try
63+ {
64+ return ! p . HasExited && p . Id != Process . GetCurrentProcess ( ) . Id ;
65+ }
66+ catch { }
67+ return false ;
68+ } ) ;
69+
70+ var isGUIRunning = IsGUIRunning ;
71+ var isDaemonRunning = IsDaemonRunning ;
4672
4773 #if ! GUI_DEBUG
4874 if ( ! args . Contains ( "--settings" ) && isDaemonRunning && ! isGUIRunning )
0 commit comments