11import { Command , FetchHttpClient , Path , Url } from '@effect/platform' ;
22import * as NodeContext from '@effect/platform-node/NodeContext' ;
33import * as NodeRuntime from '@effect/platform-node/NodeRuntime' ;
4- import { Config , Console , Effect , pipe , Runtime } from 'effect' ;
4+ import { Config , Console , Effect , pipe , Runtime , String } from 'effect' ;
55import { app , BrowserWindow , dialog , Dialog , globalShortcut , ipcMain , protocol , shell } from 'electron' ;
66import { autoUpdater } from 'electron-updater' ;
7- import child_process from 'node:child_process' ;
87import os from 'node:os' ;
98import { Agent } from 'undici' ;
109import { CustomUpdateProvider , UpdateOptions } from './update' ;
@@ -99,19 +98,6 @@ const createWindow = Effect.gen(function* () {
9998 }
10099} ) ;
101100
102- // Only 'child_process.execFile' is supported for executing binaries inside ASAR archives
103- // https://www.electronjs.org/docs/latest/tutorial/asar-archives#executing-binaries-inside-asar-archive
104- const execFile = ( file : string , args ?: string [ ] , options ?: child_process . ExecFileOptions ) =>
105- Effect . async < void , child_process . ExecFileException > ( ( resume ) => {
106- child_process . execFile ( file , args , options , ( error , stdout , stderr ) => {
107- Effect . gen ( function * ( ) {
108- if ( stdout ) console . log ( stdout ) ;
109- if ( stderr ) console . error ( stderr ) ;
110- if ( error ) yield * Effect . fail ( error ) ;
111- } ) . pipe ( resume ) ;
112- } ) ;
113- } ) ;
114-
115101const server = pipe (
116102 Effect . gen ( function * ( ) {
117103 const path = yield * Path . Path ;
@@ -122,16 +108,22 @@ const server = pipe(
122108 Effect . flatMap ( path . fromFileUrl ) ,
123109 ) ;
124110
125- yield * execFile ( path . join ( dist , 'server' ) , undefined , {
126- env : {
111+ yield * pipe (
112+ path . join ( dist , 'server' ) ,
113+ String . replaceAll ( 'app.asar' , 'app.asar.unpacked' ) ,
114+ Command . make ,
115+ Command . env ( {
127116 // TODO: we probably shouldn't encrypt local database
128117 DB_ENCRYPTION_KEY : 'secret' ,
129118 DB_MODE : 'local' ,
130119 DB_NAME : 'state' ,
131120 DB_PATH : app . getPath ( 'userData' ) ,
132121 HMAC_SECRET : 'secret' ,
133- } ,
134- } ) ;
122+ } ) ,
123+ Command . stdout ( 'inherit' ) ,
124+ Command . stderr ( 'inherit' ) ,
125+ Command . exitCode ,
126+ ) ;
135127
136128 yield * Effect . interrupt ;
137129 } ) ,
@@ -266,7 +258,9 @@ const cli = pipe(
266258 Effect . flatMap ( path . fromFileUrl ) ,
267259 ) ;
268260
269- yield * execFile ( path . join ( dist , 'cli' ) , args ) ;
261+ const bin = pipe ( path . join ( dist , 'cli' ) , String . replaceAll ( 'app.asar' , 'app.asar.unpacked' ) ) ;
262+
263+ yield * pipe ( Command . make ( bin , ...args ) , Command . stdout ( 'inherit' ) , Command . stderr ( 'inherit' ) , Command . exitCode ) ;
270264
271265 app . quit ( ) ;
272266 } ) ,
0 commit comments