(4) Tauri调试

创建项目

我使用的下面的配置

项目编译

安装依赖

进入根路径下执行 npm install,虽然使用了yarn管理工具,但是yarn安装依赖会失败。

编译前端

npm run build

运行项目包含了rust编译

npm run tauri dev

调试

必备插件

在 VS Code 中打开扩展商店(快捷键 Ctrl+Shift+X),搜索并安装,前三个是必选项:

  • CodeLLDB

  • C/C++

  • Rust Analyzer

  • CrabNebula DevTools(如果你启用了 CrabNebula 插件)

配置调试文件

launch.json文件

复制代码
{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Launch App Debug",
      "type": "cppvsdbg",
      "request": "launch",
      // change the exe name to your actual exe name
      // (to debug release builds, change `target/debug` to `release/debug`)
      "program": "${workspaceRoot}/src-tauri/target/debug/your-app-name-here.exe",
      "cwd": "${workspaceRoot}",
      "preLaunchTask": "ui:dev"
    }
  ]
}

tasks.json文件

复制代码
{
  // See https://go.microsoft.com/fwlink/?LinkId=733558
  // for the documentation about the tasks.json format
  "version": "2.0.0",
  "tasks": [
    {
      "label": "build:debug",
      "type": "cargo",
      "command": "build",
      "options": {
        "cwd": "${workspaceRoot}/src-tauri"
      }
    },
    {
      "label": "ui:dev",
      "type": "shell",
      // `dev` keeps running in the background
      // ideally you should also configure a `problemMatcher`
      // see https://code.visualstudio.com/docs/editor/tasks#_can-a-background-task-be-used-as-a-prelaunchtask-in-launchjson
      "isBackground": true,
      // change this to your `beforeDevCommand`:
      "command": "yarn",
      "args": ["dev"]
    },
    {
      "label": "dev",
      "dependsOn": ["build:debug", "ui:dev"],
      "group": {
        "kind": "build"
      }
    }
  ]
}

全部配置完后 按F5调试项目。

调试前端代码

右键webview页面选择检查即可调出开发者web页面,在源代码窗口即可调试前端代码。

添加日志

前端日志

使用webview的api即可

console.log("普通日志");

console.warn("警告日志");

console.error("错误日志");

rust日志

println!("日志消息");

相关推荐
史不了4 小时前
静态交叉编译rust程序
开发语言·后端·rust
Johnny.Cheung4 小时前
非常好的Rust自动管理内存的例子
rust·内存管理·析构函数
码界奇点5 小时前
Rust 性能优化全流程从 flamegraph 定位瓶颈到 unsafe 与 SIMD 加速响应快
开发语言·性能优化·rust·simulated annealing
向上的车轮7 小时前
Actix Web适合什么类型的Web应用?可以部署 Java 或 .NET 的应用程序?
java·前端·rust·.net
小灰灰搞电子9 小时前
Rust 操作Sqlite数据库详细教程
数据库·rust·sqlite
百锦再9 小时前
第1章 Rust语言概述
java·开发语言·人工智能·python·rust·go·1024程序员节
小虚竹10 小时前
Rust日志系统完全指南:从log门面库到env_logger实战
开发语言·后端·rust
星释10 小时前
Rust 练习册 8:链表实现与所有权管理
开发语言·链表·rust
今日说"法"10 小时前
Rust 日志级别与结构化日志:从调试到生产的日志策略
开发语言·后端·rust
-大头.10 小时前
Rust并发编程实战技巧
开发语言·后端·rust