tauri 2.0
Tauri 2.0 can be a bit confusing. It is super secure by default, which means common things don't work until you enable the permissions.
To set permissions modify the src-tauri/capabilities/default.json file.
To read a write files use:
json "fs:allow-app-write",
"fs:allow-read",
"fs:read-all",
To configure the macOS menu use:
json "core:menu:default"
Copy and paste will stop working on Mac if you customize the menu because that removes the built-in Edit menu. To fix this you need to add it back with:
javascriptconst editMenu = await Submenu.new({
text:'Edit',
items:[
await PredefinedMenuItem.new({
item: 'Cut',
}),
await PredefinedMenuItem.new({
item:'Copy',
}),
await PredefinedMenuItem.new({
item: 'Paste',
}),
]
})
const menu = await Menu.new({
items: [..., editMenu, ...]
})
await menu.setAsAppMenu()
plugins
Most APIs require installing and configuring a specific plugin.
To be able to use the process.exit command, first install the native plugin with
shellnpx tauri add process
Install the JavaScript APIs
shellnpm install --save @tauri-apps/plugin-process
Import the API on the JS side
javascriptimport {exit} from "@tauri-apps/plugin-process";
Then configure any necessary permissions in src-tauri/capabilities/default.json.
Example here.
Hide App from system menu
Hide the current app. Used for the standard MacOS system menu.
javascriptimport {app} from "@tauri-apps/api"
await app.hide()
Permission:
json
"core:app:allow-app-hide"
Quit App
Quit the current app. Used for the standard MacOS system menu. Requires the `process` plugin.
javascriptimport {exit} from "@tauri-apps/plugin-process";
await exit()