桌面应用图标替换为 B-brackets 设计(深藏青 + 白/蓝花括号)

- icon.svg 取自 opsx-icon-options/api/B-brackets.svg,全套光栅重生成:
  icon.icns(iconutil)、icon.ico(PNG-in-ICO 6 尺寸)、16-1024 PNG、Windows Square*/StoreLogo
- 替换 Tauri 脚手架默认五角星图标;GUI 重启实测 Dock 图标已生效
- 服务全量重启:server 8787(官网/文档 200)+ web 5173 + 桌面 GUI
This commit is contained in:
logan committed 2026-09-20 00:14:32 +08:00
1 parent 71a6d986a4
commit 39f4d5addc
161 files changed
+3289 -515

No files matched your search

+150 -7
View File
@@ -329,7 +329,7 @@ checksum = "65c35e4b699c7e15ccbe7ee35c005e4fc0a278d22238a2857e6ce2dadeda1b06"
dependencies = [
"cfg-if",
"cpufeatures 0.3.1",
"rand_core",
"rand_core 0.10.1",
]
[[package]]
@@ -529,6 +529,12 @@ dependencies = [
"syn 3.0.5",
]
[[package]]
name = "data-encoding"
version = "2.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4583a4551df46e2792f82ceeac45e850d2e2d5debba0b91f102385cda5b11f06"
[[package]]
name = "dbus"
version = "0.9.12"
@@ -1086,7 +1092,7 @@ dependencies = [
"js-sys",
"libc",
"r-efi 6.0.0",
"rand_core",
"rand_core 0.10.1",
"wasm-bindgen",
]
@@ -1350,7 +1356,7 @@ dependencies = [
"tokio",
"tokio-rustls",
"tower-service",
"webpki-roots",
"webpki-roots 1.0.9",
]
[[package]]
@@ -2170,13 +2176,17 @@ checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
name = "opsxapi"
version = "0.1.0"
dependencies = [
"futures-util",
"http",
"reqwest 0.12.28",
"serde",
"serde_json",
"tauri",
"tauri-build",
"tokio",
"tokio-tungstenite",
"url",
"uuid",
]
[[package]]
@@ -2373,6 +2383,15 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
[[package]]
name = "ppv-lite86"
version = "0.2.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9"
dependencies = [
"zerocopy",
]
[[package]]
name = "precomputed-hash"
version = "0.1.1"
@@ -2479,7 +2498,7 @@ dependencies = [
"bytes",
"getrandom 0.4.3",
"lru-slab",
"rand",
"rand 0.10.2",
"rand_pcg",
"ring",
"rustc-hash",
@@ -2527,6 +2546,17 @@ version = "6.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf"
[[package]]
name = "rand"
version = "0.8.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e058c7de0b26af77780c769414d6257830bb240f3c38477dbc2c16e5f54d6d4c"
dependencies = [
"libc",
"rand_chacha",
"rand_core 0.6.4",
]
[[package]]
name = "rand"
version = "0.10.2"
@@ -2535,7 +2565,26 @@ checksum = "c7f5fa3a058cd35567ef9bfa5e75732bee0f9e4c55fa90477bef2dfcdbc4be80"
dependencies = [
"chacha20",
"getrandom 0.4.3",
"rand_core",
"rand_core 0.10.1",
]
[[package]]
name = "rand_chacha"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
"rand_core 0.6.4",
]
[[package]]
name = "rand_core"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
dependencies = [
"getrandom 0.2.17",
]
[[package]]
@@ -2550,7 +2599,7 @@ version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "caa0f4137e1c0a72f4c651489402276c8e8e1cf081f3b0ba156d2cbeef09e86a"
dependencies = [
"rand_core",
"rand_core 0.10.1",
]
[[package]]
@@ -2662,7 +2711,7 @@ dependencies = [
"wasm-bindgen",
"wasm-bindgen-futures",
"web-sys",
"webpki-roots",
"webpki-roots 1.0.9",
]
[[package]]
@@ -3041,6 +3090,17 @@ dependencies = [
"stable_deref_trait",
]
[[package]]
name = "sha1"
version = "0.10.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a978451301f4db1d02937a4ab3ccce137717b81826e79b7d49ffe3244a13c3b8"
dependencies = [
"cfg-if",
"cpufeatures 0.2.17",
"digest",
]
[[package]]
name = "sha2"
version = "0.10.9"
@@ -3634,9 +3694,21 @@ dependencies = [
"mio",
"pin-project-lite",
"socket2",
"tokio-macros",
"windows-sys 0.61.2",
]
[[package]]
name = "tokio-macros"
version = "2.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78773a2a397f451582ce068015985c33193cf6dea8b74d2a639fe457b2f07b0e"
dependencies = [
"proc-macro2",
"quote",
"syn 3.0.5",
]
[[package]]
name = "tokio-rustls"
version = "0.26.5"
@@ -3647,6 +3719,22 @@ dependencies = [
"tokio",
]
[[package]]
name = "tokio-tungstenite"
version = "0.24.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "edc5f74e248dc973e0dbb7b74c7e0d6fcc301c694ff50049504004ef4d0cdcd9"
dependencies = [
"futures-util",
"log",
"rustls",
"rustls-pki-types",
"tokio",
"tokio-rustls",
"tungstenite",
"webpki-roots 0.26.11",
]
[[package]]
name = "tokio-util"
version = "0.7.19"
@@ -3872,6 +3960,26 @@ version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
[[package]]
name = "tungstenite"
version = "0.24.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "18e5b8366ee7a95b16d32197d0b2604b43a0be89dc5fac9f8e96ccafbaedda8a"
dependencies = [
"byteorder",
"bytes",
"data-encoding",
"http",
"httparse",
"log",
"rand 0.8.8",
"rustls",
"rustls-pki-types",
"sha1",
"thiserror 1.0.69",
"utf-8",
]
[[package]]
name = "typeid"
version = "1.0.3"
@@ -3968,6 +4076,12 @@ dependencies = [
"url",
]
[[package]]
name = "utf-8"
version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"
[[package]]
name = "utf8_iter"
version = "1.0.4"
@@ -4196,6 +4310,15 @@ dependencies = [
"system-deps",
]
[[package]]
name = "webpki-roots"
version = "0.26.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "521bc38abb08001b01866da9f51eb7c5d647a19260e00054a8c7fd5f9e57f7a9"
dependencies = [
"webpki-roots 1.0.9",
]
[[package]]
name = "webpki-roots"
version = "1.0.9"
@@ -4735,6 +4858,26 @@ dependencies = [
"synstructure",
]
[[package]]
name = "zerocopy"
version = "0.8.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d35102a9f36d089ccae9e4c6802bc118be4487b80aaffc0ab4e0cf5ce92d2873"
dependencies = [
"zerocopy-derive",
]
[[package]]
name = "zerocopy-derive"
version = "0.8.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "146c01f5ab44258da43cf276c74a2763db2ff3969c9c652c3f2de07041d0b2bc"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.119",
]
[[package]]
name = "zerofrom"
version = "0.1.8"
+5 -1
View File
@@ -22,5 +22,9 @@ tauri = { version = "2", features = [] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
reqwest = { version = "0.12", default-features = false, features = ["rustls-tls", "json"] }
tokio = { version = "1", features = ["time"] }
tokio = { version = "1", features = ["macros", "rt-multi-thread", "sync", "time", "net"] }
url = "2"
tokio-tungstenite = { version = "0.24", features = ["rustls-tls-webpki-roots"] }
futures-util = "0.3"
uuid = { version = "1", features = ["v4"] }
http = "1"
@@ -2,10 +2,10 @@
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "default",
"description": "Default capabilities for the OpsxAPI main window",
"windows": [
"main"
],
"windows": ["main"],
"permissions": [
"core:default"
"core:default",
"core:event:default",
"transport"
]
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.2 KiB

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.8 KiB

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.2 KiB

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.8 KiB

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.5 KiB

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1022 B

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 950 B

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.6 KiB

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.0 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

After

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.
Binary file not shown.

Before

Width:  |  Height:  |  Size: 742 B

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

After

Width:  |  Height:  |  Size: 57 KiB

+3 -11
View File
@@ -1,13 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" width="512" height="512" viewBox="0 0 512 512">
<defs>
<linearGradient id="g" x1="0" y1="0" x2="1" y2="1">
<stop offset="0%" stop-color="#0B182C"/>
<stop offset="100%" stop-color="#0F203A"/>
</linearGradient>
</defs>
<rect x="28" y="28" width="456" height="456" rx="110" fill="url(#g)"/>
<text x="256" y="240" text-anchor="middle" font-family="SF Pro Display, Helvetica, Arial" font-size="140" font-weight="700" fill="#FFFFFF">API</text>
<text x="256" y="340" text-anchor="middle" font-family="SF Pro Display, Helvetica, Arial" font-size="42" fill="#94A3B8">Opsx</text>
<circle cx="110" cy="400" r="16" fill="#10B981"/>
<rect width="512" height="512" rx="112" fill="#0B182C"/>
<path d="M200 130c-48 0-70 28-70 70v28c0 22-14 34-34 38v20c20 4 34 16 34 38v28c0 42 22 70 70 70" fill="none" stroke="#FFFFFF" stroke-width="36" stroke-linecap="round"/>
<path d="M312 130c48 0 70 28 70 70v28c0 22 14 34 34 38v20c-20 4-34 16-34 38v28c0 42-22 70-70 70" fill="none" stroke="#3B82F6" stroke-width="36" stroke-linecap="round"/>
</svg>

Before

Width:  |  Height:  |  Size: 738 B

After

Width:  |  Height:  |  Size: 496 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 349 B

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 520 B

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 520 B

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 801 B

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 445 B

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 774 B

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 774 B

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 520 B

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 987 B

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 987 B

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 107 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 957 B

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 8.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 9.7 KiB

@@ -0,0 +1,4 @@
[[permission]]
identifier = "transport"
description = "Allow HTTP/WebSocket native transport"
commands.allow = ["http_send", "ws_connect", "ws_send", "ws_close"]
+173 -16
View File
@@ -1,6 +1,12 @@
use futures_util::{SinkExt, StreamExt};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::sync::Mutex;
use std::time::{Duration, Instant};
use tauri::{AppHandle, Emitter, Manager, State};
use tokio::sync::mpsc;
use tokio_tungstenite::tungstenite::Message;
use uuid::Uuid;
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
@@ -32,10 +38,34 @@ struct HttpResult {
}
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
struct WsSpec {
url: String,
protocols: Option<Vec<String>>,
headers: Option<HashMap<String, String>>,
#[serde(default)]
headers: HashMap<String, String>,
}
#[derive(Clone, Serialize)]
#[serde(rename_all = "camelCase")]
struct WsEvent {
session_id: String,
kind: String,
data: String,
}
enum WsCmd {
Send(String),
Close,
}
struct WsHandle {
tx: mpsc::UnboundedSender<WsCmd>,
}
#[derive(Default)]
struct WsState {
sessions: Mutex<HashMap<String, WsHandle>>,
}
fn validate_http_url(raw: &str) -> Result<url::Url, String> {
@@ -44,13 +74,35 @@ fn validate_http_url(raw: &str) -> Result<url::Url, String> {
"http" | "https" => {}
_ => return Err("only http/https schemes are allowed".into()),
}
match parsed.host_str().unwrap_or("").to_ascii_lowercase().as_str() {
"169.254.169.254" | "metadata.google.internal" => Err("blocked metadata host".into()),
_ => Ok(parsed),
}
}
fn validate_ws_url(raw: &str) -> Result<String, String> {
let mut parsed = url::Url::parse(raw).map_err(|e| format!("invalid URL: {e}"))?;
match parsed.scheme() {
"ws" | "wss" => {}
"http" => {
parsed
.set_scheme("ws")
.map_err(|_| "cannot set ws scheme".to_string())?;
}
"https" => {
parsed
.set_scheme("wss")
.map_err(|_| "cannot set wss scheme".to_string())?;
}
_ => return Err("only ws/wss schemes are allowed".into()),
}
match parsed.host_str().unwrap_or("").to_ascii_lowercase().as_str() {
"169.254.169.254" | "metadata.google.internal" => {
return Err("blocked metadata host".into())
}
_ => {}
}
Ok(parsed)
Ok(parsed.to_string())
}
#[tauri::command]
@@ -71,8 +123,8 @@ async fn http_send(spec: HttpSpec) -> Result<HttpResult, String> {
.build()
.map_err(|e| e.to_string())?;
let mut request = client.request(method, url);
for (key, value) in spec.headers {
request = request.header(&key, &value);
for (key, value) in &spec.headers {
request = request.header(key, value);
}
if let Some(body) = spec.body {
if body.mode != "none" {
@@ -101,30 +153,135 @@ async fn http_send(spec: HttpSpec) -> Result<HttpResult, String> {
}
#[tauri::command]
async fn ws_connect(spec: WsSpec) -> Result<String, String> {
let _ = (&spec.protocols, &spec.headers);
// TODO(week2): hold WebSocket sessions in managed state and emit messages.
Err(format!(
"WebSocket native tunnel is not implemented yet for {} (use browser WS in MVP)",
spec.url
))
async fn ws_connect(
app: AppHandle,
state: State<'_, WsState>,
spec: WsSpec,
) -> Result<String, String> {
let url = validate_ws_url(&spec.url)?;
let session_id = Uuid::new_v4().to_string();
let mut req = http::Request::builder().method("GET").uri(&url);
for (k, v) in &spec.headers {
req = req.header(k.as_str(), v.as_str());
}
if let Some(protocols) = &spec.protocols {
let joined = protocols
.iter()
.map(|s| s.trim())
.filter(|s| !s.is_empty())
.collect::<Vec<_>>()
.join(", ");
if !joined.is_empty() {
req = req.header("Sec-WebSocket-Protocol", joined);
}
}
let request = req
.body(())
.map_err(|e| format!("build ws request: {e}"))?;
let (tx, mut rx) = mpsc::unbounded_channel::<WsCmd>();
{
let mut map = state.sessions.lock().map_err(|e| e.to_string())?;
map.insert(session_id.clone(), WsHandle { tx });
}
let sid = session_id.clone();
let app2 = app.clone();
tauri::async_runtime::spawn(async move {
let emit = |kind: &str, data: String| {
let _ = app2.emit(
"ws-event",
WsEvent {
session_id: sid.clone(),
kind: kind.to_string(),
data,
},
);
};
match tokio_tungstenite::connect_async(request).await {
Ok((ws, _)) => {
emit("status", "open".into());
let (mut write, mut read) = ws.split();
loop {
tokio::select! {
cmd = rx.recv() => {
match cmd {
Some(WsCmd::Send(data)) => {
if write.send(Message::Text(data.into())).await.is_err() {
emit("status", "error".into());
break;
}
}
Some(WsCmd::Close) | None => {
let _ = write.close().await;
break;
}
}
}
msg = read.next() => {
match msg {
Some(Ok(Message::Text(t))) => emit("message", t.to_string()),
Some(Ok(Message::Binary(b))) => {
emit("message", format!("[binary {} bytes]", b.len()))
}
Some(Ok(Message::Close(_))) | None => break,
Some(Ok(_)) => {}
Some(Err(e)) => {
emit("message", format!("[ws error] {e}"));
emit("status", "error".into());
break;
}
}
}
}
}
emit("status", "closed".into());
}
Err(e) => {
emit("message", format!("[ws_connect error] {e}"));
emit("status", "error".into());
emit("status", "closed".into());
}
}
if let Some(st) = app2.try_state::<WsState>() {
if let Ok(mut map) = st.sessions.lock() {
map.remove(&sid);
}
}
});
Ok(session_id)
}
#[tauri::command]
async fn ws_send(session_id: String, data: String) -> Result<(), String> {
let _ = (session_id, data);
Err("WebSocket native send is a Week 2 stub".into())
async fn ws_send(state: State<'_, WsState>, session_id: String, data: String) -> Result<(), String> {
let map = state.sessions.lock().map_err(|e| e.to_string())?;
let handle = map
.get(&session_id)
.ok_or_else(|| format!("unknown ws session {session_id}"))?;
handle
.tx
.send(WsCmd::Send(data))
.map_err(|_| "ws session closed".to_string())?;
Ok(())
}
#[tauri::command]
async fn ws_close(session_id: String) -> Result<(), String> {
let _ = session_id;
async fn ws_close(state: State<'_, WsState>, session_id: String) -> Result<(), String> {
let mut map = state.sessions.lock().map_err(|e| e.to_string())?;
if let Some(handle) = map.remove(&session_id) {
let _ = handle.tx.send(WsCmd::Close);
}
Ok(())
}
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.manage(WsState::default())
.invoke_handler(tauri::generate_handler![
http_send,
ws_connect,