Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/main/services/OpenClawService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type { NodeCheckResult } from '@shared/config/types'
import { IpcChannel } from '@shared/IpcChannel'
import { hasAPIVersion, withoutTrailingSlash } from '@shared/utils'
import type { Model, Provider, ProviderType, VertexProvider } from '@types'
import type { ChildProcess } from 'child_process'
import { type ChildProcess, spawn } from 'child_process'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Good cleanup by importing directly alongside type. This avoids redundant import statements.

import semver from 'semver'

import VertexAIService from './VertexAIService'
Expand Down Expand Up @@ -501,10 +501,20 @@ class OpenClawService {
let startupError: string | null = null
let processExited = false

const gatewayEnv = { ...shellEnv, OPENCLAW_CONFIG_PATH }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Positive: Good refactoring by extracting into a separate variable. This improves readability and ensures both Windows and non-Windows paths use the same environment configuration.

logger.info(`Spawning gateway process: ${openclawPath} gateway --port ${this.gatewayPort}`)
this.gatewayProcess = crossPlatformSpawn(openclawPath, ['gateway', '--port', String(this.gatewayPort)], {
env: { ...shellEnv, OPENCLAW_CONFIG_PATH }
})
if (isWin) {
// Force UTF-8 code page to prevent garbled Chinese text from child processes. See #13384.
this.gatewayProcess = spawn(
'cmd',
['/c', `chcp 65001 >nul && "${openclawPath}" gateway --port ${this.gatewayPort}`],
{ env: gatewayEnv, stdio: 'pipe' }
)
} else {
this.gatewayProcess = crossPlatformSpawn(openclawPath, ['gateway', '--port', String(this.gatewayPort)], {
env: gatewayEnv
})
}
logger.info(`Gateway process spawned with pid: ${this.gatewayProcess.pid}`)

// Monitor stderr for error messages
Expand Down
Loading