fix(desktop): resolve the development runtime directory from the build target
The unpackaged shell derived the primary-runtime directory from process.arch, while preparePrimaryRuntime() resolves the target through resolveDesktopBuildTarget(), which fixes Windows to x64. On a Windows ARM64 host the shell looked under targets/win-arm64 while the payload was under targets/win-x64, and the missing office-skills/scripts/check_office.py became a fatal startup dialog. The launcher now resolves that directory through the same resolver and passes it to the shell as DSH_DESKTOP_PRIMARY_RUNTIME_DIR.
This commit is contained in:
1 parent
35fe8e0966
commit
3515c48a37
10 files changed
+57
-6
No files matched your search
@@ -2,5 +2,5 @@
|
||||
# side as of the last confirmed-consistent state. Both languages carry equal authority;
|
||||
# after editing either side, bring the other along and re-record with:
|
||||
# pnpm run verify-translation-pairing --write apps/desktop/README.md
|
||||
README.md: 6c9a6a8784732e6fa1369df5632391b789786b22
|
||||
README.zh.md: a0f2184d911eeab46902670cf992b6847e2bca31
|
||||
README.md: 860867eef3ae1da8c89d8292f00afa9ad2a20872
|
||||
README.zh.md: ac9a4ddbfff1ad96950fbda6e14ea2632480ea03
|
||||
@@ -342,7 +342,7 @@ The downloaded bytes are inert, and the installation call is recorded rather tha
|
||||
|
||||
## Low-level development overrides
|
||||
|
||||
An unpackaged Electron process uses `.desktop-build/development/project` under its application directory as its development project. `DSH_DESKTOP_PNPM_ENTRY` and `DSH_DESKTOP_DSH_DIR` select explicit runtime resources. Packaged applications ignore these variables, resolve signed resources from `process.resourcesPath`, and use the managed Desktop profile.
|
||||
An unpackaged Electron process uses `.desktop-build/development/project` under its application directory as its development project. `DSH_DESKTOP_PNPM_ENTRY`, `DSH_DESKTOP_DSH_DIR`, and `DSH_DESKTOP_PRIMARY_RUNTIME_DIR` select explicit runtime resources. The development launcher sets `DSH_DESKTOP_PRIMARY_RUNTIME_DIR` to the primary-runtime directory of the target it prepared, because the Windows target is always x64. Packaged applications ignore these variables, resolve signed resources from `process.resourcesPath`, and use the managed Desktop profile.
|
||||
|
||||
## Known limitations
|
||||
|
||||
|
||||
@@ -342,7 +342,7 @@ node apps/desktop/node_modules/pnpm/bin/pnpm.mjs --dir apps/desktop run test:upd
|
||||
|
||||
## 底层开发覆盖项
|
||||
|
||||
未打包的 Electron 进程使用应用目录下的 `.desktop-build/development/project` 作为开发项目。`DSH_DESKTOP_PNPM_ENTRY` 和 `DSH_DESKTOP_DSH_DIR` 用于选择明确的运行时资源。打包应用会忽略这些变量,从 `process.resourcesPath` 解析签名资源,并使用受管 Desktop profile。
|
||||
未打包的 Electron 进程使用应用目录下的 `.desktop-build/development/project` 作为开发项目。`DSH_DESKTOP_PNPM_ENTRY`、`DSH_DESKTOP_DSH_DIR` 和 `DSH_DESKTOP_PRIMARY_RUNTIME_DIR` 用于选择明确的运行时资源。开发启动器将 `DSH_DESKTOP_PRIMARY_RUNTIME_DIR` 设置为其已准备目标的 primary-runtime 目录,因为 Windows 目标固定为 x64。打包应用会忽略这些变量,从 `process.resourcesPath` 解析签名资源,并使用受管 Desktop profile。
|
||||
|
||||
## 已知限制
|
||||
|
||||
|
||||
@@ -47,3 +47,16 @@ export function resolveDesktopTargetBuildPaths(
|
||||
hostPlatform?: NodeJS.Platform,
|
||||
hostArch?: string,
|
||||
): DesktopTargetBuildPaths
|
||||
|
||||
/**
|
||||
* Resolve the primary-runtime directory an unpackaged development launch uses.
|
||||
* @param env - Packaging environment.
|
||||
* @param hostPlatform - Build-host platform used when no target override exists.
|
||||
* @param hostArch - Build-host architecture used when no target override exists.
|
||||
* @returns Primary-runtime directory prepared for the selected target.
|
||||
*/
|
||||
export function developmentRuntimeDirectory(
|
||||
env?: NodeJS.ProcessEnv,
|
||||
hostPlatform?: NodeJS.Platform,
|
||||
hostArch?: string,
|
||||
): string
|
||||
@@ -69,3 +69,20 @@ export function resolveDesktopTargetBuildPaths(
|
||||
) {
|
||||
return desktopTargetBuildPaths(resolveDesktopBuildTarget(env, hostPlatform, hostArch))
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the primary-runtime directory an unpackaged development launch uses.
|
||||
* The build target fixes Windows to x64, so the shell cannot derive this directory from
|
||||
* the architecture of the process that launched it.
|
||||
* @param {NodeJS.ProcessEnv} env - Packaging environment.
|
||||
* @param {NodeJS.Platform} hostPlatform - Build-host platform used when no target override exists.
|
||||
* @param {string} hostArch - Build-host architecture used when no target override exists.
|
||||
* @returns {string} Primary-runtime directory prepared for the selected target.
|
||||
*/
|
||||
export function developmentRuntimeDirectory(
|
||||
env = process.env,
|
||||
hostPlatform = process.platform,
|
||||
hostArch = process.arch,
|
||||
) {
|
||||
return join(resolveDesktopTargetBuildPaths(env, hostPlatform, hostArch).runtime, 'primary-runtime')
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import { join, resolve } from 'node:path'
|
||||
import { parseArgs } from 'node:util'
|
||||
import { DESKTOP_HOST_PROTOCOL_VERSION } from '../src/host-protocol.ts'
|
||||
import type { DesktopRelease } from '../src/release.ts'
|
||||
import { developmentRuntimeDirectory } from './desktop-build-paths.mjs'
|
||||
import { prepareDevelopmentProject } from './development-project.ts'
|
||||
import { preparePrimaryRuntime } from './prepare-primary-runtime.ts'
|
||||
|
||||
@@ -66,6 +67,7 @@ async function launchElectron(): Promise<void> {
|
||||
const environment: NodeJS.ProcessEnv = {
|
||||
...process.env,
|
||||
DSH_HOME: home,
|
||||
DSH_DESKTOP_PRIMARY_RUNTIME_DIR: developmentRuntimeDirectory(),
|
||||
DSH_DESKTOP_HOST_INSPECT_PORT: String(hostPort),
|
||||
DSH_DESKTOP_OPEN_DEVTOOLS: process.env.DSH_DESKTOP_OPEN_DEVTOOLS ?? '1',
|
||||
ELECTRON_ENABLE_LOGGING: process.env.ELECTRON_ENABLE_LOGGING ?? '1',
|
||||
|
||||
@@ -56,7 +56,7 @@ try {
|
||||
...(interactive ? ['--interactive'] : [])], {
|
||||
cwd: root, env: { ...environment, DSH_HOME: join(root, 'home'), USERPROFILE: root, HOME: root,
|
||||
TEMP: root, TMP: root, TMPDIR: root, DSH_WORKSPACE_UPDATE_ROOT: root, DSH_WORKSPACE_UPDATE_TOKEN: randomUUID(),
|
||||
DSH_DESKTOP_OPEN_DEVTOOLS: '0' },
|
||||
DSH_DESKTOP_PRIMARY_RUNTIME_DIR: join(application, 'runtime', 'primary-runtime'), DSH_DESKTOP_OPEN_DEVTOOLS: '0' },
|
||||
// Hiding the GUI process suppresses its first window and can suspend renderer frame callbacks.
|
||||
stdio: 'inherit', windowsHide: false,
|
||||
})
|
||||
|
||||
@@ -98,6 +98,14 @@ function runtimeResources(): RuntimeResources {
|
||||
return { node, nodeBin, pnpm, dsh }
|
||||
}
|
||||
|
||||
function developmentPrimaryRuntime(): string {
|
||||
const directory = process.env.DSH_DESKTOP_PRIMARY_RUNTIME_DIR
|
||||
if (directory === undefined || directory === '') {
|
||||
throw new Error('dsh desktop: DSH_DESKTOP_PRIMARY_RUNTIME_DIR is required for an unpackaged launch')
|
||||
}
|
||||
return directory
|
||||
}
|
||||
|
||||
function developmentHostInspectPort(enabled: boolean): number | undefined {
|
||||
const configured = process.env.DSH_DESKTOP_HOST_INSPECT_PORT
|
||||
if (!enabled || configured === undefined || configured === '') return undefined
|
||||
@@ -261,7 +269,7 @@ async function main(): Promise<void> {
|
||||
const hostInspectPort = developmentHostInspectPort(development)
|
||||
const host = new DesktopHostProcess(resources.node, resources.dsh, activeProject,
|
||||
hostInspectPort, process.env, onFailure,
|
||||
development ? join(app.getAppPath(), '.desktop-build', 'targets', `${process.platform === 'darwin' ? 'mac' : 'win'}-${process.arch}`, 'runtime', 'primary-runtime')
|
||||
development ? developmentPrimaryRuntime()
|
||||
: join(process.resourcesPath, 'runtime', 'primary-runtime'),
|
||||
resources)
|
||||
return {
|
||||
|
||||
@@ -2,6 +2,7 @@ import { join, sep } from 'node:path'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
desktopTargetBuildPaths,
|
||||
developmentRuntimeDirectory,
|
||||
resolveDesktopBuildTarget,
|
||||
} from '../scripts/desktop-build-paths.mjs'
|
||||
|
||||
@@ -38,6 +39,15 @@ describe('desktop build paths', () => {
|
||||
expect(arm64.downloads).not.toContain(`${sep}targets${sep}`)
|
||||
})
|
||||
|
||||
it('resolves the development primary runtime from the build target rather than the host architecture', () => {
|
||||
expect(developmentRuntimeDirectory({}, 'darwin', 'arm64'))
|
||||
.toContain(join('targets', 'mac-arm64', 'runtime', 'primary-runtime'))
|
||||
expect(developmentRuntimeDirectory({}, 'darwin', 'x64'))
|
||||
.toContain(join('targets', 'mac-x64', 'runtime', 'primary-runtime'))
|
||||
expect(developmentRuntimeDirectory({}, 'win32', 'arm64'))
|
||||
.toContain(join('targets', 'win-x64', 'runtime', 'primary-runtime'))
|
||||
})
|
||||
|
||||
it('resolves environment overrides and rejects unsupported targets', () => {
|
||||
expect(resolveDesktopBuildTarget({
|
||||
DSH_DESKTOP_TARGET_PLATFORM: 'darwin',
|
||||
|
||||
@@ -291,6 +291,7 @@ beforeEach(() => {
|
||||
vi.spyOn(console, 'info').mockImplementation(() => {})
|
||||
vi.stubEnv('DSH_DESKTOP_PNPM_ENTRY', 'test-pnpm')
|
||||
vi.stubEnv('DSH_DESKTOP_DSH_DIR', 'test-runtime')
|
||||
vi.stubEnv('DSH_DESKTOP_PRIMARY_RUNTIME_DIR', 'test-primary-runtime')
|
||||
vi.stubGlobal('process', { ...process, platform: 'win32', arch: 'x64', resourcesPath: 'desktop-test-resources' })
|
||||
vi.stubEnv('DSH_DESKTOP_HOST_INSPECT_PORT', undefined)
|
||||
vi.stubEnv('DSH_DESKTOP_MANDATORY_UPDATE_CONFIG', undefined)
|
||||
|
||||
Reference in new issue
Block a user