-
-
Notifications
You must be signed in to change notification settings - Fork 122
feat: rust托盘图标 #338
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
feat: rust托盘图标 #338
Changes from 37 commits
a29b0f6
c79bd1e
5ee6882
0a8e434
cfa8b43
2b5e784
18f3265
40490f5
1338d62
96a3769
8f7c9e9
f6af9ce
55b6e37
9dda020
c8bdd30
2d53cd8
d37093e
ea5f5a3
67cbb39
8f96c01
5d810c0
0dbf3b1
b25b160
b51d02b
84e48e1
3993895
fbbd666
aeec553
cd0acbd
f166c19
8bff078
67ae4a0
43a8f6e
8f5eb5d
d0c2871
d903986
0206257
3af156f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,121 @@ | ||||||||||||||
| # rust_tray.cmake | ||||||||||||||
| # CMake configuration for building and linking the Rust tray library | ||||||||||||||
|
|
||||||||||||||
| set(RUST_TRAY_SOURCE_DIR "${CMAKE_SOURCE_DIR}/rust_tray") | ||||||||||||||
| set(RUST_TARGET_DIR "${CMAKE_BINARY_DIR}/rust_tray") | ||||||||||||||
|
|
||||||||||||||
| # Determine the Rust target and output filename based on platform | ||||||||||||||
| if(WIN32) | ||||||||||||||
| # Windows uses MinGW/UCRT toolchain - must use gnu target | ||||||||||||||
| set(RUST_TARGET "x86_64-pc-windows-gnu") | ||||||||||||||
| set(RUST_LIB_NAME "libtray.a") | ||||||||||||||
| elseif(APPLE) | ||||||||||||||
| set(RUST_LIB_NAME "libtray.a") | ||||||||||||||
| # Check for ARM64 | ||||||||||||||
| if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64" OR CMAKE_OSX_ARCHITECTURES MATCHES "arm64") | ||||||||||||||
| set(RUST_TARGET "aarch64-apple-darwin") | ||||||||||||||
| else() | ||||||||||||||
| set(RUST_TARGET "x86_64-apple-darwin") | ||||||||||||||
| endif() | ||||||||||||||
| else() | ||||||||||||||
| set(RUST_LIB_NAME "libtray.a") | ||||||||||||||
| # Check for ARM64 | ||||||||||||||
| if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64") | ||||||||||||||
| set(RUST_TARGET "aarch64-unknown-linux-gnu") | ||||||||||||||
| else() | ||||||||||||||
| set(RUST_TARGET "x86_64-unknown-linux-gnu") | ||||||||||||||
| endif() | ||||||||||||||
| endif() | ||||||||||||||
|
|
||||||||||||||
| # Set the output path based on build type | ||||||||||||||
| if(CMAKE_BUILD_TYPE STREQUAL "Debug") | ||||||||||||||
| set(RUST_BUILD_TYPE "debug") | ||||||||||||||
| set(CARGO_BUILD_FLAGS "") | ||||||||||||||
| else() | ||||||||||||||
| set(RUST_BUILD_TYPE "release") | ||||||||||||||
| set(CARGO_BUILD_FLAGS "--release") | ||||||||||||||
| endif() | ||||||||||||||
|
|
||||||||||||||
| # Output path: target/<target>/<profile>/ | ||||||||||||||
| set(RUST_OUTPUT_LIB "${RUST_TARGET_DIR}/${RUST_TARGET}/${RUST_BUILD_TYPE}/${RUST_LIB_NAME}") | ||||||||||||||
|
|
||||||||||||||
| # Find cargo | ||||||||||||||
| find_program(CARGO_EXECUTABLE cargo HINTS $ENV{HOME}/.cargo/bin $ENV{USERPROFILE}/.cargo/bin) | ||||||||||||||
| if(NOT CARGO_EXECUTABLE) | ||||||||||||||
| message(FATAL_ERROR "Cargo (Rust package manager) not found. Please install Rust: https://rustup.rs/") | ||||||||||||||
| endif() | ||||||||||||||
|
|
||||||||||||||
| message(STATUS "Found Cargo: ${CARGO_EXECUTABLE}") | ||||||||||||||
| message(STATUS "Rust target: ${RUST_TARGET}") | ||||||||||||||
| message(STATUS "Rust tray library will be built at: ${RUST_OUTPUT_LIB}") | ||||||||||||||
|
|
||||||||||||||
| # Custom command to build the Rust library | ||||||||||||||
| add_custom_command( | ||||||||||||||
| OUTPUT ${RUST_OUTPUT_LIB} | ||||||||||||||
| COMMAND ${CMAKE_COMMAND} -E env | ||||||||||||||
| CARGO_TARGET_DIR=${RUST_TARGET_DIR} | ||||||||||||||
| ${CARGO_EXECUTABLE} build | ||||||||||||||
| --manifest-path ${RUST_TRAY_SOURCE_DIR}/Cargo.toml | ||||||||||||||
| --target ${RUST_TARGET} | ||||||||||||||
| ${CARGO_BUILD_FLAGS} | ||||||||||||||
| WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} | ||||||||||||||
| COMMENT "Building Rust tray library (${RUST_BUILD_TYPE})" | ||||||||||||||
| DEPENDS | ||||||||||||||
| ${RUST_TRAY_SOURCE_DIR}/Cargo.toml | ||||||||||||||
| ${RUST_TRAY_SOURCE_DIR}/build.rs | ||||||||||||||
| ${RUST_TRAY_SOURCE_DIR}/src/lib.rs | ||||||||||||||
| ${RUST_TRAY_SOURCE_DIR}/src/i18n.rs | ||||||||||||||
| ${RUST_TRAY_SOURCE_DIR}/src/actions.rs | ||||||||||||||
|
||||||||||||||
| ${RUST_TRAY_SOURCE_DIR}/src/actions.rs | |
| ${RUST_TRAY_SOURCE_DIR}/src/actions.rs | |
| ${RUST_TRAY_SOURCE_DIR}/src/dialogs.rs | |
| ${RUST_TRAY_SOURCE_DIR}/src/menu.rs | |
| ${RUST_TRAY_SOURCE_DIR}/src/menu_items.rs | |
| ${RUST_TRAY_SOURCE_DIR}/src/notification.rs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DEPENDS 列表不完整,可能导致增量构建失效
根据 lib.rs 中声明的模块,src/ 目录下还有 dialogs.rs、menu.rs、menu_items.rs 和 notification.rs,但这些文件未包含在依赖列表中。当这些文件修改时,CMake 不会触发重新构建。
🔧 建议的修复方案
DEPENDS
${RUST_TRAY_SOURCE_DIR}/Cargo.toml
${RUST_TRAY_SOURCE_DIR}/build.rs
${RUST_TRAY_SOURCE_DIR}/src/lib.rs
${RUST_TRAY_SOURCE_DIR}/src/i18n.rs
${RUST_TRAY_SOURCE_DIR}/src/actions.rs
+ ${RUST_TRAY_SOURCE_DIR}/src/dialogs.rs
+ ${RUST_TRAY_SOURCE_DIR}/src/menu.rs
+ ${RUST_TRAY_SOURCE_DIR}/src/menu_items.rs
+ ${RUST_TRAY_SOURCE_DIR}/src/notification.rs
VERBATIM或者使用 file(GLOB ...) 自动收集所有 .rs 文件(但需注意 GLOB 在新增文件时的限制)。
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@cmake/targets/rust_tray.cmake` around lines 63 - 69, The DEPENDS list for the
rust tray target is incomplete: files referenced by lib.rs (dialogs.rs, menu.rs,
menu_items.rs, notification.rs) are missing so CMake won't re-run when they
change; update the DEPENDS block that references
${RUST_TRAY_SOURCE_DIR}/Cargo.toml, build.rs, src/lib.rs, src/i18n.rs,
src/actions.rs to also include ${RUST_TRAY_SOURCE_DIR}/src/dialogs.rs,
${RUST_TRAY_SOURCE_DIR}/src/menu.rs, ${RUST_TRAY_SOURCE_DIR}/src/menu_items.rs
and ${RUST_TRAY_SOURCE_DIR}/src/notification.rs (or replace the explicit list by
a file(GLOB ...) over ${RUST_TRAY_SOURCE_DIR}/src/*.rs if you prefer
auto-collecting files, noting GLOB caveats) so changes to those modules trigger
incremental rebuilds.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # Cargo configuration for MinGW builds | ||
|
|
||
| [target.x86_64-pc-windows-gnu] | ||
| # Static link libgcc to avoid runtime DLL dependency | ||
| rustflags = ["-C", "link-arg=-static-libgcc"] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| /target/ | ||
| /Cargo.lock |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,35 @@ | ||||||
| [package] | ||||||
| name = "sunshine_tray" | ||||||
| version = "0.1.0" | ||||||
| edition = "2021" | ||||||
| build = "build.rs" | ||||||
| description = "Windows-only system tray implementation for Sunshine" | ||||||
|
||||||
| description = "Windows-only system tray implementation for Sunshine" | |
| description = "System tray implementation for Sunshine (currently targeting Windows)" |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,68 @@ | ||||||||||||||||||||||||||||||||||||
| # Rust Tray Library | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| This directory contains a Rust implementation of the system tray library, designed to replace the original C `tray` library. | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| ## Features | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| - Cross-platform support (Windows, Linux, macOS) | ||||||||||||||||||||||||||||||||||||
| - Compatible C API matching the original `tray.h` header | ||||||||||||||||||||||||||||||||||||
| - Uses the `tray-icon` Rust crate for the underlying implementation | ||||||||||||||||||||||||||||||||||||
| - Better maintainability and reduced cross-platform adaptation code | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+7
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. README 仍把当前实现写成跨平台。
Also applies to: 28-31 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| ## Prerequisites | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| - [Rust](https://rustup.rs/) (latest stable version recommended) | ||||||||||||||||||||||||||||||||||||
| - Cargo (comes with Rust) | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| ## Building | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| The library is automatically built by CMake when `SUNSHINE_USE_RUST_TRAY=ON` is set. | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| ### Manual Build | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| ```bash | ||||||||||||||||||||||||||||||||||||
| cd rust_tray | ||||||||||||||||||||||||||||||||||||
| cargo build --release | ||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| The static library will be generated at: | ||||||||||||||||||||||||||||||||||||
| - Windows (MSVC): `target/release/tray.lib` | ||||||||||||||||||||||||||||||||||||
| - Windows (MinGW): `target/release/libtray.a` | ||||||||||||||||||||||||||||||||||||
| - Linux/macOS: `target/release/libtray.a` | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| ## CMake Integration | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| To enable the Rust tray library, configure CMake with: | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| ```bash | ||||||||||||||||||||||||||||||||||||
| cmake -DSUNSHINE_USE_RUST_TRAY=ON .. | ||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||
|
ShadowLemoon marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| ## API | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| The library provides the following C-compatible functions: | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| - `tray_init(struct tray *tray)` - Initialize the tray icon | ||||||||||||||||||||||||||||||||||||
| - `tray_update(struct tray *tray)` - Update the tray icon and menu | ||||||||||||||||||||||||||||||||||||
| - `tray_loop(int blocking)` - Run one iteration of the UI loop | ||||||||||||||||||||||||||||||||||||
| - `tray_exit(void)` - Terminate the UI loop | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| See `../third-party/tray/src/tray.h` for the complete API definition. | ||||||||||||||||||||||||||||||||||||
|
ShadowLemoon marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| ## Architecture | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||
| rust_tray/ | ||||||||||||||||||||||||||||||||||||
| ├── Cargo.toml # Rust package manifest | ||||||||||||||||||||||||||||||||||||
| ├── build.rs # Build script (platform-specific setup) | ||||||||||||||||||||||||||||||||||||
| ├── src/ | ||||||||||||||||||||||||||||||||||||
| │ ├── lib.rs # Main library implementation | ||||||||||||||||||||||||||||||||||||
| │ └── ffi.rs # FFI type definitions | ||||||||||||||||||||||||||||||||||||
|
ShadowLemoon marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||
| └── README.md # This file | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+56
to
+61
|
||||||||||||||||||||||||||||||||||||
| ├── Cargo.toml # Rust package manifest | |
| ├── build.rs # Build script (platform-specific setup) | |
| ├── src/ | |
| │ ├── lib.rs # Main library implementation | |
| │ └── ffi.rs # FFI type definitions | |
| └── README.md # This file | |
| ├── Cargo.toml # Rust package manifest | |
| ├── build.rs # Build script (platform-specific setup) | |
| ├── src/ | |
| │ ├── lib.rs # Main library implementation and C FFI | |
| │ ├── i18n.rs # Internationalization and localized strings | |
| │ ├── actions.rs # Actions and callbacks triggered from the tray | |
| │ ├── dialogs.rs # Platform-specific dialog helpers | |
| │ ├── menu.rs # Tray menu construction and management | |
| │ ├── menu_items.rs # Individual tray menu item definitions | |
| │ └── notification.rs # User notifications from the tray | |
| └── README.md # This file |
Copilot
AI
Jan 24, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The README claims "No changes are required to src/system_tray.cpp" but this is incorrect - the PR actually replaces system_tray.cpp with system_tray_rust.cpp (as shown in common.cmake line 120). This statement is misleading and should be removed or updated to reflect the actual changes made.
| - No changes are required to `src/system_tray.cpp` | |
| - The original `third-party/tray/src/tray.h` header is still used for the C++ code | |
| - When `SUNSHINE_USE_RUST_TRAY=ON` is enabled, the Rust-based implementation is used in place of the original `src/system_tray.cpp` implementation via CMake | |
| - The original `third-party/tray/src/tray.h` header is still used as the public API header for the C++ code |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
架构章节已经落后于当前实现。
目录树没有列出这次新增的 actions.rs、menu.rs、notification.rs、dialogs.rs,下面还写着“不需要修改 src/system_tray.cpp”,但当前接入点已经是 src/system_tray_rust.cpp。另外这个代码块缺少语言标记,也会继续触发 markdownlint MD040。
🧰 Tools
🪛 markdownlint-cli2 (0.22.0)
[warning] 54-54: Fenced code blocks should have a language specified
(MD040, fenced-code-language)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@rust_tray/README.md` around lines 54 - 68, The README's architecture section
is outdated: update the directory tree to list the new Rust files (actions.rs,
menu.rs, notification.rs, dialogs.rs) under src and replace the note that
mentions src/system_tray.cpp with the current entry point
src/system_tray_rust.cpp; also add a language tag to the code fence (e.g.,
```text or ```bash) to satisfy markdownlint MD040 so the tree block is properly
marked. Ensure the paragraph referencing compatibility/third-party headers still
applies or update it if the integration changed, and keep all edits inside
README.md to reflect the new filenames and entry point.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| //! Build script for sunshine_tray | ||
| //! | ||
| //! Note: We manually define the C structures in lib.rs instead of using bindgen | ||
| //! to avoid requiring LLVM/Clang installation on all build machines. | ||
|
|
||
| fn main() { | ||
| // Tell cargo to rerun this script if the header file changes | ||
| println!("cargo:rerun-if-changed=../third-party/tray/src/tray.h"); | ||
| println!("cargo:rerun-if-changed=build.rs"); | ||
|
|
||
| // Note: We manually define the FFI structures in src/ffi.rs | ||
| // to match the original tray.h header file. | ||
|
|
||
| // Platform-specific linker flags | ||
| #[cfg(target_os = "windows")] | ||
| { | ||
| println!("cargo:rustc-link-lib=user32"); | ||
| println!("cargo:rustc-link-lib=gdi32"); | ||
| println!("cargo:rustc-link-lib=shell32"); | ||
| println!("cargo:rustc-link-lib=ole32"); | ||
| println!("cargo:rustc-link-lib=comctl32"); | ||
| } | ||
|
Comment on lines
+14
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# 验证 CMake 中定义的平台库是否与 build.rs 重复
echo "=== CMake RUST_TRAY_PLATFORM_LIBS ==="
rg -A 20 'RUST_TRAY_PLATFORM_LIBS' cmake/targets/rust_tray.cmake
echo ""
echo "=== build.rs link-lib ==="
cat rust_tray/build.rsRepository: AlkaidLab/foundation-sunshine Length of output: 1734 build.rs 中的 Windows 库链接不完整且存在重复
当通过 cargo 独立构建此 Rust 库时,将缺少这些关键依赖,可能导致链接或运行时失败。建议:
🤖 Prompt for AI Agents |
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.