@@ -397,7 +397,7 @@ public string TrackingSystemName
397397 }
398398 }
399399
400- public void OnLoad ( )
400+ public Task OnLoad ( )
401401 {
402402 VrInput ??= new SteamEvrInput ( Host , this ) ;
403403 VrInputStatic = VrInput ;
@@ -411,21 +411,23 @@ public void OnLoad()
411411
412412 IsStandableSupportEnabled = Host ? . PluginSettings
413413 . GetSetting ( "StandableSupport" , false ) ?? false ;
414+
415+ return Task . CompletedTask ;
414416 }
415417
416- public int Initialize ( )
418+ public async Task Initialize ( )
417419 {
418420 // Reset the status
419421 ServiceStatus = 0 ;
420422
421423 // Check if Amethyst is running as admin
422424 // Check if OpenVR is running as admin
423425 // Initialize OpenVR if we're ready to go
424- if ( VrHelper . IsCurrentProcessElevated ( ) !=
425- VrHelper . IsOpenVrElevated ( ) || ! OpenVrStartup ( ) )
426+ if ( VrHelper . IsCurrentProcessElevated ( ) != VrHelper . IsOpenVrElevated ( ) ||
427+ ! await Task . Run ( OpenVrStartup ) ) // Wait for the system to initialize
426428 {
427429 ServiceStatus = 1 ;
428- return 1 ;
430+ return ;
429431 }
430432
431433 // Install the manifest
@@ -435,14 +437,10 @@ public int Initialize()
435437 UpdateBindingTexts ( ) ;
436438
437439 // Startup input actions
438- var serviceStatus = 0 ;
439- if ( ! EvrActionsStartup ( ) ) serviceStatus = 2 ;
440+ EvrActionsStartup ( ) ;
440441
441442 // Connect to the server driver
442- K2ServerDriverRefresh ( ) ;
443-
444- // Return the binding error if the driver is fine
445- return ServiceStatus == 0 ? serviceStatus : ServiceStatus ;
443+ await K2ServerDriverRefresh ( ) ;
446444 }
447445
448446 public void Heartbeat ( )
@@ -487,7 +485,7 @@ public void Heartbeat()
487485 }
488486 }
489487
490- public void Shutdown ( )
488+ public Task Shutdown ( )
491489 {
492490 lock ( InitLock )
493491 lock ( Host . UpdateThreadLock )
@@ -500,6 +498,8 @@ public void Shutdown()
500498 // K2ServerDriverRefresh(); // TODO
501499 Host ? . RefreshStatusInterface ( ) ;
502500 }
501+
502+ return Task . CompletedTask ;
503503 }
504504
505505 public void DisplayToast ( ( string Title , string Text ) message )
@@ -764,7 +764,7 @@ public Task ProcessKeyInput(IKeyInputAction action, object data, TrackerType? re
764764 UpdateBindingTexts ( ) ;
765765
766766 // Refresh the driver, just in case
767- K2ServerDriverRefresh ( ) ;
767+ await K2ServerDriverRefresh ( ) ;
768768
769769 // Driver client sanity check: return empty or null if not valid
770770 if ( ! Initialized || OpenVR . System is null || DriverService is null ||
@@ -936,9 +936,9 @@ private async Task<int> CheckK2ServerStatusAsync()
936936 */
937937 }
938938
939- private void K2ServerDriverRefresh ( )
939+ private async Task K2ServerDriverRefresh ( )
940940 {
941- ServiceStatus = CheckK2ServerStatusAsync ( ) . Result ;
941+ ServiceStatus = await CheckK2ServerStatusAsync ( ) ;
942942
943943 // Request a quick status refresh
944944 Host ? . RefreshStatusInterface ( ) ;
0 commit comments