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:
@@ -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');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user