fix: avoid unnecessary macOS folder prompts on desktop startup

Start managed OpenCode from the app data directory instead of the home folder
Prevent unnecessary Desktop, Documents, Downloads, and Music access prompts
Add coverage for configured OpenCode working directory
This commit is contained in:
Bohdan Triapitsyn
2026-06-11 01:06:25 +03:00
parent 6a4cf33131
commit a6571aa8b7
3 changed files with 37 additions and 1 deletions
+5
View File
@@ -1089,7 +1089,12 @@ const spawnLocalServer = async () => {
process.env.OPENCHAMBER_HOST = bindHost;
process.env.OPENCHAMBER_DIST_DIR = resolveWebDistDir();
process.env.OPENCHAMBER_RUNTIME = 'desktop';
process.env.OPENCHAMBER_OPENCODE_CWD = app.getPath('userData');
process.env.OPENCHAMBER_DESKTOP_NOTIFY = 'true';
try {
fs.mkdirSync(process.env.OPENCHAMBER_OPENCODE_CWD, { recursive: true });
} catch {
}
if (desktopUiPassword) {
process.env.OPENCHAMBER_UI_PASSWORD = desktopUiPassword;
} else {
@@ -6,12 +6,19 @@ export const createHmrStateRuntime = (dependencies) => {
stateKey,
} = dependencies;
const getInitialOpenCodeWorkingDirectory = () => {
const configured = typeof processLike.env.OPENCHAMBER_OPENCODE_CWD === 'string'
? processLike.env.OPENCHAMBER_OPENCODE_CWD.trim()
: '';
return configured || os.homedir();
};
const getOrCreateHmrState = () => {
if (!globalThisLike[stateKey]) {
globalThisLike[stateKey] = {
openCodeProcess: null,
openCodePort: null,
openCodeWorkingDirectory: os.homedir(),
openCodeWorkingDirectory: getInitialOpenCodeWorkingDirectory(),
isShuttingDown: false,
signalsAttached: false,
userProvidedOpenCodePassword: undefined,
@@ -0,0 +1,24 @@
import { describe, expect, it } from 'vitest';
import { createHmrStateRuntime } from './hmr-state-runtime.js';
const createRuntime = (env = {}) => createHmrStateRuntime({
globalThisLike: {},
os: { homedir: () => '/Users/example' },
processLike: { env },
stateKey: '__testHmrState',
});
describe('hmr state runtime', () => {
it('uses configured OpenCode cwd when provided', () => {
const runtime = createRuntime({ OPENCHAMBER_OPENCODE_CWD: '/tmp/openchamber-data' });
expect(runtime.getOrCreateHmrState().openCodeWorkingDirectory).toBe('/tmp/openchamber-data');
});
it('falls back to home directory without configured OpenCode cwd', () => {
const runtime = createRuntime();
expect(runtime.getOrCreateHmrState().openCodeWorkingDirectory).toBe('/Users/example');
});
});