Skip to content

Commit b690d3b

Browse files
committed
feat(toast): 新增web后台管理
1 parent 01b77f5 commit b690d3b

22 files changed

Lines changed: 1813 additions & 43 deletions

File tree

Cargo.lock

Lines changed: 139 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
[package]
22
name = "use"
33
description = "像 BusyBox 一样, 把多个实用命令集合在一个二进制文件中"
4-
version = "1.0.0"
4+
version = "1.0.5"
55
edition = "2024"
66

77
[dependencies]
88
axum = "0.8.4"
9+
axum-extra = { version = "0.12.3", features = ["typed-header"] }
910
clap = { version = "4.5.40", features = ["derive"] }
1011
ifcfg = "0.1.2"
1112
macro-log = "0.3.0"
13+
mime = "0.3.17"
1214
normalize-path = "0.2.1"
1315
once_cell = "1.21.3"
1416
regex = "1.11.1"

build.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ fn main() {
1515
});
1616
cc.compile("ffi");
1717
}
18+
19+
#[cfg(not(windows))]
20+
fn main() {
21+
}

src/args.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub enum Commands {
1515
RBS(crate::mods::rbs::Param),
1616
RBC(crate::mods::rbc::Param),
1717
Oneport(crate::mods::oneport::Param),
18+
#[cfg(windows)]
1819
Toast(crate::mods::toast::Param),
1920
Install(crate::mods::install::Param),
2021
}

src/ffi/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::ffi::{c_int, c_uchar, c_uint};
22

3+
#[cfg(windows)]
34
unsafe extern "C" {
45
unsafe fn init_float_window() -> c_int;
56
unsafe fn toast(msg: *const u16, time: c_uint);

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ async fn main() -> tokio::io::Result<()> {
1515
args::Commands::RBS(param) => mods::rbs::main(param).await,
1616
args::Commands::RBC(param) => mods::rbc::main(param).await,
1717
args::Commands::Oneport(param) => mods::oneport::main(param).await,
18+
#[cfg(windows)]
1819
args::Commands::Toast(param) => mods::toast::main(param).await,
1920
args::Commands::Install(param) => mods::install::main(param).await,
2021
}

src/mods/toast/mod.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
mod web;
2+
13
use axum::extract::Query;
24
use clap::Parser;
35
use serde::Deserialize;
@@ -8,7 +10,7 @@ use crate::{ffi::{set_toast_alpha, set_toast_position, set_toast_wh, show_toast}
810
#[derive(Parser, Debug, Clone)]
911
#[command(version = "0.0.1", about = "Windows文本消息吐司API服务", long_about = "Windows文本消息吐司API服务
1012
API:
11-
- GET http://IP:PORT/toast?msg=123456&time=2000 (设置消息与显示时长)
13+
- GET http://IP:PORT/toast?msg=123456&time=2000 (设置消息与显示时长[毫秒], 0为永久显示)
1214
- GET http://IP:PORT/setpos?x=1000&y=550 (设置窗口位置)
1315
- GET http://IP:PORT/setwh?w=860&h=200 (设置窗口宽高)
1416
- GET http://IP:PORT/setalpha?alpha=190 (设置窗口整体不透明度, 0为完全透明, 255为完全不透明)
@@ -62,12 +64,21 @@ async fn handler_set_alpha(Query(alpha): Query<Alpha>) {
6264
set_toast_alpha(alpha.alpha);
6365
}
6466

67+
#[cfg(windows)]
68+
#[allow(unused)]
69+
unsafe extern "system" {
70+
fn FreeConsole();
71+
fn AllocConsole();
72+
fn WinExec(cmd: *const u8, cmdShow: u8);
73+
}
74+
6575
pub async fn main(param: Param) -> tokio::io::Result<()> {
6676
let router = axum::Router::new()
6777
.route("/toast", axum::routing::get(handler))
6878
.route("/setpos", axum::routing::get(handler_setpos))
6979
.route("/setwh", axum::routing::get(handler_setwh))
7080
.route("/setalpha", axum::routing::get(handler_set_alpha))
81+
.fallback_service(web::route_assets())
7182
.layer(CorsLayer::permissive())
7283
.with_state(param.clone())
7384
.into_make_service();
@@ -84,6 +95,12 @@ pub async fn main(param: Param) -> tokio::io::Result<()> {
8495
show_toast("服务已启动, 调用/toast接口, 您的消息将在这里显示", 0);
8596
set_toast_position(1000, 550);
8697
});
98+
#[cfg(windows)]
99+
unsafe {
100+
WinExec(format!("explorer http://127.0.0.1:{}\0", port).as_ptr(), 0);
101+
// FreeConsole();
102+
// AllocConsole();
103+
}
87104
axum::serve(listener, router).await?;
88105
Ok(())
89106
}

0 commit comments

Comments
 (0)