3636using Newtonsoft . Json ;
3737using Newtonsoft . Json . Linq ;
3838using LaunchActivatedEventArgs = Microsoft . UI . Xaml . LaunchActivatedEventArgs ;
39- using System . Text ;
40-
41- // To learn more about WinUI, the WinUI project structure,
42- // and more about our project templates, see: http://aka.ms/winui-project-info.
4339
4440namespace Amethyst ;
4541
@@ -61,6 +57,7 @@ public partial class App : Application
6157 public App ( )
6258 {
6359 InitializeComponent ( ) ;
60+ AsyncUtils . RunSync ( PathsHandler . Setup ) ;
6461
6562 // Listen for and log all uncaught second-chance exceptions : XamlApp
6663 UnhandledException += ( _ , e ) =>
@@ -296,7 +293,7 @@ protected override async void OnLaunched(LaunchActivatedEventArgs eventArgs)
296293 ElementSoundPlayer . State = ElementSoundPlayerState . Off ;
297294
298295 Logger . Info ( "Creating a new CrashWindow view..." ) ;
299- _crashWindow = new CrashWindow ( ) ; // Create a new window
296+ _crashWindow = new CrashWindow ( args ) ; // Create a new window
300297
301298 Logger . Info ( $ "Activating { _crashWindow . GetType ( ) } ...") ;
302299 _crashWindow . Activate ( ) ; // Activate the main window
@@ -328,8 +325,13 @@ protected override async void OnLaunched(LaunchActivatedEventArgs eventArgs)
328325 }
329326
330327 // Check if activated via uri
331- var activationUri = ( AppInstance . GetCurrent ( ) . GetActivatedEventArgs ( ) . Data as
332- ProtocolActivatedEventArgs ) ? . Uri ;
328+ var activationUri = PathsHandler . IsAmethystPackaged
329+ ? ( AppInstance . GetCurrent ( ) . GetActivatedEventArgs ( ) . Data as
330+ ProtocolActivatedEventArgs ) ? . Uri
331+ : args . Length > 1 && args [ 1 ] . StartsWith ( "amethyst-app:" ) &&
332+ Uri . TryCreate ( args [ 1 ] , UriKind . RelativeOrAbsolute , out var au )
333+ ? au
334+ : null ;
333335
334336 // Check if there's any launch arguments
335337 if ( activationUri is not null && activationUri . Segments . Length > 0 )
@@ -683,7 +685,7 @@ await Interfacing.ExecuteAppRestart(admin: true, filenameOverride: "powershell.e
683685 if ( ! needToCreateNew )
684686 {
685687 Logger . Fatal ( new AbandonedMutexException ( "Startup failed! The app is already running." ) ) ;
686- await "amethyst-app:crash-already-running" . ToUri ( ) . LaunchAsync ( ) ;
688+ await "amethyst-app:crash-already-running" . Launch ( ) ;
687689
688690 await Task . Delay ( 3000 ) ;
689691 Environment . Exit ( 0 ) ; // Exit peacefully
@@ -692,15 +694,15 @@ await Interfacing.ExecuteAppRestart(admin: true, filenameOverride: "powershell.e
692694 catch ( Exception e )
693695 {
694696 Logger . Fatal ( new AbandonedMutexException ( $ "Startup failed! Mutex creation error: { e . Message } ") ) ;
695- await "amethyst-app:crash-already-running" . ToUri ( ) . LaunchAsync ( ) ;
697+ await "amethyst-app:crash-already-running" . Launch ( ) ;
696698
697699 await Task . Delay ( 3000 ) ;
698700 Environment . Exit ( 0 ) ; // Exit peacefully
699701 }
700702
701703 Logger . Info ( "Starting the crash handler passing the app PID..." ) ;
702704 await ( $ "amethyst-app:crash-watchdog?pid={ Environment . ProcessId } &log={ Logger . LogFilePath } " +
703- $ "&crash={ Interfacing . CrashFile . FullName } ") . ToUri ( ) . LaunchAsync ( ) ;
705+ $ "&crash={ Interfacing . CrashFile . FullName } ") . Launch ( ) ;
704706
705707 // Disable internal sounds
706708 ElementSoundPlayer . State = ElementSoundPlayerState . Off ;
@@ -884,9 +886,9 @@ await Interfacing.ExecuteAppRestart(admin: true, filenameOverride: "powershell.e
884886 // Update 1.2.13.0: reset configuration
885887 try
886888 {
887- if ( ApplicationData . Current . LocalSettings . Values [ "SetupFinished" ] as bool ? ?? false )
889+ if ( PathsHandler . LocalSettings [ "SetupFinished" ] as bool ? ?? false )
888890 {
889- ApplicationData . Current . LocalSettings . Values . Remove ( "SetupFinished" ) ;
891+ PathsHandler . LocalSettings . Remove ( "SetupFinished" ) ;
890892 AppData . Settings = new AppSettings ( ) ; // Reset application settings
891893 AppData . Settings . SaveSettings ( ) ; // Save empty settings to file
892894
@@ -896,7 +898,7 @@ await Interfacing.ExecuteAppRestart(admin: true, filenameOverride: "powershell.e
896898 "a critical update, so you'll need to reconfigure it." ) ;
897899
898900 // If there's an OVR driver folder, try to delete it if possible
899- await ( await ApplicationData . Current . LocalFolder . GetFolderAsync ( "Amethyst" ) ) ? . DeleteAsync ( ) ;
901+ await ( await PathsHandler . LocalFolder . GetFolderAsync ( "Amethyst" ) ) ? . DeleteAsync ( ) ;
900902 }
901903 }
902904 catch ( Exception ex )
0 commit comments