Skip to content
Merged
Show file tree
Hide file tree
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
20 changes: 20 additions & 0 deletions crates/server/src/host/catalog/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ struct SystemSettingsStore {
proxy: PersistedProxy,
#[serde(default)]
rendering: SystemRenderingSettings,
/// Desktop shell flag. Full-section saves must keep it, or a proxy or
/// rendering write drops the remembered developer-mode switch.
#[serde(default)]
developer_mode: bool,
}

#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
Expand Down Expand Up @@ -1166,4 +1170,20 @@ mod tests {
Some(target)
);
}

#[test]
fn system_section_rewrite_keeps_developer_mode() {
let store: SystemSettingsStore = serde_json::from_str(
r#"{"proxy":{"mode":"auto"},"rendering":{"acceleration_mode":"auto"},"developer_mode":true}"#,
)
.expect("system section");
assert!(store.developer_mode);
let rewritten = serde_json::to_value(&store).expect("rewrite");
assert_eq!(rewritten["developer_mode"], true);

let missing: SystemSettingsStore =
serde_json::from_str(r#"{"rendering":{"acceleration_mode":"disable_gpu"}}"#)
.expect("older system section");
assert!(!missing.developer_mode);
}
}
10 changes: 9 additions & 1 deletion docs/settings-json.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ The current document shape is:
},
"rendering": {
"acceleration_mode": "auto"
}
},
"developer_mode": false
},
"web_service": {
"port": 17891,
Expand Down Expand Up @@ -77,6 +78,13 @@ The former application `config.json`, `version-control-settings.json`, and
imported when their corresponding section is first needed. Existing browser
preferences are likewise imported into the `frontend` section on first launch.

`system.developer_mode` is the desktop shell switch for the app inspector. It
defaults to false. When true, the shell that owns the WebView enables F12 and
the platform inspect shortcut, and Settings → System can open the inspector
for the current window. The desktop shell reads and writes this field in the
local settings document. A remote Host's copy does not control the window you
are looking at. Proxy and rendering saves keep the field.

Secrets stay out of this user-editable document: provider and channel tokens
remain in their protected secret stores. Agent-native settings remain in the
files owned by each agent; VibeX does not duplicate or overwrite those
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/i18n/locales/en/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3340,6 +3340,10 @@
"moreEntries": "{{count}} more entries not shown",
"clearLocalDataTitle": "Clear VibeX local data",
"clearLocalDataLabel": "Clear local configuration and cache",
"developerMode": "Developer mode",
"developerModeDescription": "When on, inspect the interface with F12 or Ctrl+Shift+I. On macOS, use Option+Command+I.",
"openDeveloperTools": "Open developer tools",
"developerModeSaveFailed": "Could not save developer mode",
"saveSettings": "Save settings"
},
"browser": {
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/i18n/locales/zh-CN/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3340,6 +3340,10 @@
"moreEntries": "还有 {{count}} 个条目未显示",
"clearLocalDataTitle": "清除 VibeX 本地数据",
"clearLocalDataLabel": "清除本机配置和缓存",
"developerMode": "开发者模式",
"developerModeDescription": "打开后可用 F12 或 Ctrl+Shift+I 检查界面。macOS 使用 Option+Command+I。",
"openDeveloperTools": "打开开发者工具",
"developerModeSaveFailed": "开发者模式保存失败",
"saveSettings": "保存设置"
},
"browser": {
Expand Down
9 changes: 9 additions & 0 deletions frontend/src/lib/api/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,15 @@ export const desktopApi = {
revealInFileManager: async (path: string): Promise<void> => {
return desktopShellCall<void>('reveal_in_file_manager', { path });
},
getDeveloperMode: async (): Promise<boolean> => {
return desktopShellCall<boolean>('get_developer_mode');
},
setDeveloperMode: async (enabled: boolean): Promise<boolean> => {
return desktopShellCall<boolean>('set_developer_mode', { enabled });
},
openDeveloperTools: async (): Promise<void> => {
return desktopShellCall<void>('open_developer_tools');
},
isMainWindowFocused: async (): Promise<boolean> => {
return desktopShellCall<boolean>('is_main_window_focused');
},
Expand Down
34 changes: 34 additions & 0 deletions frontend/src/pages/settings/SystemSettings.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ const mocks = vi.hoisted(() => ({
getDataDir: vi.fn(),
updateDataDir: vi.fn(),
revealInFileManager: vi.fn(),
getDeveloperMode: vi.fn(),
setDeveloperMode: vi.fn(),
openDeveloperTools: vi.fn(),
pickHostDirectory: vi.fn(),
backupCreate: vi.fn(),
backupInspect: vi.fn(),
Expand Down Expand Up @@ -48,6 +51,9 @@ vi.mock('@/lib/hostFs', () => ({
vi.mock('@/lib/api/misc', () => ({
desktopApi: {
revealInFileManager: mocks.revealInFileManager,
getDeveloperMode: mocks.getDeveloperMode,
setDeveloperMode: mocks.setDeveloperMode,
openDeveloperTools: mocks.openDeveloperTools,
},
}));

Expand Down Expand Up @@ -166,6 +172,11 @@ describe('SystemSettings', () => {
requires_reload: false,
}));
mocks.revealInFileManager.mockResolvedValue(undefined);
mocks.getDeveloperMode.mockResolvedValue(false);
mocks.setDeveloperMode.mockImplementation(
async (enabled: boolean) => enabled
);
mocks.openDeveloperTools.mockResolvedValue(undefined);
mocks.pickHostDirectory.mockResolvedValue('/Volumes/SSD/VibeXData');
mocks.backupCreate.mockResolvedValue(preview);
mocks.backupInspect.mockResolvedValue(preview);
Expand Down Expand Up @@ -338,4 +349,27 @@ describe('SystemSettings', () => {
await act(async () => confirmOptions.action.onClick());
expect(mocks.updateDataDir).toHaveBeenCalledWith('/Volumes/SSD/VibeXData');
});

it('keeps developer mode at the bottom of system settings and opens the inspector', async () => {
const user = userEvent.setup();
render(<SystemSettings />);

const headings = await screen.findAllByRole('heading', { level: 3 });
expect(headings.at(-1)).toHaveTextContent('开发者模式');
expect(
headings.findIndex(
(heading) => heading.textContent === '清除 VibeX 本地数据'
)
).toBeLessThan(headings.length - 1);

const toggle = screen.getByRole('switch', { name: '开发者模式' });
expect(toggle).not.toBeChecked();
await user.click(toggle);
await waitFor(() => {
expect(mocks.setDeveloperMode).toHaveBeenCalledWith(true);
});

await user.click(screen.getByRole('button', { name: '打开开发者工具' }));
expect(mocks.openDeveloperTools).toHaveBeenCalled();
});
});
84 changes: 82 additions & 2 deletions frontend/src/pages/settings/SystemSettings.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useCallback, useEffect, useRef, useState } from 'react';
import {
Archive,
Bug,
Download,
FileJson2,
FolderOpen,
Expand All @@ -17,6 +18,7 @@ import { useUserSystem } from '@/components/ConfigProvider';
import { TextInput } from '@astryxdesign/core/TextInput';
import { Button } from '@/components/ui/button';
import { Label } from '@/components/ui/label';
import { Switch } from '@/components/ui/switch';
import {
Select,
SelectContent,
Expand All @@ -38,7 +40,7 @@ import { useWindowProjectsStore } from '@/stores/useWindowProjectsStore';
import { ConversationBundlePanel } from '@/features/conversation/ConversationBundle';
import { getInvokeErrorMessage } from '@/lib/errors';
import { SETTINGS_CHANGED_EVENT } from '@/lib/frontendPreferences';
import { useLocalDesktopHost } from '@/lib/desktopShell';
import { useLocalDesktopHost, useTauriClient } from '@/lib/desktopShell';

import { SettingsSection } from './SettingsUi';
import { useLiveSettingsCommit } from './useLiveSettingsCommit';
Expand Down Expand Up @@ -133,6 +135,7 @@ export function SystemSettings() {
const { t } = useTranslation(['settings', 'common']);
const { config, loading, updateAndSaveConfig } = useUserSystem();
const localDesktopHost = useLocalDesktopHost();
const tauriClient = useTauriClient();

const [draft, setDraft] = useState<SystemSettingsConfig | null>(() =>
config ? structuredClone(config as SystemSettingsConfig) : null
Expand All @@ -152,6 +155,9 @@ export function SystemSettings() {
const renderingDraftRef = useRef(renderingDraft);
renderingDraftRef.current = renderingDraft;
const [renderingLoading, setRenderingLoading] = useState(true);
const [developerMode, setDeveloperMode] = useState(false);
const [developerModeLoading, setDeveloperModeLoading] = useState(tauriClient);
const developerModeHoldingRef = useRef(false);
const { writeNow, holding } = useLiveSettingsCommit(
async (next: SystemSettingsConfig) => {
const saved = await updateAndSaveConfig(sanitizeDraft(next));
Expand Down Expand Up @@ -249,6 +255,23 @@ export function SystemSettings() {
setRenderingLoading(false);
}

if (tauriClient) {
try {
const enabled = await desktopApi.getDeveloperMode();
if (!developerModeHoldingRef.current) {
setDeveloperMode(enabled);
}
} catch (error) {
toast.error(
error instanceof Error
? error.message
: t('system.developerModeSaveFailed')
);
} finally {
setDeveloperModeLoading(false);
}
}

try {
const dataDirSettings = await systemSettingsApi.getDataDir?.();
if (dataDirSettings?.current_data_dir) {
Expand All @@ -258,7 +281,7 @@ export function SystemSettings() {
} catch {
// Optional during backend transition or mocked environments.
}
}, [proxyHoldingRef, renderingHoldingRef, t]);
}, [proxyHoldingRef, renderingHoldingRef, t, tauriClient]);

useEffect(() => {
void refreshSystemSettings();
Expand Down Expand Up @@ -959,6 +982,63 @@ export function SystemSettings() {
</Button>
</div>
</SettingsSection>

{tauriClient ? (
<SettingsSection
icon={Bug}
title={t('system.developerMode')}
description={t('system.developerModeDescription')}
bare={!developerMode}
action={
<Switch
aria-label={t('system.developerMode')}
checked={developerMode}
disabled={developerModeLoading}
onCheckedChange={(checked) => {
const previous = developerMode;
developerModeHoldingRef.current = true;
setDeveloperMode(checked);
void desktopApi
.setDeveloperMode(checked)
.then((saved) => {
setDeveloperMode(saved);
})
.catch((error: unknown) => {
setDeveloperMode(previous);
toast.error(
error instanceof Error
? error.message
: t('system.developerModeSaveFailed')
);
})
.finally(() => {
developerModeHoldingRef.current = false;
});
}}
/>
}
>
{developerMode ? (
<div className="flex justify-end">
<Button
variant="outline"
onClick={() => {
void desktopApi
.openDeveloperTools()
.catch((error: unknown) => {
toast.error(
getInvokeErrorMessage(error) ||
t('system.developerModeSaveFailed')
);
});
}}
>
{t('system.openDeveloperTools')}
</Button>
</div>
) : null}
</SettingsSection>
) : null}
</div>
</div>
);
Expand Down
1 change: 1 addition & 0 deletions frontend/src/pages/settings/settingsSearchCatalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,5 +212,6 @@ export const SETTINGS_SEARCH_ENTRIES: SettingsSearchEntry[] = [
'system.renderingTitle',
'system.backupTitle',
'system.clearLocalDataTitle',
'system.developerMode',
]),
];
8 changes: 6 additions & 2 deletions frontend/tests/tauri-build-devtools-feature.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ function readRepoFile(relativePath) {
return fs.readFileSync(path.join(repoRoot, relativePath), 'utf8');
}

test('release tauri build enables devtools feature for desktop parity', () => {
test('release tauri build leaves the devtools feature off', () => {
const source = readRepoFile('src-tauri/Cargo.toml');

assert.match(source, /tauri\s*=\s*\{\s*version\s*=\s*"2"\s*,\s*features\s*=\s*\[[^\]]*"devtools"/);
assert.doesNotMatch(
source,
/tauri\s*=\s*\{[^}]*"devtools"/,
'developer mode is a settings.json switch, not the compile-time tauri/devtools feature'
);
});
3 changes: 3 additions & 0 deletions shared/hostCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,9 @@ export const DESKTOP_SHELL_COMMANDS = [
'start_create_host_tunnel',
'take_tauri_inspector_capture',
'update_web_service_config',
'get_developer_mode',
'set_developer_mode',
'open_developer_tools',
] as const;

export const HOST_CAPABILITY_SCOPES = [
Expand Down
3 changes: 3 additions & 0 deletions src-tauri/src/bin/generate_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,9 @@ const DESKTOP_SHELL_COMMANDS: &[&str] = &[
"start_create_host_tunnel",
"take_tauri_inspector_capture",
"update_web_service_config",
"get_developer_mode",
"set_developer_mode",
"open_developer_tools",
];

fn workspace_root() -> PathBuf {
Expand Down
3 changes: 3 additions & 0 deletions src-tauri/src/commands/system_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ struct SystemSettingsStore {
proxy: PersistedProxy,
#[serde(default)]
rendering: SystemRenderingSettings,
/// Kept so a legacy migration rewrite does not drop the desktop shell flag.
#[serde(default)]
developer_mode: bool,
}

fn settings_path() -> PathBuf {
Expand Down
Loading
Loading