feat(): 优化状态栏

This commit is contained in:
tsl
2026-03-10 15:20:06 +08:00
parent da677a033e
commit 17618ec3a0
11 changed files with 135 additions and 52 deletions
+31 -23
View File
@@ -2,7 +2,7 @@ use std::io::{Read, Write};
use std::net::TcpListener;
use std::sync::atomic::{AtomicU16, Ordering};
use tauri::{Emitter, Manager};
use tauri::Emitter;
use tauri_plugin_autostart::MacosLauncher;
mod notification;
@@ -25,34 +25,42 @@ fn start_notification_callback_server(app_handle: tauri::AppHandle) {
});
}
fn handle_callback_request(app_handle: &tauri::AppHandle, mut stream: std::net::TcpStream) {
let mut buf = [0u8; 1024];
let n = stream.read(&mut buf).unwrap_or(0);
let request = String::from_utf8_lossy(&buf[..n]);
let (action, html) = if request.contains("GET /postpone") {
let _ = app_handle.emit("notification-action", "postpone_1h");
if let Some(w) = app_handle.get_webview_window("main") {
let _ = w.unminimize();
let _ = w.show();
let _ = w.set_focus();
}
("postpone", "已推迟1小时,监控将在1小时后恢复")
} else {
("unknown", "未知操作")
};
log::info!("Notification callback: {}", action);
let body = format!(
fn simple_page(msg: &str) -> String {
format!(
"<!DOCTYPE html><html><head><meta charset='utf-8'></head>\
<body style='display:flex;justify-content:center;align-items:center;\
height:80vh;font-family:system-ui;color:#333'>\
<div style='text-align:center'><h2>{}</h2>\
<p style='color:#888'>此标签页可以关闭</p></div></body>\
<script>setTimeout(()=>window.close(),1500)</script></html>",
html
);
msg
)
}
fn redirect_page(url: &str) -> String {
format!(
"<!DOCTYPE html><html><head><meta charset='utf-8'>\
<meta http-equiv='refresh' content='0;url={url}'></head>\
<body>正在跳转...</body></html>"
)
}
fn handle_callback_request(app_handle: &tauri::AppHandle, mut stream: std::net::TcpStream) {
let mut buf = [0u8; 1024];
let n = stream.read(&mut buf).unwrap_or(0);
let request = String::from_utf8_lossy(&buf[..n]);
let (action, body) = if request.contains("GET /postpone") {
let _ = app_handle.emit("notification-action", "postpone_1h");
("postpone", simple_page("已推迟1小时,监控将在1小时后恢复"))
} else if request.contains("GET /handle") {
let _ = app_handle.emit("notification-action", "go_handle");
("handle", redirect_page("https://crm.yunvip123.com/index.html"))
} else {
("unknown", simple_page("未知操作"))
};
log::info!("Notification callback: {}", action);
let response = format!(
"HTTP/1.1 200 OK\r\nContent-Type: text/html; charset=utf-8\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{}",
+1 -1
View File
@@ -37,7 +37,7 @@ pub fn send_interactive_toast(
</visual>
<actions>
<action content="推迟1小时" arguments="http://127.0.0.1:{port}/postpone" activationType="protocol"/>
<action content="去处理" arguments="https://crm.yunvip123.com/index.html" activationType="protocol"/>
<action content="去处理" arguments="http://127.0.0.1:{port}/handle" activationType="protocol"/>
</actions>
</toast>"#,
port = port,
+1 -1
View File
@@ -1,7 +1,7 @@
{
"$schema": "https://schema.tauri.app/config/2",
"productName": "工单系统监测",
"version": "0.1.1",
"version": "0.1.2",
"identifier": "com.administrator.tauri-app",
"build": {
"beforeDevCommand": "pnpm dev",