Add farmcontrolinstaller logo and enhance Windows path handling
All checks were successful
farmcontrol/farmcontrol-ui/pipeline/head This commit looks good

- Introduced a new logo file for the farmcontrol installer.
- Updated the `patch-electrobun-src.mjs` script to improve the resolution of the native wrapper path, ensuring compatibility across different execution contexts.
- Refactored the `index.js` file to utilize a new function for setting the working directory on Windows, enhancing application behavior.
- Added a new module in `windows-app-paths.js` to manage Windows-specific directory resolution and ensure the correct working directory is set before launching the application.
This commit is contained in:
Tom Butcher 2026-08-02 23:32:27 +01:00
parent 4cf4f5e27f
commit ee35e12959
4 changed files with 84 additions and 16 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 392 KiB

View File

@ -283,23 +283,56 @@ function patchNativeWrapperPath(nativeTsPath) {
} }
let source = readFileSync(nativeTsPath, 'utf8') let source = readFileSync(nativeTsPath, 'utf8')
const needle =
'const nativeWrapperPath = join(process.cwd(), `libNativeWrapper.${suffix}`);'
const replacement =
'const nativeWrapperPath = join(dirname(process.execPath), `libNativeWrapper.${suffix}`);'
if (!source.includes(needle)) { if (source.includes('function resolveNativeWrapperPath()')) {
return return
} }
if (!source.includes('dirname')) { if (!source.includes('existsSync')) {
if (source.includes('import { dirname, join } from "path";')) {
source = source.replace(
'import { dirname, join } from "path";',
'import { existsSync } from "fs";\nimport { dirname, join } from "path";'
)
} else {
source = source.replace(
'import { join } from "path";',
'import { existsSync } from "fs";\nimport { dirname, join } from "path";'
)
}
} else if (!source.includes('dirname')) {
source = source.replace( source = source.replace(
'import { join } from "path";', 'import { join } from "path";',
'import { dirname, join } from "path";' 'import { dirname, join } from "path";'
) )
} }
source = source.replace(needle, replacement) const helper = `
function resolveNativeWrapperPath() {
\tconst fileName = \`libNativeWrapper.\${suffix}\`;
\tconst candidates = [
\t\tjoin(dirname(process.execPath), fileName),
\t\tjoin(process.cwd(), fileName),
\t];
\tfor (const candidate of candidates) {
\t\tif (existsSync(candidate)) {
\t\t\treturn candidate;
\t\t}
\t}
\treturn candidates[0]!;
}
`
source = source.replace(
'export const native = (() => {',
`${helper}\nexport const native = (() => {`
)
source = source.replace(
/const nativeWrapperPath = join\((?:dirname\(process\.execPath\)|process\.cwd\(\)), `libNativeWrapper\.\$\{suffix\}`\);/,
'const nativeWrapperPath = resolveNativeWrapperPath();'
)
writeFileSync(nativeTsPath, source) writeFileSync(nativeTsPath, source)
} }

View File

@ -1,18 +1,11 @@
import { chdirSync } from 'node:fs' import { ensureWindowsWorkingDirectory } from '../desktop/windows-app-paths.js'
import { dirname } from 'node:path'
import { import {
captureLaunchUrl, captureLaunchUrl,
closeSingleInstanceServer, closeSingleInstanceServer,
ensureSingleInstanceLock ensureSingleInstanceLock
} from '../desktop/single-instance.js' } from '../desktop/single-instance.js'
if (process.platform === 'win32') { ensureWindowsWorkingDirectory()
try {
chdirSync(dirname(process.execPath))
} catch {
// Best effort; some launchers may not allow changing directory.
}
}
const launchUrl = captureLaunchUrl() const launchUrl = captureLaunchUrl()
const gotSingleInstanceLock = await ensureSingleInstanceLock({ launchUrl }) const gotSingleInstanceLock = await ensureSingleInstanceLock({ launchUrl })

View File

@ -0,0 +1,42 @@
import { chdirSync, existsSync } from 'node:fs'
import { dirname, join } from 'node:path'
const NATIVE_WRAPPER_DLL = 'libNativeWrapper.dll'
export function resolveWindowsBinDir() {
const candidates = [
dirname(process.execPath),
process.cwd(),
join(dirname(process.execPath), 'bin'),
join(process.cwd(), 'bin')
]
for (const candidate of candidates) {
if (
existsSync(join(candidate, 'launcher.exe')) ||
existsSync(join(candidate, NATIVE_WRAPPER_DLL))
) {
return candidate
}
}
return dirname(process.execPath)
}
export function ensureWindowsWorkingDirectory() {
if (process.platform !== 'win32') {
return
}
const binDir = resolveWindowsBinDir()
const wrapperInCwd = existsSync(join(process.cwd(), NATIVE_WRAPPER_DLL))
const wrapperInBinDir = existsSync(join(binDir, NATIVE_WRAPPER_DLL))
if (!wrapperInCwd && wrapperInBinDir) {
try {
chdirSync(binDir)
} catch {
// Ignore if we cannot change directory.
}
}
}