Skip to content

Commit abc25e8

Browse files
committed
codex_desktop for win, linux
1 parent 2c3f4b5 commit abc25e8

1 file changed

Lines changed: 40 additions & 10 deletions

File tree

‎crates/wizard-core/src/agents/codex.rs‎

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ pub fn prepare_routing(mode: RoutingMode, settings: &Settings) -> Result<Prepare
172172
))
173173
}
174174

175-
/// Add GUI-owned proxy demand and, on macOS, `ChatGPT` profile configuration.
175+
/// Add GUI-owned proxy demand and `ChatGPT` profile configuration.
176176
pub fn prepare_routing_for_gui(mode: RoutingMode, settings: &Settings) -> Result<PreparedPlan> {
177177
let mut plan = prepare_routing(mode, settings)?;
178178
let enabled = if mode == RoutingMode::Disabled {
@@ -189,23 +189,53 @@ pub fn prepare_routing_for_gui(mode: RoutingMode, settings: &Settings) -> Result
189189
}
190190
}
191191
};
192-
#[cfg(target_os = "macos")]
193-
{
194-
let change = prepare_desktop_proxy(enabled)?;
195-
plan.steps.insert(0, PreparedStep::ChangeFile { change });
196-
}
192+
let path = desktop_preferences_path()?.context("ChatGPT profile location is unavailable")?;
193+
let change = prepare_desktop_proxy(path, enabled)?;
194+
plan.steps.insert(0, PreparedStep::ChangeFile { change });
197195
plan.steps
198196
.push(PreparedStep::SetCodexProxyEnabled { enabled });
199197
Ok(plan)
200198
}
201199

202-
#[cfg(target_os = "macos")]
203-
fn prepare_desktop_proxy(enabled: bool) -> Result<FileChange> {
200+
fn desktop_preferences_path() -> Result<Option<PathBuf>> {
201+
#[cfg(any(target_os = "macos", target_os = "linux"))]
202+
{
203+
let config =
204+
dirs::config_dir().context("failed to resolve ChatGPT configuration directory")?;
205+
Ok(Some(config.join("Codex/Default/Preferences")))
206+
}
207+
#[cfg(target_os = "windows")]
208+
{
209+
// MSIX redirects roaming app data into the current user's package directory.
210+
// Query metadata only; do not launch the app or read its profile here.
211+
let script = r"
212+
$ErrorActionPreference = 'Stop'
213+
$ProgressPreference = 'SilentlyContinue'
214+
[Console]::OutputEncoding = [System.Text.UTF8Encoding]::new($false)
215+
$package = Get-AppxPackage -Name OpenAI.Codex | Sort-Object Version -Descending | Select-Object -First 1
216+
if ($null -eq $package) { 'null'; exit 0 }
217+
$root = Join-Path (Join-Path $env:LOCALAPPDATA 'Packages') $package.PackageFamilyName
218+
Join-Path $root 'LocalCache\Roaming\Codex\web\Codex\Default\Preferences' | ConvertTo-Json -Compress
219+
";
220+
let mut command = tokio::process::Command::new("powershell.exe");
221+
command
222+
.args(["-NoProfile", "-NonInteractive", "-Command", script])
223+
.stdin(Stdio::null())
224+
.stdout(Stdio::piped())
225+
.stderr(Stdio::piped());
226+
let output = command_output(command, Duration::from_secs(15))?;
227+
ensure!(
228+
output.status.success(),
229+
"ChatGPT profile location query failed"
230+
);
231+
serde_json::from_slice(&output.stdout).context("invalid ChatGPT profile location response")
232+
}
233+
}
234+
235+
fn prepare_desktop_proxy(path: PathBuf, enabled: bool) -> Result<FileChange> {
204236
use crate::config_files::{changes::FileSnapshot, json};
205237
use serde_json::json;
206238

207-
let home = dirs::home_dir().context("failed to resolve home directory")?;
208-
let path = home.join("Library/Application Support/Codex/Default/Preferences");
209239
let mut change = FileChange::read(std::path::absolute(path)?)?;
210240
if matches!(change.after, FileSnapshot::Missing) {
211241
log::info!("ChatGPT proxy configuration skipped: profile Preferences file is missing");

0 commit comments

Comments
 (0)