mirror of
https://github.com/aiclientproxy/proxycast.git
synced 2026-09-24 23:10:56 +08:00
fix: 消除跨平台编译警告
修复 macOS 和 Linux 平台上的 Rust 编译警告,实现零警告编译。 主要更改: - 在 lib.rs 添加全局 #![allow(unexpected_cfgs)] 抑制 objc 宏的 cfg 警告 - 修复 runner.rs 中 macOS 特定的 Emitter/Listener trait 导入 - 修复 capture.rs 中 warn 宏的条件导入 - 修复 window.rs 和 update_window.rs 中的变量命名和 lint 属性 - 修复 provider_pool_cmd.rs 中的 home 变量命名 技术细节: - 使用 #[cfg(target_os = "macos")] 条件导入平台特定模块 - 使用 #[cfg_attr] 条件属性抑制非目标平台的未使用变量警告 - 在 crate 根级别抑制外部依赖(cocoa/objc)的内部警告 验证: - macOS: cargo check --no-default-features 零警告 - Linux: cargo check --no-default-features 零警告
This commit is contained in:
@@ -5,6 +5,9 @@
|
||||
use std::sync::Arc;
|
||||
use tauri::Manager;
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
use tauri::{Emitter, Listener};
|
||||
|
||||
use crate::commands;
|
||||
use crate::tray::{TrayIconStatus, TrayManager, TrayStateSnapshot};
|
||||
|
||||
|
||||
@@ -2934,7 +2934,11 @@ pub struct PlaywrightStatus {
|
||||
|
||||
/// 获取系统 Chrome 可执行文件路径
|
||||
fn get_system_chrome_path() -> Option<String> {
|
||||
let _home = dirs::home_dir().unwrap_or_else(|| PathBuf::from("."));
|
||||
#[cfg_attr(
|
||||
not(any(target_os = "macos", target_os = "windows")),
|
||||
allow(unused_variables)
|
||||
)]
|
||||
let home = dirs::home_dir().unwrap_or_else(|| PathBuf::from("."));
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
//!
|
||||
//! 这是一个 Tauri 应用,提供 AI API 的代理和管理功能。
|
||||
|
||||
// 抑制 objc crate 宏内部的 unexpected_cfgs 警告
|
||||
// 该警告来自 cocoa/objc 依赖的 msg_send! 宏,是已知的 issue
|
||||
#![allow(unexpected_cfgs)]
|
||||
|
||||
// 核心模块
|
||||
pub mod agent;
|
||||
pub mod app;
|
||||
|
||||
@@ -6,6 +6,9 @@ use std::path::PathBuf;
|
||||
use tauri::AppHandle;
|
||||
use tracing::{debug, error, info};
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
use tracing::warn;
|
||||
|
||||
/// 截图错误类型
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum CaptureError {
|
||||
|
||||
@@ -8,8 +8,10 @@ use tauri::{AppHandle, Manager, WebviewUrl, WebviewWindowBuilder};
|
||||
use tracing::{debug, info};
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
#[allow(deprecated)]
|
||||
use cocoa::appkit::{NSColor, NSWindow};
|
||||
#[cfg(target_os = "macos")]
|
||||
#[allow(deprecated)]
|
||||
use cocoa::base::{id, nil};
|
||||
|
||||
/// 窗口错误类型
|
||||
@@ -164,6 +166,7 @@ pub fn open_floating_window(app: &AppHandle, image_path: &Path) -> Result<(), Wi
|
||||
{
|
||||
use objc::{msg_send, sel, sel_impl};
|
||||
if let Ok(ns_win) = window.ns_window() {
|
||||
#[allow(deprecated, unexpected_cfgs)]
|
||||
unsafe {
|
||||
let ns_window = ns_win as id;
|
||||
// 设置窗口背景透明
|
||||
@@ -202,24 +205,25 @@ pub fn open_floating_window(app: &AppHandle, image_path: &Path) -> Result<(), Wi
|
||||
let (x, y) = calculate_window_position(app);
|
||||
|
||||
// 创建悬浮窗口(启用透明)
|
||||
let _window =
|
||||
WebviewWindowBuilder::new(app, FLOATING_WINDOW_LABEL, WebviewUrl::App(url.into()))
|
||||
.inner_size(WINDOW_WIDTH, WINDOW_HEIGHT)
|
||||
.position(x, y)
|
||||
.decorations(false)
|
||||
.always_on_top(true)
|
||||
.skip_taskbar(true)
|
||||
.visible(true)
|
||||
.focused(true)
|
||||
.transparent(true)
|
||||
.build()
|
||||
.map_err(|e| WindowError::CreateFailed(format!("{}", e)))?;
|
||||
#[cfg_attr(not(target_os = "macos"), allow(unused_variables))]
|
||||
let window = WebviewWindowBuilder::new(app, FLOATING_WINDOW_LABEL, WebviewUrl::App(url.into()))
|
||||
.inner_size(WINDOW_WIDTH, WINDOW_HEIGHT)
|
||||
.position(x, y)
|
||||
.decorations(false)
|
||||
.always_on_top(true)
|
||||
.skip_taskbar(true)
|
||||
.visible(true)
|
||||
.focused(true)
|
||||
.transparent(true)
|
||||
.build()
|
||||
.map_err(|e| WindowError::CreateFailed(format!("{}", e)))?;
|
||||
|
||||
// macOS: 设置窗口和 webview 背景透明
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
use objc::{msg_send, sel, sel_impl};
|
||||
if let Ok(ns_win) = window.ns_window() {
|
||||
#[allow(deprecated, unexpected_cfgs)]
|
||||
unsafe {
|
||||
let ns_window = ns_win as id;
|
||||
// 设置窗口背景透明
|
||||
|
||||
@@ -12,8 +12,10 @@ use tauri::{AppHandle, Manager, WebviewUrl, WebviewWindowBuilder};
|
||||
use tracing::{debug, info};
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
#[allow(deprecated)]
|
||||
use cocoa::appkit::{NSColor, NSWindow};
|
||||
#[cfg(target_os = "macos")]
|
||||
#[allow(deprecated)]
|
||||
use cocoa::base::{id, nil};
|
||||
|
||||
use super::update_check_service::UpdateInfo;
|
||||
@@ -164,7 +166,8 @@ pub fn open_update_window(
|
||||
|
||||
let (x, y) = calculate_window_position(app);
|
||||
|
||||
let _window = WebviewWindowBuilder::new(app, UPDATE_WINDOW_LABEL, WebviewUrl::App(url.into()))
|
||||
#[cfg_attr(not(target_os = "macos"), allow(unused_variables))]
|
||||
let window = WebviewWindowBuilder::new(app, UPDATE_WINDOW_LABEL, WebviewUrl::App(url.into()))
|
||||
.inner_size(WINDOW_WIDTH, WINDOW_HEIGHT)
|
||||
.position(x, y)
|
||||
.decorations(false)
|
||||
@@ -182,6 +185,7 @@ pub fn open_update_window(
|
||||
{
|
||||
use objc::{msg_send, sel, sel_impl};
|
||||
if let Ok(ns_win) = window.ns_window() {
|
||||
#[allow(deprecated, unexpected_cfgs)]
|
||||
unsafe {
|
||||
let ns_window = ns_win as id;
|
||||
let clear_color = NSColor::clearColor(nil);
|
||||
|
||||
Reference in New Issue
Block a user