我在 Ubuntu 上使用 Tauri JS。我想读取项目目录中的 csv 文件。
/data/example.csv
/src-tauri/
/src
...
Run Code Online (Sandbox Code Playgroud)
我激活了fs模块,我尝试了不同的模式
"all": true,
"fs": {
"scope": {
"allow": ["$APP/**", "$APP/db/**", "$APP/data/**" ,"$DOWNLOAD/**", "$RESOURCE/**", "/data/**", "data/**"]
}
},
Run Code Online (Sandbox Code Playgroud)
但是当我尝试使用以下代码阅读时:
import { readTextFile } from "@tauri-apps/api/fs";
let filePath = "./data/example.csv";
console.log("File path:", filePath)
const promise = readTextFile(filePath);
promise.then((response) => {
console.log(response);
}).catch((error) => {
console.error(error);
})
Run Code Online (Sandbox Code Playgroud)
我总是收到以下错误:
[Error] path not allowed on the configured scope: ./data/profiles.csv
Run Code Online (Sandbox Code Playgroud) 我是 tauri 的新人,我遇到了从 @tauri-apps/api 获取数据的问题。
"@tauri-apps/api": "^1.1.0",
"@tauri-apps/cli": "^1.1.1"
Run Code Online (Sandbox Code Playgroud)
这是我的反应代码如下:
/index.jsx
import {getTauriVersion} from "@tauri-apps/api/app"
function App() {
const func = async () => {
const res = await getTauriVersion()
return res
}
return (<></>)
}
Run Code Online (Sandbox Code Playgroud)
这是我的 tauri.conf.json
{
"build": {
"beforeDevCommand": "npm run dev",
"beforeBuildCommand": "npm run build",
"devPath": "http://localhost:1420",
"distDir": "../dist",
"withGlobalTauri": true
},
...
"tauri": {
"allowList": {"all": true}
}
}
Run Code Online (Sandbox Code Playgroud)
错误是:
Uncaught (in promise) TypeError: window.__TAURI_IPC__ is not a function
unhandledRejection: ReferenceError: window is not defined …Run Code Online (Sandbox Code Playgroud) 我有一个 React 应用程序并对其实现了 tauri,这样我就可以将其作为桌面应用程序。
我有两个 .env 文件:.env.development 和 .env.Production。当我运行时,tauri dev一切正常,但是当我运行时,tauri build运行时没有生产或开发环境文件中的环境变量。
我附上了我的 tauri.conf.json 的快照,希望它有帮助。
{
"$schema": "../node_modules/@tauri-apps/cli/schema.json",
"build": {
"beforeBuildCommand": "npm run build",
"beforeDevCommand": "npm start",
"devPath": "http://localhost:3000",
"distDir": "../build"
},
"package": {
"productName": "AppName",
"version": "1.2.3"
},
"tauri": {
"allowlist": {
"all": true
},
"bundle": {
"active": true,
"category": "DeveloperTool",
"copyright": "",
"deb": {
"depends": []
},
"externalBin": [],
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico"
],
"identifier": "com.myappname.app",
"longDescription": "",
"macOS": {
"entitlements": null, …Run Code Online (Sandbox Code Playgroud) 我通过以下方式安装它:
npm create tauri-app
Run Code Online (Sandbox Code Playgroud)
我选择了一个普通的 JavaScript 环境来编码。
我跑:
cd app
npm install
npm run tauri dev
Run Code Online (Sandbox Code Playgroud)
结果是这个错误:
> app@0.0.0 tauri
> tauri dev
thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }', src/interface/rust.rs:762:69
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Run Code Online (Sandbox Code Playgroud)
我使用的是 Mac OS Monterey。
我在线搜索了该错误,似乎它可能与我的系统时间配置有关,但我不确定。
我正在尝试制作一个小型金牛座应用程序,每个页面顶部都有相同的菜单。我按照本教程的“将菜单添加到所有窗口”部分进行操作。我可以看到菜单,我可以用它退出应用程序,但我不知道如何在点击时转到另一个 hmtl 页面。
我有这段代码,但我不知道在“accel”下放什么
.on_menu_event(|event| {
match event.menu_item_id() {
"quit" => {
std::process::exit(0);
}
"close" => {
event.window().close().unwrap();
}
"accel" => {
//not working, as you can imagine
//tauri::WindowUrl::App("index.html".into());
//I would like tauri to display index.html in the main window
}
_ => {}
}
})
Run Code Online (Sandbox Code Playgroud)
有人知道如何做到这一点吗?我找到了几十个带有菜单的示例代码,但没有一个显示我正在寻找的内容(或者我无法指出我需要的行)
感谢您的帮助 !
我正在尝试编写一个使用discord.js 的tauri 应用程序(react+ts+vite)。但是,当我尝试运行该应用程序时,出现以下错误:
node_modules/discord-api-types/payloads/v9/permissions.js:17:16: ERROR: Big integer literals are not available in the configured target environment ("chrome87", "edge88", "es2019", "firefox78", "safari13.1")
Run Code Online (Sandbox Code Playgroud)
是否可以一起使用 tauri 和 Discord.js,或者我是否必须编写单独的应用程序和“discord bot”?
我知道询问有关错误本身的问题会更明智,但是浏览了一下互联网后,我没有找到任何东西,或者除了将compilerOptions设置为es2020之外,但这对我没有帮助。我还在 github 上发现了一个讨论浏览器中的discord.js 的问题,但它已经过时了。
运行 Tauri 应用程序时,它只显示如下白屏:
我没有对应用程序进行任何更改
这是我创建应用程序的方式:
npx 创建 tauri 应用程序
然后我选择React作为我的前端框架
然后它创建了应用程序,我只需 cd 到该文件夹并运行 npm run tauri dev
这是我的 Tauri 配置 json 文件:
{
"$schema": "..\\node_modules/@tauri-apps/cli\\schema.json",
"build": {
"beforeBuildCommand": "npm run build",
"beforeDevCommand": "npm run start",
"devPath": "http://localhost:3000",
"distDir": "../build"
},
"package": {
"productName": "test",
"version": "0.1.0"
},
"tauri": {
"allowlist": {
"all": true
},
"bundle": {
"active": true,
"category": "DeveloperTool",
"copyright": "",
"deb": {
"depends": []
},
"externalBin": [],
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico"
],
"identifier": "com.tauri.dev",
"longDescription": …Run Code Online (Sandbox Code Playgroud) 我试图将 Tauri 应用程序放在 osx 托盘图标的中心,但找不到方法。
这个想法是让应用程序在托盘图标单击时打开和关闭,并使其固定在屏幕顶部并以图标为中心(y 位置可能会根据其他应用程序可用的项目数量而变化)。像这样的东西:
https://eshop.macsales.com/blog/wp-content/uploads/2019/05/Fantastical1280.jpg
(抱歉,我尝试将图像添加到问题中,但上传时总是出现“服务器错误”)
我搜索了文档,但没有找到任何内容,也没有在谷歌上找到解决方案
上面tauri.conf.json有一个windows.x和windows.y选项,但我不认为我能在那里得到这种逻辑。
我注意到有一个window.set_position()函数可以在单击图标时调用。但我不知道如何获得图标上进入窗口的正确位置
我对 Tauri 和 Rust 都很陌生,我试图在单击某些菜单项时向前端发出事件
fn main() {
Builder::default()
.menu(build_menu())
.on_menu_event(|event| {
match event.menu_item_id() {
"new" => {
println!("New fired");
// Emit event here
}
"save" => {
println!("Save fired");
}
"open" => {
println!("Open fired")
}
"export" => {
println!("Export fired");
}
_ => {}
}
})
.run(generate_context!())
.expect("error while running tauri application");
}
Run Code Online (Sandbox Code Playgroud)
我一直在查看 Tauri 文档和其他问题,但到目前为止我只能弄清楚如何从设置中发出事件
来自tauri.app的示例
fn main() {
tauri::Builder::default()
.setup(|app| {
// `main` here is the window label; it is defined on the window creation …Run Code Online (Sandbox Code Playgroud) 有没有办法在我的 macbook pro m1 上构建 Windows 和 Linux 版本的 Tauri?我已经尝试过了,--target只是在构建时出现错误。
yarn run v1.22.15
$ tauri build -t x86_64-pc-windows-msvc
Compiling proc-macro2 v1.0.36
Compiling unicode-xid v0.2.2
Compiling syn v1.0.86
Compiling libc v0.2.119
Compiling cfg-if v1.0.0
Compiling serde_derive v1.0.136
Compiling serde v1.0.136
Compiling ppv-lite86 v0.2.16
Compiling siphasher v0.3.9
Compiling getrandom v0.1.16
Compiling winapi v0.3.9
error[E0463]: can't find crate for `core`
|
= note: the `x86_64-pc-windows-msvc` target may not be installed
= help: consider downloading the target with `rustup target add x86_64-pc-windows-msvc` …Run Code Online (Sandbox Code Playgroud) tauri ×10
rust ×4
javascript ×2
reactjs ×2
apple-m1 ×1
centering ×1
discord.js ×1
events ×1
node.js ×1
npm ×1
typescript ×1