22import * as NodeChildProcess from "node:child_process" ;
33import * as NodeFS from "node:fs" ;
44import * as NodePath from "node:path" ;
5+ import * as Config from "effect/Config" ;
56import * as Context from "effect/Context" ;
67import * as Effect from "effect/Effect" ;
78import * as Layer from "effect/Layer" ;
9+ import * as Option from "effect/Option" ;
810
911import * as Electron from "electron" ;
1012import * as HostProcess from "@t3tools/shared/HostProcess" ;
1113
1214import * as DesktopEarlyElectronStartup from "./DesktopEarlyElectronStartup.ts" ;
15+ import { trimmedString } from "./DesktopConfig.ts" ;
1316import { resolveDesktopAppBranding } from "./DesktopEnvironment.ts" ;
1417import { renderUrlHandlerDesktopEntry } from "./DesktopLinuxUrlHandler.ts" ;
1518import * as ElectronProtocol from "../electron/ElectronProtocol.ts" ;
@@ -49,11 +52,17 @@ export class DesktopPreReadyElectronOptions extends Context.Service<
4952 }
5053> ( ) ( "@t3tools/desktop/app/DesktopPreReadyPlatform/DesktopPreReadyElectronOptions" ) { }
5154
55+ const LinuxDesktopEntryConfig = Config . all ( {
56+ xdgDataHome : trimmedString ( "XDG_DATA_HOME" ) ,
57+ launcherPath : trimmedString ( "T3CODE_DESKTOP_LAUNCHER_PATH" ) ,
58+ appImagePath : trimmedString ( "APPIMAGE" ) ,
59+ } ) ;
60+
5261/** @public */
5362export const make = Effect . gen ( function * ( ) {
5463 const platform = yield * HostProcess . Platform ;
5564 const homeDirectory = yield * HostProcess . HomeDirectory ;
56- const env = yield * HostProcess . Environment ;
65+ const linuxDesktopEntryConfig = yield * LinuxDesktopEntryConfig ;
5766 return yield * Effect . sync ( ( ) : DesktopPreReadyElectronOptions [ "Service" ] => {
5867 const linuxPasswordStoreCommandLine =
5968 platform === "linux"
@@ -64,7 +73,7 @@ export const make = Effect.gen(function* () {
6473
6574 if ( linux !== null ) {
6675 DesktopEarlyElectronStartup . restoreEarlyLinuxDeviceScaleFactor ( {
67- env,
76+ env : process . env ,
6877 homeDirectory,
6978 joinPath : NodePath . posix . join ,
7079 commandLine : Electron . app . commandLine ,
@@ -78,7 +87,9 @@ export const make = Effect.gen(function* () {
7887 // have removed the executable referenced by the previous launch's entry.
7988 try {
8089 const applicationsDir = NodePath . posix . join (
81- env . XDG_DATA_HOME ?. trim ( ) || NodePath . posix . join ( homeDirectory , ".local" , "share" ) ,
90+ Option . getOrElse ( linuxDesktopEntryConfig . xdgDataHome , ( ) =>
91+ NodePath . posix . join ( homeDirectory , ".local" , "share" ) ,
92+ ) ,
8293 "applications" ,
8394 ) ;
8495 NodeFS . mkdirSync ( applicationsDir , { recursive : true } ) ;
@@ -110,7 +121,12 @@ export const make = Effect.gen(function* () {
110121 appVersion : Electron . app . getVersion ( ) ,
111122 } ) . displayName ,
112123 execTarget :
113- env . T3CODE_DESKTOP_LAUNCHER_PATH ?. trim ( ) || env . APPIMAGE ?. trim ( ) || process . execPath ,
124+ Option . getOrUndefined (
125+ Option . orElse (
126+ linuxDesktopEntryConfig . launcherPath ,
127+ ( ) => linuxDesktopEntryConfig . appImagePath ,
128+ ) ,
129+ ) ?? process . execPath ,
114130 scheme : ElectronProtocol . getDesktopScheme ( linux . isDevelopment ) ,
115131 ...( iconPath === undefined ? { } : { iconPath } ) ,
116132 } ) ,
@@ -124,7 +140,7 @@ export const make = Effect.gen(function* () {
124140 }
125141 // Chromium keeps only the last --disable-features value, so pass the merged list.
126142 const disableFeatures = DesktopEarlyElectronStartup . resolveLinuxDisableFeaturesSwitch ( {
127- env,
143+ env : process . env ,
128144 ozonePlatform : readCommandLineSwitchValue ( Electron . app . commandLine , "ozone-platform" ) ,
129145 enableFeatures : readCommandLineSwitchValue ( Electron . app . commandLine , "enable-features" ) ,
130146 disableFeatures : readCommandLineSwitchValue ( Electron . app . commandLine , "disable-features" ) ,
0 commit comments