Skip to content

Commit

Permalink
feat: 新增http调用
Browse files Browse the repository at this point in the history
  • Loading branch information
Pylogmon committed Mar 24, 2023
1 parent 23e56b3 commit e4f6679
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 21 deletions.
67 changes: 46 additions & 21 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ tauri-plugin-autostart = { git = "https://github.com/tauri-apps/plugins-workspac
reqwest = { version = "0.11", features = ["blocking", "json"] }
once_cell = "1.17.1"
toml = "0.7.3"
tiny_http = "0.12.0"

[target.'cfg(windows)'.dependencies]
windows = {version="0.44.0",features= ["Win32_UI_WindowsAndMessaging", "Win32_Foundation","Win32_UI_HiDpi"] }
Expand Down
13 changes: 13 additions & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ use once_cell::sync::OnceCell;
use selection::get_translate_text;
use shortcut::register_shortcut;
use std::sync::Mutex;
use std::thread;
use tauri::api::notification::Notification;
use tauri::AppHandle;
use tauri::Manager;
use tauri::SystemTrayEvent;
use tauri_plugin_autostart::MacosLauncher;
use tiny_http::{Response, Server};
use trayicon::*;
use utils::*;
use window::*;
Expand All @@ -28,6 +30,7 @@ use window::*;
pub static APP: OnceCell<AppHandle> = OnceCell::new();
// 存待翻译文本
pub struct StringWrapper(pub Mutex<String>);

fn main() {
tauri::Builder::default()
// 单例运行
Expand Down Expand Up @@ -75,6 +78,16 @@ fn main() {
.unwrap();
}
}
thread::spawn(move || {
let server = Server::http("127.0.0.1:60828").unwrap();
for request in server.incoming_requests() {
let mut text = request.url().to_string();
text.remove(0);
popclip_window(text);
let response = Response::from_string("success");
request.respond(response).unwrap();
}
});
Ok(())
})
// 注册Tauri Command
Expand Down

0 comments on commit e4f6679

Please sign in to comment.