mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2025-05-20 07:26:58 -04:00
Refactor using Tauri (#278)
This commit is contained in:
10
crates/gpapi/src/service/event.rs
Normal file
10
crates/gpapi/src/service/event.rs
Normal file
@@ -0,0 +1,10 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::vpn_state::VpnState;
|
||||
|
||||
/// Events that can be emitted by the service
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub enum WsEvent {
|
||||
VpnState(VpnState),
|
||||
ActiveGui,
|
||||
}
|
3
crates/gpapi/src/service/mod.rs
Normal file
3
crates/gpapi/src/service/mod.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
pub mod event;
|
||||
pub mod request;
|
||||
pub mod vpn_state;
|
118
crates/gpapi/src/service/request.rs
Normal file
118
crates/gpapi/src/service/request.rs
Normal file
@@ -0,0 +1,118 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use specta::Type;
|
||||
|
||||
use crate::{gateway::Gateway, gp_params::ClientOs};
|
||||
|
||||
use super::vpn_state::ConnectInfo;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct LaunchGuiRequest {
|
||||
user: String,
|
||||
envs: HashMap<String, String>,
|
||||
}
|
||||
|
||||
impl LaunchGuiRequest {
|
||||
pub fn new(user: String, envs: HashMap<String, String>) -> Self {
|
||||
Self { user, envs }
|
||||
}
|
||||
|
||||
pub fn user(&self) -> &str {
|
||||
&self.user
|
||||
}
|
||||
|
||||
pub fn envs(&self) -> &HashMap<String, String> {
|
||||
&self.envs
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Type)]
|
||||
pub struct ConnectArgs {
|
||||
cookie: String,
|
||||
vpnc_script: Option<String>,
|
||||
user_agent: Option<String>,
|
||||
os: Option<ClientOs>,
|
||||
}
|
||||
|
||||
impl ConnectArgs {
|
||||
pub fn new(cookie: String) -> Self {
|
||||
Self {
|
||||
cookie,
|
||||
vpnc_script: None,
|
||||
user_agent: None,
|
||||
os: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cookie(&self) -> &str {
|
||||
&self.cookie
|
||||
}
|
||||
|
||||
pub fn vpnc_script(&self) -> Option<String> {
|
||||
self.vpnc_script.clone()
|
||||
}
|
||||
|
||||
pub fn user_agent(&self) -> Option<String> {
|
||||
self.user_agent.clone()
|
||||
}
|
||||
|
||||
pub fn openconnect_os(&self) -> Option<String> {
|
||||
self
|
||||
.os
|
||||
.as_ref()
|
||||
.map(|os| os.to_openconnect_os().to_string())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Type)]
|
||||
pub struct ConnectRequest {
|
||||
info: ConnectInfo,
|
||||
args: ConnectArgs,
|
||||
}
|
||||
|
||||
impl ConnectRequest {
|
||||
pub fn new(info: ConnectInfo, cookie: String) -> Self {
|
||||
Self {
|
||||
info,
|
||||
args: ConnectArgs::new(cookie),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_vpnc_script<T: Into<Option<String>>>(mut self, vpnc_script: T) -> Self {
|
||||
self.args.vpnc_script = vpnc_script.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_user_agent<T: Into<Option<String>>>(mut self, user_agent: T) -> Self {
|
||||
self.args.user_agent = user_agent.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_os<T: Into<Option<ClientOs>>>(mut self, os: T) -> Self {
|
||||
self.args.os = os.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn gateway(&self) -> &Gateway {
|
||||
self.info.gateway()
|
||||
}
|
||||
|
||||
pub fn info(&self) -> &ConnectInfo {
|
||||
&self.info
|
||||
}
|
||||
|
||||
pub fn args(&self) -> &ConnectArgs {
|
||||
&self.args
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Type)]
|
||||
pub struct DisconnectRequest;
|
||||
|
||||
/// Requests that can be sent to the service
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub enum WsRequest {
|
||||
Connect(Box<ConnectRequest>),
|
||||
Disconnect(DisconnectRequest),
|
||||
}
|
34
crates/gpapi/src/service/vpn_state.rs
Normal file
34
crates/gpapi/src/service/vpn_state.rs
Normal file
@@ -0,0 +1,34 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use specta::Type;
|
||||
|
||||
use crate::gateway::Gateway;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Type, Clone)]
|
||||
pub struct ConnectInfo {
|
||||
portal: String,
|
||||
gateway: Gateway,
|
||||
gateways: Vec<Gateway>,
|
||||
}
|
||||
|
||||
impl ConnectInfo {
|
||||
pub fn new(portal: String, gateway: Gateway, gateways: Vec<Gateway>) -> Self {
|
||||
Self {
|
||||
portal,
|
||||
gateway,
|
||||
gateways,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn gateway(&self) -> &Gateway {
|
||||
&self.gateway
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum VpnState {
|
||||
Disconnected,
|
||||
Connecting(Box<ConnectInfo>),
|
||||
Connected(Box<ConnectInfo>),
|
||||
Disconnecting,
|
||||
}
|
Reference in New Issue
Block a user