linux mobile app
This commit is contained in:
@@ -12,6 +12,7 @@ links = "tauri-plugin-vpn"
|
||||
tauri = { version = "2.10.3" }
|
||||
serde = "1.0"
|
||||
thiserror = "2"
|
||||
netrunner-client = { git = "ssh://git@github.com/nineAp/netrunner-core.git", branch = "main", features = ["desktop"] }
|
||||
|
||||
[build-dependencies]
|
||||
tauri-plugin = { version = "2.5.4", features = ["build"] }
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
use std::sync::Arc;
|
||||
use std::sync::Mutex;
|
||||
|
||||
use crate::models::*;
|
||||
use crate::VpnInterface;
|
||||
use netrunner_client::session::SessionManager;
|
||||
use netrunner_client::Session;
|
||||
use serde::de::DeserializeOwned;
|
||||
use tauri::{plugin::PluginApi, AppHandle, Runtime};
|
||||
|
||||
@@ -8,17 +13,32 @@ pub fn init<R: Runtime, C: DeserializeOwned>(
|
||||
app: &AppHandle<R>,
|
||||
_api: PluginApi<R, C>,
|
||||
) -> crate::Result<Vpn<R>> {
|
||||
Ok(Vpn(app.clone()))
|
||||
Ok(Vpn {
|
||||
app: app.clone(),
|
||||
active_session: Mutex::new(None),
|
||||
})
|
||||
}
|
||||
|
||||
pub struct Vpn<R: Runtime>(AppHandle<R>);
|
||||
pub struct Vpn<R: Runtime> {
|
||||
app: AppHandle<R>,
|
||||
active_session: Mutex<Option<Arc<Session>>>, // Хранилище сессии
|
||||
}
|
||||
|
||||
impl<R: Runtime> VpnInterface<R> for Vpn<R> {
|
||||
fn start_vpn(&self, _config: TunnelConfig, _ip: String, _port: i32) -> crate::Result<()> {
|
||||
fn start_vpn(&self, _config: TunnelConfig, ip: String, port: i32) -> crate::Result<()> {
|
||||
let session = SessionManager.start_desktop(format!("{}:{}", ip, port));
|
||||
|
||||
// Сохраняем сессию, чтобы она не выпала при выходе из функции
|
||||
let mut lock = self.active_session.lock().unwrap();
|
||||
*lock = Some(session);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn stop_vpn(&self) -> crate::Result<()> {
|
||||
let mut lock = self.active_session.lock().unwrap();
|
||||
if let Some(session) = lock.take() {
|
||||
session.stop();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user