mirror of
https://github.com/sst/opencode.git
synced 2025-12-23 10:11:41 +00:00
tui: use random free port and enable icon discovery by default
- Tauri app now automatically finds an available port instead of defaulting to 4096 - Icon discovery feature is now enabled by default in the Tauri app - Prevents port conflicts when multiple OpenCode instances are running
This commit is contained in:
parent
59fb3ae606
commit
9ad828dcd0
3 changed files with 12 additions and 3 deletions
|
|
@ -14,6 +14,8 @@ export namespace Flag {
|
|||
|
||||
// Experimental
|
||||
export const OPENCODE_EXPERIMENTAL = truthy("OPENCODE_EXPERIMENTAL")
|
||||
export const OPENCODE_EXPERIMENTAL_ICON_DISCOVERY =
|
||||
OPENCODE_EXPERIMENTAL || truthy("OPENCODE_EXPERIMENTAL_ICON_DISCOVERY")
|
||||
export const OPENCODE_EXPERIMENTAL_WATCHER = OPENCODE_EXPERIMENTAL || truthy("OPENCODE_EXPERIMENTAL_WATCHER")
|
||||
export const OPENCODE_EXPERIMENTAL_DISABLE_COPY_ON_SELECT = truthy("OPENCODE_EXPERIMENTAL_DISABLE_COPY_ON_SELECT")
|
||||
export const OPENCODE_ENABLE_EXA =
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ export namespace Project {
|
|||
await migrateFromGlobal(id, worktree)
|
||||
}
|
||||
}
|
||||
if (Flag.OPENCODE_EXPERIMENTAL) discover(existing)
|
||||
if (Flag.OPENCODE_EXPERIMENTAL_ICON_DISCOVERY) discover(existing)
|
||||
const result: Info = {
|
||||
...existing,
|
||||
worktree,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use std::{
|
||||
net::SocketAddr,
|
||||
net::{SocketAddr, TcpListener},
|
||||
process::Command,
|
||||
sync::{Arc, Mutex},
|
||||
time::{Duration, Instant},
|
||||
|
|
@ -18,7 +18,13 @@ fn get_sidecar_port() -> u16 {
|
|||
.map(|s| s.to_string())
|
||||
.or_else(|| std::env::var("OPENCODE_PORT").ok())
|
||||
.and_then(|port_str| port_str.parse().ok())
|
||||
.unwrap_or(4096)
|
||||
.unwrap_or_else(|| {
|
||||
TcpListener::bind("127.0.0.1:0")
|
||||
.expect("Failed to bind to find free port")
|
||||
.local_addr()
|
||||
.expect("Failed to get local address")
|
||||
.port()
|
||||
})
|
||||
}
|
||||
|
||||
fn find_and_kill_process_on_port(port: u16) -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
|
@ -60,6 +66,7 @@ fn spawn_sidecar(app: &AppHandle, port: u16) -> CommandChild {
|
|||
.shell()
|
||||
.sidecar("opencode")
|
||||
.unwrap()
|
||||
.env("OPENCODE_EXPERIMENTAL_ICON_DISCOVERY", "true")
|
||||
.args(["serve", &format!("--port={port}")])
|
||||
.spawn()
|
||||
.expect("Failed to spawn opencode");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue