Skip to content

Commit 251421c

Browse files
Fix: Add more error handling
Co-Authored-By: SamsidParty <[email protected]>
1 parent 897ed0f commit 251421c

File tree

6 files changed

+40
-14
lines changed

6 files changed

+40
-14
lines changed

Docs/Screenshot2.pdn

-770 KB
Binary file not shown.

Docs/Screenshot2.png

-249 KB
Loading

Docs/Screenshot3.pdn

5.11 KB
Binary file not shown.

Docs/Screenshot3.png

-60 KB
Loading

TopNotify/MSIX/AppxManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<!--Package created by MSIX Packaging Tool version: 1.2023.807.0-->
44
<!--Use CN=68C2D20A-96CA-43CC-A323-A549C2786CDA For Prod-->
55
<!--Use CN=SamsidParty For Beta-->
6-
<Identity Name="55968SamsidGameStudios.TopNotify" Publisher="CN=68C2D20A-96CA-43CC-A323-A549C2786CDA" Version="3.0.0.0" ProcessorArchitecture="x64" />
6+
<Identity Name="55968SamsidGameStudios.TopNotify" Publisher="CN=68C2D20A-96CA-43CC-A323-A549C2786CDA" Version="3.0.1.0" ProcessorArchitecture="x64" />
77
<Properties>
88
<DisplayName>TopNotify</DisplayName>
99
<PublisherDisplayName>SamsidParty</PublisherDisplayName>

TopNotify/Program.cs

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)