黄中银 vor 2 Wochen
Ursprung
Commit
ae014df78c

+ 11 - 21
.github/workflows/release.yml

@@ -42,29 +42,19 @@ jobs:
         with:
           targets: ${{ matrix.target }}
 
-      - name: Cache Cargo
-        uses: actions/cache@v4
+      - name: Cache Rust
+        uses: Swatinem/rust-cache@v2
         with:
-          path: |
-            ~/.cargo/bin/
-            ~/.cargo/registry/index/
-            ~/.cargo/registry/cache/
-            ~/.cargo/git/db/
-            src-tauri/target/
-          key: cargo-${{ runner.os }}-${{ matrix.target }}-${{ hashFiles('src-tauri/Cargo.lock') }}
-          restore-keys: |
-            cargo-${{ runner.os }}-${{ matrix.target }}-
-
-      - name: Install Linux dependencies
+          workspaces: src-tauri -> target
+          cache-targets: true
+          shared-key: ${{ matrix.target }}
+
+      - name: Install Linux dependencies (cached)
         if: matrix.platform == 'linux'
-        run: |
-          sudo apt-get update
-          sudo apt-get install -y \
-            libwebkit2gtk-4.1-dev \
-            libayatana-appindicator3-dev \
-            librsvg2-dev \
-            patchelf \
-            libgtk-3-dev
+        uses: awalsh128/cache-apt-pkgs-action@latest
+        with:
+          packages: libwebkit2gtk-4.1-dev libayatana-appindicator3-dev librsvg2-dev patchelf libgtk-3-dev
+          version: 1.0
 
       - name: Install dependencies
         run: npm ci

+ 17 - 2
src-tauri/src/commands/install.rs

@@ -1,20 +1,31 @@
+#[cfg(target_os = "windows")]
 use crate::commands::config::{get_git_mirror_config, get_nodejs_mirror_config};
 use crate::commands::AppState;
-use crate::utils::http::{get_client, HttpRequest};
-use crate::utils::shell::{run_program, run_shell_hidden, CommandOptions};
+#[cfg(target_os = "windows")]
+use crate::utils::http::get_client;
+#[cfg(any(target_os = "windows", target_os = "linux"))]
+use crate::utils::http::HttpRequest;
+use crate::utils::shell::run_shell_hidden;
+#[cfg(target_os = "windows")]
+use crate::utils::shell::{run_program, CommandOptions};
+#[cfg(target_os = "windows")]
 use futures::StreamExt;
 use serde::{Deserialize, Serialize};
+#[cfg(target_os = "windows")]
 use std::io::Write;
+#[cfg(target_os = "windows")]
 use std::path::Path;
 use tauri::{Emitter, State};
 
 /// 安装错误,包含 i18nKey 用于前端翻译
+#[cfg(target_os = "windows")]
 #[derive(Debug, Clone)]
 pub struct InstallError {
     pub i18n_key: String,
     pub detail: Option<String>,
 }
 
+#[cfg(target_os = "windows")]
 impl InstallError {
     pub fn new(i18n_key: &str) -> Self {
         Self {
@@ -39,6 +50,7 @@ impl InstallError {
     }
 }
 
+#[cfg(target_os = "windows")]
 impl std::fmt::Display for InstallError {
     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
         write!(f, "{}", self.to_message())
@@ -47,6 +59,7 @@ impl std::fmt::Display for InstallError {
 
 /// 下载文件并报告进度(支持断点续传)
 /// progress_callback: (downloaded_bytes, total_bytes, percent)
+#[cfg(target_os = "windows")]
 async fn download_file_with_progress<F>(
     url: &str,
     dest_path: &Path,
@@ -567,6 +580,7 @@ where
 async fn install_vscode<F, C>(
     _app: &tauri::AppHandle,
     _state: &State<'_, AppState>,
+    #[cfg_attr(target_os = "macos", allow(unused_variables))]
     options: &InstallOptions,
     emit_status: F,
     is_cancelled: C,
@@ -753,6 +767,7 @@ where
 async fn install_git<F, C>(
     _app: &tauri::AppHandle,
     _state: &State<'_, AppState>,
+    #[cfg_attr(not(target_os = "windows"), allow(unused_variables))]
     options: &InstallOptions,
     emit_status: F,
     is_cancelled: C,

+ 2 - 0
src-tauri/src/utils/shell.rs

@@ -22,6 +22,7 @@ pub struct CommandOptions {
     /// 是否显示窗口(仅 Windows 有效)
     /// - true: 显示窗口(用于需要用户交互的命令)
     /// - false: 隐藏窗口(用于后台执行的命令,默认)
+    #[cfg_attr(not(target_os = "windows"), allow(dead_code))]
     pub show_window: bool,
 
     /// 是否使用最新的环境变量(默认 true)
@@ -305,6 +306,7 @@ pub fn run_shell(command: &str, options: CommandOptions) -> Result<Output, Strin
 /// ```rust
 /// let output = run_program("msiexec", &["/i", "setup.msi", "/qn"], CommandOptions::hidden())?;
 /// ```
+#[cfg_attr(not(target_os = "windows"), allow(dead_code))]
 pub fn run_program(program: &str, args: &[&str], options: CommandOptions) -> Result<Output, String> {
     let mut cmd = Command::new(program);
     cmd.args(args)

+ 1 - 4
src-tauri/tauri.conf.json

@@ -31,10 +31,7 @@
   },
   "bundle": {
     "active": true,
-    "targets": [
-      "msi",
-      "nsis"
-    ],
+    "targets": "all",
     "icon": [
       "icons/32x32.png",
       "icons/128x128.png",