1
0
Эх сурвалжийг харах

fix(tauri): 在 main.rs 注册 write_export_file 并清理配置警告

default-run 走 main.rs,此前仅在 lib.rs 注册导致导出命令在实际 binary 中失效;同步 log_error、接入 normalize_proxy_base,并用 import.meta.dirname 兼容 Vite native configLoader。

Co-authored-by: Cursor <cursoragent@cursor.com>
darknessomi 4 долоо хоног өмнө
parent
commit
3e9dd60b84

+ 1 - 4
src-tauri/src/commands/cursor_cli.rs

@@ -283,10 +283,7 @@ pub async fn cursor_proxy_status(state: State<'_, CursorProxyState>) -> Result<P
     let (base, managed) = {
         let guard = state.managed.lock().await;
         (
-            guard
-                .base_url
-                .clone()
-                .unwrap_or_else(|| DEFAULT_PROXY_BASE.to_string()),
+            normalize_proxy_base(guard.base_url.clone()),
             guard.child.is_some(),
         )
     };

+ 12 - 0
src-tauri/src/lib.rs

@@ -10,6 +10,17 @@ fn set_proxy_env(config: proxy::ProxyConfig) -> String {
     summary
 }
 
+#[tauri::command]
+fn log_error(message: String, stack: String, component_stack: String) {
+    eprintln!("[frontend-error] message: {}", message);
+    if !stack.is_empty() {
+        eprintln!("[frontend-error] stack: {}", stack);
+    }
+    if !component_stack.is_empty() {
+        eprintln!("[frontend-error] component-stack: {}", component_stack);
+    }
+}
+
 pub fn run() {
     tauri::Builder::default()
         .plugin(tauri_plugin_single_instance::init(|app, _args, _cwd| {
@@ -110,6 +121,7 @@ pub fn run() {
             commands::writing_wake_lock::acquire_writing_wake_lock,
             commands::writing_wake_lock::release_writing_wake_lock,
             set_proxy_env,
+            log_error,
         ])
         .on_window_event(|window, event| {
             if let tauri::WindowEvent::CloseRequested { api, .. } = event {

+ 1 - 0
src-tauri/src/main.rs

@@ -63,6 +63,7 @@ fn main() {
             commands::fs::read_file,
             commands::fs::write_file,
             commands::fs::write_file_if_absent,
+            commands::fs::write_export_file,
             commands::fs::write_file_atomic,
             commands::fs::list_directory,
             commands::fs::copy_file,

+ 3 - 0
src/lib/export-center/export-service.spec.ts

@@ -103,6 +103,7 @@ it("Rust 临时文件使用同一可写句柄 write_all 和 sync_all,关闭后
 it("默认二进制写入桥接在 Rust 后端实现并注册", () => {
   const fsSource = readFileSync(resolve(process.cwd(), "src-tauri/src/commands/fs.rs"), "utf8")
   const libSource = readFileSync(resolve(process.cwd(), "src-tauri/src/lib.rs"), "utf8")
+  const mainSource = readFileSync(resolve(process.cwd(), "src-tauri/src/main.rs"), "utf8")
 
   expect(fsSource).toContain("pub async fn write_export_file")
   expect(fsSource).toContain("file.write_all(bytes)")
@@ -124,6 +125,8 @@ it("默认二进制写入桥接在 Rust 后端实现并注册", () => {
   expect(fsSource).toContain("validate_export_base64_length")
   expect(fsSource).toContain("write_export_file_enforces_64_mib_boundary")
   expect(libSource).toContain("commands::fs::write_export_file")
+  // default-run is main.rs; registration only in lib.rs leaves the command dead in the real binary.
+  expect(mainSource).toContain("commands::fs::write_export_file")
   const serviceSource = readFileSync(resolve(process.cwd(), "src/lib/export-center/export-service.ts"), "utf8")
   expect(serviceSource).toContain("contentsBase64: encodeExportBytesBase64(bytes)")
 })

+ 2 - 2
vite.config.ts

@@ -8,14 +8,14 @@ const host = process.env.TAURI_DEV_HOST
 
 // Read version from package.json at config-load time so the Settings
 // UI can show the running app version without duplicating the string.
-const pkgJson = JSON.parse(readFileSync(path.resolve(__dirname, "package.json"), "utf-8"))
+const pkgJson = JSON.parse(readFileSync(path.resolve(import.meta.dirname, "package.json"), "utf-8"))
 
 // https://vitejs.dev/config/
 export default defineConfig(async () => ({
   plugins: [react(), tailwindcss()],
 
   resolve: {
-    alias: { "@": path.resolve(__dirname, "./src") },
+    alias: { "@": path.resolve(import.meta.dirname, "./src") },
   },
 
   define: {