55 using System ;
66 using System . ComponentModel ;
77 using System . IO ;
8+ using System . Runtime . InteropServices ;
89 using System . Threading . Tasks ;
910
1011 /// <summary>
@@ -42,6 +43,11 @@ protected override Task StartCore()
4243 var electrondir = Path . Combine ( dir . FullName , ".electron" ) ;
4344 startCmd = Path . Combine ( electrondir , "node_modules" , "electron" , "dist" , "electron" ) ;
4445
46+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . OSX ) )
47+ {
48+ startCmd = Path . Combine ( electrondir , "node_modules" , "electron" , "dist" , "Electron.app" , "Contents" , "MacOS" , "Electron" ) ;
49+ }
50+
4551 args = $ "main.js -unpackeddotnet --trace-warnings -electronforcedport={ this . socketPort : D} " + this . extraArguments ;
4652 workingDir = electrondir ;
4753 }
@@ -68,22 +74,40 @@ protected override Task StopCore()
6874
6975 private async Task StartInternal ( string startCmd , string args , string directoriy )
7076 {
71- await Task . Delay ( 10 ) . ConfigureAwait ( false ) ;
77+ try
78+ {
79+ await Task . Delay ( 10 ) . ConfigureAwait ( false ) ;
7280
73- this . process = new ProcessRunner ( "ElectronRunner" ) ;
74- this . process . ProcessExited += this . Process_Exited ;
75- this . process . Run ( startCmd , args , directoriy ) ;
81+ Console . Error . WriteLine ( "[StartInternal]: startCmd: {0}" , startCmd ) ;
82+ Console . Error . WriteLine ( "[StartInternal]: args: {0}" , args ) ;
7683
77- await Task . Delay ( 500 ) . ConfigureAwait ( false ) ;
84+ this . process = new ProcessRunner ( "ElectronRunner" ) ;
85+ this . process . ProcessExited += this . Process_Exited ;
86+ this . process . Run ( startCmd , args , directoriy ) ;
7887
79- if ( ! this . process . IsRunning )
80- {
81- Task . Run ( ( ) => this . TransitionState ( LifetimeState . Stopped ) ) ;
88+ await Task . Delay ( 500 ) . ConfigureAwait ( false ) ;
8289
83- throw new Exception ( "Failed to launch the Electron process." ) ;
84- }
90+ Console . Error . WriteLine ( "[StartInternal]: after run:" ) ;
91+
92+ if ( ! this . process . IsRunning )
93+ {
94+ Console . Error . WriteLine ( "[StartInternal]: Process is not running: " + this . process . StandardError ) ;
95+ Console . Error . WriteLine ( "[StartInternal]: Process is not running: " + this . process . StandardOutput ) ;
8596
86- this . TransitionState ( LifetimeState . Ready ) ;
97+ Task . Run ( ( ) => this . TransitionState ( LifetimeState . Stopped ) ) ;
98+
99+ throw new Exception ( "Failed to launch the Electron process." ) ;
100+ }
101+
102+ this . TransitionState ( LifetimeState . Ready ) ;
103+ }
104+ catch ( Exception ex )
105+ {
106+ Console . Error . WriteLine ( "[StartInternal]: Exception: " + this . process ? . StandardError ) ;
107+ Console . Error . WriteLine ( "[StartInternal]: Exception: " + this . process ? . StandardOutput ) ;
108+ Console . Error . WriteLine ( "[StartInternal]: Exception: " + ex ) ;
109+ throw ;
110+ }
87111 }
88112
89113 private void Process_Exited ( object sender , EventArgs e )
0 commit comments