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
31 changes: 30 additions & 1 deletion src-tauri/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ pub(crate) struct WorkspaceSettings {
pub(crate) struct AppSettings {
#[serde(default, rename = "codexBin")]
pub(crate) codex_bin: Option<String>,
#[serde(default, rename = "backendMode")]
pub(crate) backend_mode: BackendMode,
#[serde(default = "default_remote_backend_host", rename = "remoteBackendHost")]
pub(crate) remote_backend_host: String,
#[serde(default, rename = "remoteBackendToken")]
pub(crate) remote_backend_token: Option<String>,
#[serde(default = "default_access_mode", rename = "defaultAccessMode")]
pub(crate) default_access_mode: String,
#[serde(default = "default_ui_scale", rename = "uiScale")]
Expand Down Expand Up @@ -204,10 +210,27 @@ pub(crate) struct AppSettings {
pub(crate) dictation_hold_key: String,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "lowercase")]
pub(crate) enum BackendMode {
Local,
Remote,
}

impl Default for BackendMode {
fn default() -> Self {
BackendMode::Local
}
}

fn default_access_mode() -> String {
"current".to_string()
}

fn default_remote_backend_host() -> String {
"127.0.0.1:4732".to_string()
}

fn default_ui_scale() -> f64 {
1.0
}
Expand Down Expand Up @@ -244,6 +267,9 @@ impl Default for AppSettings {
fn default() -> Self {
Self {
codex_bin: None,
backend_mode: BackendMode::Local,
remote_backend_host: default_remote_backend_host(),
remote_backend_token: None,
default_access_mode: "current".to_string(),
ui_scale: 1.0,
notification_sounds_enabled: true,
Expand All @@ -260,12 +286,15 @@ impl Default for AppSettings {

#[cfg(test)]
mod tests {
use super::{AppSettings, WorkspaceEntry, WorkspaceKind};
use super::{AppSettings, BackendMode, WorkspaceEntry, WorkspaceKind};

#[test]
fn app_settings_defaults_from_empty_json() {
let settings: AppSettings = serde_json::from_str("{}").expect("settings deserialize");
assert!(settings.codex_bin.is_none());
assert!(matches!(settings.backend_mode, BackendMode::Local));
assert_eq!(settings.remote_backend_host, "127.0.0.1:4732");
assert!(settings.remote_backend_token.is_none());
assert_eq!(settings.default_access_mode, "current");
assert!((settings.ui_scale - 1.0).abs() < f64::EPSILON);
assert!(settings.notification_sounds_enabled);
Expand Down
101 changes: 101 additions & 0 deletions src/features/settings/components/SettingsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ export function SettingsView({
}: SettingsViewProps) {
const [activeSection, setActiveSection] = useState<CodexSection>("projects");
const [codexPathDraft, setCodexPathDraft] = useState(appSettings.codexBin ?? "");
const [remoteHostDraft, setRemoteHostDraft] = useState(appSettings.remoteBackendHost);
const [remoteTokenDraft, setRemoteTokenDraft] = useState(appSettings.remoteBackendToken ?? "");
const [scaleDraft, setScaleDraft] = useState(
`${Math.round(clampUiScale(appSettings.uiScale) * 100)}%`,
);
Expand Down Expand Up @@ -116,6 +118,14 @@ export function SettingsView({
setCodexPathDraft(appSettings.codexBin ?? "");
}, [appSettings.codexBin]);

useEffect(() => {
setRemoteHostDraft(appSettings.remoteBackendHost);
}, [appSettings.remoteBackendHost]);

useEffect(() => {
setRemoteTokenDraft(appSettings.remoteBackendToken ?? "");
}, [appSettings.remoteBackendToken]);

useEffect(() => {
setScaleDraft(`${Math.round(clampUiScale(appSettings.uiScale) * 100)}%`);
}, [appSettings.uiScale]);
Expand Down Expand Up @@ -158,6 +168,30 @@ export function SettingsView({
}
};

const handleCommitRemoteHost = async () => {
const nextHost = remoteHostDraft.trim() || "127.0.0.1:4732";
setRemoteHostDraft(nextHost);
if (nextHost === appSettings.remoteBackendHost) {
return;
}
await onUpdateAppSettings({
...appSettings,
remoteBackendHost: nextHost,
});
};

const handleCommitRemoteToken = async () => {
const nextToken = remoteTokenDraft.trim() ? remoteTokenDraft.trim() : null;
setRemoteTokenDraft(nextToken ?? "");
if (nextToken === appSettings.remoteBackendToken) {
return;
}
await onUpdateAppSettings({
...appSettings,
remoteBackendToken: nextToken,
});
};

const handleCommitScale = async () => {
if (parsedScale === null) {
setScaleDraft(`${Math.round(clampUiScale(appSettings.uiScale) * 100)}%`);
Expand Down Expand Up @@ -742,6 +776,73 @@ export function SettingsView({
</select>
</div>

<div className="settings-field">
<label className="settings-field-label" htmlFor="backend-mode">
Backend mode
</label>
<select
id="backend-mode"
className="settings-select"
value={appSettings.backendMode}
onChange={(event) =>
void onUpdateAppSettings({
...appSettings,
backendMode: event.target.value as AppSettings["backendMode"],
})
}
>
<option value="local">Local (default)</option>
<option value="remote">Remote (daemon)</option>
</select>
<div className="settings-help">
Remote mode connects to a separate daemon running the backend on another machine (e.g. WSL2/Linux).
</div>
</div>

{appSettings.backendMode === "remote" && (
<div className="settings-field">
<div className="settings-field-label">Remote backend</div>
<div className="settings-field-row">
<input
className="settings-input settings-input--compact"
value={remoteHostDraft}
placeholder="127.0.0.1:4732"
onChange={(event) => setRemoteHostDraft(event.target.value)}
onBlur={() => {
void handleCommitRemoteHost();
}}
onKeyDown={(event) => {
if (event.key === "Enter") {
event.preventDefault();
void handleCommitRemoteHost();
}
}}
aria-label="Remote backend host"
/>
<input
type="password"
className="settings-input settings-input--compact"
value={remoteTokenDraft}
placeholder="Token (optional)"
onChange={(event) => setRemoteTokenDraft(event.target.value)}
onBlur={() => {
void handleCommitRemoteToken();
}}
onKeyDown={(event) => {
if (event.key === "Enter") {
event.preventDefault();
void handleCommitRemoteToken();
}
}}
aria-label="Remote backend token"
/>
</div>
<div className="settings-help">
Start the daemon separately and point CodexMonitor to it (host:port + token).
</div>
</div>
)}

<div className="settings-field">
<div className="settings-field-label">Workspace overrides</div>
<div className="settings-overrides">
Expand Down
3 changes: 3 additions & 0 deletions src/features/settings/hooks/useAppSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { clampUiScale, UI_SCALE_DEFAULT } from "../../../utils/uiScale";

const defaultSettings: AppSettings = {
codexBin: null,
backendMode: "local",
remoteBackendHost: "127.0.0.1:4732",
remoteBackendToken: null,
defaultAccessMode: "current",
uiScale: UI_SCALE_DEFAULT,
notificationSoundsEnabled: true,
Expand Down
4 changes: 4 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,13 @@ export type ReviewTarget =
| { type: "custom"; instructions: string };

export type AccessMode = "read-only" | "current" | "full-access";
export type BackendMode = "local" | "remote";

export type AppSettings = {
codexBin: string | null;
backendMode: BackendMode;
remoteBackendHost: string;
remoteBackendToken: string | null;
defaultAccessMode: AccessMode;
uiScale: number;
notificationSoundsEnabled: boolean;
Expand Down