Skip to content

Commit

Permalink
perf: 后移http服务器开启时机,提升响应速度
Browse files Browse the repository at this point in the history
  • Loading branch information
Pylogmon committed May 22, 2023
1 parent d853755 commit 0d086b5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src-tauri/src/config.rs
Expand Up @@ -163,9 +163,9 @@ pub fn create_background_window() {
}

#[tauri::command]
pub fn set_proxy(proxy:&str)->Result<(),()> {
pub fn set_proxy(proxy: &str) -> Result<(), ()> {
std::env::set_var("http_proxy", proxy);
std::env::set_var("https_proxy", proxy);
std::env::set_var("all_proxy", proxy);
Ok(())
}
}
24 changes: 12 additions & 12 deletions src-tauri/src/main.rs
Expand Up @@ -32,18 +32,6 @@ pub struct StringWrapper(pub Mutex<String>);
fn main() {
#[cfg(target_os = "linux")]
std::env::set_var("GDK_BACKEND", "x11");
use std::thread;
use tiny_http::{Response, Server};
thread::spawn(move || {
let server = Server::http("127.0.0.1:60828").unwrap();
for mut request in server.incoming_requests() {
let mut content = String::new();
request.as_reader().read_to_string(&mut content).unwrap();
popclip_window(content);
let response = Response::from_string("success");
request.respond(response).unwrap();
}
});
tauri::Builder::default()
// 单例运行
.plugin(tauri_plugin_single_instance::init(|app, argv, cwd| {
Expand Down Expand Up @@ -84,6 +72,18 @@ fn main() {
if is_first {
on_config_click(app_handle);
}
use std::thread;
use tiny_http::{Response, Server};
thread::spawn(move || {
let server = Server::http("127.0.0.1:60828").unwrap();
for mut request in server.incoming_requests() {
let mut content = String::new();
request.as_reader().read_to_string(&mut content).unwrap();
popclip_window(content);
let response = Response::from_string("success");
request.respond(response).unwrap();
}
});
// 注册全局快捷键
match register_shortcut("all") {
Ok(_) => {}
Expand Down
4 changes: 2 additions & 2 deletions src-tauri/src/selection.rs
Expand Up @@ -7,10 +7,10 @@ pub fn get_selection_text() -> Result<String, String> {
// if let Ok(session_type) = var("XDG_SESSION_TYPE") {
// match session_type.as_str() {
// "x11" => {
use crate::APP;
use std::time::Duration;
use tauri::Manager;
use x11_clipboard::Clipboard;
use crate::APP;

if let Ok(clipboard) = Clipboard::new() {
if let Ok(primary) = clipboard.load(
Expand Down Expand Up @@ -111,7 +111,7 @@ pub fn get_selection_text() -> Result<String, String> {
// if new.trim() == text.trim() {
// Ok("".to_string())
// } else {
Ok(new)
Ok(new)
// }
} else {
Ok("".to_string())
Expand Down
4 changes: 2 additions & 2 deletions src-tauri/src/window.rs
Expand Up @@ -225,7 +225,7 @@ pub fn translate_window() {
match handle.get_window("translator") {
Some(window) => {
window.set_focus().unwrap();
window.emit("new_selection",text ).unwrap();
window.emit("new_selection", text).unwrap();
}
None => {
let _window = build_translate_window("translator", "Translator", handle).unwrap();
Expand Down Expand Up @@ -256,7 +256,7 @@ pub fn popclip_window(text: String) {
match handle.get_window("popclip") {
Some(window) => {
window.set_focus().unwrap();
window.emit("new_selection",text ).unwrap();
window.emit("new_selection", text).unwrap();
}
None => {
let _window = build_translate_window("popclip", "PopClip", handle).unwrap();
Expand Down

0 comments on commit 0d086b5

Please sign in to comment.