feat: compatible with macos(wip)

This commit is contained in:
GyDi
2021-12-29 18:49:38 +08:00
parent 63b01376d6
commit 1d87f78088
4 changed files with 22 additions and 22 deletions

View File

@@ -1,6 +1,7 @@
extern crate warp;
use port_scanner::local_port_available;
use std::sync::{Arc, Mutex};
use tauri::{AppHandle, Manager};
use warp::Filter;
@@ -22,15 +23,16 @@ 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: &AppHandle) {
let window = app.get_window("main").unwrap();
let commands = warp::path!("commands" / "visible").map(move || {
window.show().unwrap();
window.set_focus().unwrap();
return format!("ok");
});
let window = Arc::new(Mutex::new(app.get_window("main").unwrap()));
tauri::async_runtime::spawn(async move {
let commands = warp::path!("commands" / "visible").map(move || {
let win = window.lock().unwrap();
win.show().unwrap();
win.set_focus().unwrap();
return format!("ok");
});
warp::serve(commands)
.bind(([127, 0, 0, 1], SERVER_PORT))
.await;