mirror of
https://wget.la/https://github.com/leookun/cursor-byok
synced 2026-10-06 21:52:51 +08:00
feat: add configurable Cursor TAB routing
This commit is contained in:
@@ -9,7 +9,10 @@ use parking_lot::RwLock;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
use crate::{store::Store, Error, Result};
|
||||
use crate::{
|
||||
store::{Store, TabMode, TabSettings},
|
||||
Error, Result,
|
||||
};
|
||||
|
||||
use self::{ca::CaManager, proxy::ProxyRuntime};
|
||||
|
||||
@@ -65,6 +68,7 @@ struct Inner {
|
||||
ca: CaManager,
|
||||
ca_initialization: Mutex<()>,
|
||||
backend_addr: RwLock<Option<SocketAddr>>,
|
||||
tab_mode: Arc<RwLock<TabMode>>,
|
||||
proxy: Mutex<ProxyRuntime>,
|
||||
}
|
||||
|
||||
@@ -76,6 +80,7 @@ impl CursorHarness {
|
||||
ca: CaManager::managed()?,
|
||||
ca_initialization: Mutex::new(()),
|
||||
backend_addr: RwLock::new(None),
|
||||
tab_mode: Arc::new(RwLock::new(TabMode::default())),
|
||||
proxy: Mutex::new(ProxyRuntime::default()),
|
||||
}),
|
||||
})
|
||||
@@ -138,6 +143,12 @@ impl CursorHarness {
|
||||
self.status().await
|
||||
}
|
||||
|
||||
pub async fn set_tab_settings(&self, settings: TabSettings) -> Result<TabSettings> {
|
||||
let saved = self.inner.store.set_tab_settings(settings).await?;
|
||||
*self.inner.tab_mode.write() = saved.mode;
|
||||
Ok(saved)
|
||||
}
|
||||
|
||||
async fn enable(&self) -> Result<()> {
|
||||
if !matches!(self.inner.ca.state()?, CaState::Ready) {
|
||||
return Err(Error::Config(
|
||||
@@ -158,7 +169,15 @@ impl CursorHarness {
|
||||
}
|
||||
let ca = self.inner.ca.load()?;
|
||||
let requested_port = self.inner.store.port_settings().await?.proxy_port;
|
||||
let (url, actual_port) = proxy.start(backend_addr, ca, requested_port).await?;
|
||||
*self.inner.tab_mode.write() = self.inner.store.tab_settings().await?.mode;
|
||||
let (url, actual_port) = proxy
|
||||
.start(
|
||||
backend_addr,
|
||||
ca,
|
||||
requested_port,
|
||||
self.inner.tab_mode.clone(),
|
||||
)
|
||||
.await?;
|
||||
if let Err(error) = self.inner.store.set_proxy_port(actual_port).await {
|
||||
proxy.stop().await;
|
||||
return Err(error);
|
||||
|
||||
Reference in New Issue
Block a user