fix: adjust singleton detect
This commit is contained in:
parent
4ae00714d2
commit
be81cd72af
@ -2,19 +2,26 @@ extern crate warp;
|
|||||||
|
|
||||||
use super::resolve;
|
use super::resolve;
|
||||||
use crate::config::IVerge;
|
use crate::config::IVerge;
|
||||||
|
use anyhow::{bail, Result};
|
||||||
use port_scanner::local_port_available;
|
use port_scanner::local_port_available;
|
||||||
use tauri::AppHandle;
|
use tauri::AppHandle;
|
||||||
use warp::Filter;
|
use warp::Filter;
|
||||||
|
|
||||||
/// check whether there is already exists
|
/// check whether there is already exists
|
||||||
pub fn check_singleton() -> Result<(), ()> {
|
pub fn check_singleton() -> Result<()> {
|
||||||
let port = IVerge::get_singleton_port();
|
let port = IVerge::get_singleton_port();
|
||||||
|
|
||||||
if !local_port_available(port) {
|
if !local_port_available(port) {
|
||||||
tauri::async_runtime::block_on(async {
|
tauri::async_runtime::block_on(async {
|
||||||
let url = format!("http://127.0.0.1:{}/commands/visible", port);
|
let url = format!("http://127.0.0.1:{port}/commands/visible");
|
||||||
reqwest::get(url).await.unwrap();
|
let resp = reqwest::get(url).await?.text().await?;
|
||||||
Err(())
|
|
||||||
|
if &resp == "ok" {
|
||||||
|
bail!("app exists");
|
||||||
|
}
|
||||||
|
|
||||||
|
log::error!("failed to setup singleton listen server");
|
||||||
|
Ok(())
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -24,7 +31,6 @@ pub fn check_singleton() -> Result<(), ()> {
|
|||||||
/// The embed server only be used to implement singleton process
|
/// The embed server only be used to implement singleton process
|
||||||
/// maybe it can be used as pac server later
|
/// maybe it can be used as pac server later
|
||||||
pub fn embed_server(app_handle: AppHandle) {
|
pub fn embed_server(app_handle: AppHandle) {
|
||||||
let app_handle = app_handle.clone();
|
|
||||||
let port = IVerge::get_singleton_port();
|
let port = IVerge::get_singleton_port();
|
||||||
|
|
||||||
tauri::async_runtime::spawn(async move {
|
tauri::async_runtime::spawn(async move {
|
||||||
|
Loading…
Reference in New Issue
Block a user