55 using System ;
66 using System . ComponentModel ;
77 using System . IO ;
8+ using System . Linq ;
89 using System . Runtime . InteropServices ;
910 using System . Threading . Tasks ;
11+ using ElectronNET . Common ;
12+ using ElectronNET . Runtime . Data ;
1013
1114 /// <summary>
1215 /// Launches and manages the Electron app process.
@@ -33,14 +36,40 @@ public ElectronProcessActive(bool isUnpackaged, string electronBinaryName, strin
3336 this . socketPort = socketPort ;
3437 }
3538
36- protected override Task StartCore ( )
39+ protected override async Task StartCore ( )
3740 {
3841 var dir = new DirectoryInfo ( AppDomain . CurrentDomain . BaseDirectory ) ;
3942 string startCmd , args , workingDir ;
4043
4144 if ( this . isUnpackaged )
4245 {
4346 var electrondir = Path . Combine ( dir . FullName , ".electron" ) ;
47+
48+ ProcessRunner chmodRunner = null ;
49+
50+ try
51+ {
52+ if ( ! RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
53+ {
54+ var distFolder = Path . Combine ( electrondir , "node_modules" , "electron" , "dist" ) ;
55+
56+ chmodRunner = new ProcessRunner ( "ElectronRunner-Chmod" ) ;
57+ chmodRunner . Run ( "chmod" , "-R +x " + distFolder , electrondir ) ;
58+ await chmodRunner . WaitForExitAsync ( ) . ConfigureAwait ( true ) ;
59+
60+ if ( chmodRunner . LastExitCode != 0 )
61+ {
62+ throw new Exception ( "Failed to set executable permissions on Electron dist folder." ) ;
63+ }
64+ }
65+ }
66+ catch ( Exception ex )
67+ {
68+ Console . Error . WriteLine ( "[StartCore]: Exception: " + chmodRunner ? . StandardError ) ;
69+ Console . Error . WriteLine ( "[StartCore]: Exception: " + chmodRunner ? . StandardOutput ) ;
70+ Console . Error . WriteLine ( "[StartCore]: Exception: " + ex ) ;
71+ }
72+
4473 startCmd = Path . Combine ( electrondir , "node_modules" , "electron" , "dist" , "electron" ) ;
4574
4675 if ( RuntimeInformation . IsOSPlatform ( OSPlatform . OSX ) )
@@ -53,7 +82,7 @@ protected override Task StartCore()
5382 }
5483 else
5584 {
56- dir = dir . Parent ? . Parent ;
85+ dir = dir . Parent ! . Parent ! ;
5786 startCmd = Path . Combine ( dir . FullName , this . electronBinaryName ) ;
5887 args = $ "-dotnetpacked -electronforcedport={ this . socketPort : D} " + this . extraArguments ;
5988 workingDir = dir . FullName ;
0 commit comments