refactor: wip

This commit is contained in:
GyDi
2022-11-14 01:26:33 +08:00
parent fd6633f536
commit b03c52a501
32 changed files with 2704 additions and 880 deletions

View File

@@ -1,20 +1,14 @@
extern crate warp;
use super::resolve;
use crate::data::Verge;
use crate::config::VergeN;
use port_scanner::local_port_available;
use tauri::AppHandle;
use warp::Filter;
#[cfg(not(feature = "verge-dev"))]
const SERVER_PORT: u16 = 33331;
#[cfg(feature = "verge-dev")]
const SERVER_PORT: u16 = 11233;
/// check whether there is already exists
pub fn check_singleton() -> Result<(), ()> {
let verge = Verge::new();
let port = verge.app_singleton_port.unwrap_or(SERVER_PORT);
let port = VergeN::get_singleton_port();
if !local_port_available(port) {
tauri::async_runtime::block_on(async {
@@ -29,14 +23,14 @@ pub fn check_singleton() -> Result<(), ()> {
/// The embed server only be used to implement singleton process
/// maybe it can be used as pac server later
pub fn embed_server(app_handle: &AppHandle, port: Option<u16>) {
pub fn embed_server(app_handle: AppHandle) {
let app_handle = app_handle.clone();
let port = port.unwrap_or(SERVER_PORT);
let port = VergeN::get_singleton_port();
tauri::async_runtime::spawn(async move {
let commands = warp::path!("commands" / "visible").map(move || {
resolve::create_window(&app_handle);
return format!("ok");
format!("ok")
});
warp::serve(commands).bind(([127, 0, 0, 1], port)).await;