Skip to content

Commit

Permalink
Crashing fixes?
Browse files Browse the repository at this point in the history
  • Loading branch information
KimihikoAkayasaki committed Jan 7, 2024
1 parent 2a873c7 commit 284b9e3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
19 changes: 14 additions & 5 deletions Amethyst/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,17 @@ public App()
// Create an empty file for checking for crashes
try
{
Interfacing.CrashFile = new FileInfo(Path.Join(Interfacing.TemporaryFolder.Path, ".crash"));
if (Environment.GetCommandLineArgs().ElementAtOrDefault(1)?.StartsWith("amethyst-app:crash") ?? false)
Interfacing.CrashFile.Create(); // Create the file if not running as crash handler
if (!Interfacing.SuppressAllDomainExceptions &&
(string.IsNullOrEmpty(Environment.GetCommandLineArgs().ElementAtOrDefault(1)) ||
Environment.GetCommandLineArgs().ElementAtOrDefault(1) is "amethyst-app:"))
{
Interfacing.CrashFile =
new FileInfo(Path.Join(Interfacing.TemporaryFolder.Path, "Crash",
Guid.NewGuid().ToString().ToUpper()));

Interfacing.CrashFile.Directory?.Create(); // Create the directory too...
Interfacing.CrashFile.Create(); // Create the file if not running as slave
}
}
catch (Exception e)
{
Expand Down Expand Up @@ -515,7 +523,8 @@ protected override async void OnLaunched(LaunchActivatedEventArgs eventArgs)
new DirectoryInfo(Path.Join(pluginFolder, "Assets", "Strings"))
.CopyToFolder(outputFolder.Path);

pluginStringsFolders.Add(Path.Join(pluginFolder, "Assets", "Strings"), outputFolder.Path);
pluginStringsFolders.Add(Path.Join(pluginFolder, "Assets", "Strings"),
outputFolder.Path);
}

// Create a new localization config
Expand Down Expand Up @@ -566,7 +575,7 @@ await File.WriteAllTextAsync(Interfacing.GetAppDataFilePath("Localization.json")

Logger.Info("Starting the crash handler passing the app PID...");
await ($"amethyst-app:crash-watchdog?pid={Environment.ProcessId}&log={Logger.LogFilePath}" +
$"&crash={Path.Join(Interfacing.TemporaryFolder.Path, ".crash")}").ToUri().LaunchAsync();
$"&crash={Interfacing.CrashFile.FullName}").ToUri().LaunchAsync();

// Disable internal sounds
ElementSoundPlayer.State = ElementSoundPlayerState.Off;
Expand Down
4 changes: 3 additions & 1 deletion Amethyst/Classes/AppPlugins.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ public static void UpdateTrackingDevicesInterface()
var failingOverrideGuid = "";

foreach (var device in AppData.Settings.OverrideDevicesGuidMap
.Where(device => TrackingDevicesList[device].DeviceStatus != 0))
.Where(device =>
TrackingDevicesList.TryGetValue(device, out var deviceInternal) &&
deviceInternal.DeviceStatus != 0))
{
overrideStatusOk = false;
failingOverrideGuid = device;
Expand Down
13 changes: 10 additions & 3 deletions Amethyst/Classes/Interfacing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -776,9 +776,16 @@ public static async Task ExecuteAppRestart(bool handleExit = true, string parame
info.FileName = "explorer.exe";
}

// Exit without re-handling everything
Process.Start(info);
Environment.Exit(0);
try
{
// Exit without re-handling everything
Process.Start(info);
Environment.Exit(0);
}
catch (Exception e)
{
Logger.Fatal(e);
}
}

// Still here?
Expand Down

0 comments on commit 284b9e3

Please sign in to comment.