feat: update to tauri beta, add permissions (#862)

Co-authored-by: Lucas Nogueira <lucas@tauri.app>
Co-authored-by: Lucas Nogueira <lucas@crabnebula.dev>
This commit is contained in:
Tillmann
2024-02-04 03:14:41 +09:00
committed by GitHub
parent 506ce4835b
commit d198c01486
387 changed files with 21883 additions and 943 deletions
+3 -3
View File
@@ -9,7 +9,7 @@
"serve": "vite preview"
},
"dependencies": {
"@tauri-apps/api": "2.0.0-alpha.13",
"@tauri-apps/api": "2.0.0-beta.0",
"@tauri-apps/plugin-barcode-scanner": "2.0.0-alpha.4",
"@tauri-apps/plugin-biometric": "2.0.0-alpha.0",
"@tauri-apps/plugin-cli": "2.0.0-alpha.5",
@@ -30,11 +30,11 @@
"@iconify-json/codicon": "^1.1.37",
"@iconify-json/ph": "^1.1.8",
"@sveltejs/vite-plugin-svelte": "^3.0.1",
"@tauri-apps/cli": "2.0.0-alpha.20",
"@tauri-apps/cli": "2.0.0-beta.0",
"@unocss/extractor-svelte": "^0.58.0",
"internal-ip": "^8.0.0",
"svelte": "^4.2.8",
"unocss": "^0.58.0",
"vite": "^5.0.6"
"vite": "^5.0.12"
}
}
+3 -2
View File
@@ -7,6 +7,7 @@ fn main() {
if !cfg!(feature = "custom-protocol") {
codegen = codegen.dev();
}
codegen.build();
tauri_build::build();
tauri_build::try_build(tauri_build::Attributes::new().codegen(codegen))
.expect("failed to run tauri_build::try_build");
}
@@ -0,0 +1,78 @@
{
"$schema": "schemas/desktop-schema.json",
"identifier": "run-app-base",
"description": "Base permissions to run the app",
"windows": ["main"],
"permissions": [
"log:default",
{
"identifier": "http:default",
"allow": [
{
"url": "http://localhost:3003"
}
]
},
"app:default",
"resources:default",
"fs:default",
"menu:default",
"path:default",
"tray:default",
"event:default",
"window:default",
"notification:default",
"os:allow-platform",
"dialog:allow-open",
"dialog:allow-save",
"dialog:allow-confirm",
{
"identifier": "shell:allow-execute",
"allow": [
{
"name": "sh",
"cmd": "sh",
"args": [
"-c",
{
"validator": "\\S+"
}
]
},
{
"name": "cmd",
"cmd": "cmd",
"args": [
"/C",
{
"validator": "\\S+"
}
]
}
]
},
"shell:allow-kill",
"shell:allow-stdin-write",
"clipboard-manager:allow-read",
"clipboard-manager:allow-write",
"fs:allow-rename",
"fs:allow-mkdir",
"fs:allow-remove",
"fs:allow-write-text-file",
"fs:scope-download-recursive",
"fs:scope-resource-recursive",
{
"identifier": "fs:scope-appdata-recursive",
"allow": [
{
"path": "$APPDATA/db/**"
}
],
"deny": [
{
"path": "$APPDATA/db/*.stronghold"
}
]
}
]
}
@@ -0,0 +1,14 @@
{
"$schema": "./schemas/desktop-schema.json",
"identifier": "run-app-desktop",
"description": "Permissions to run the app (desktop only)",
"windows": ["main"],
"platforms": ["linux", "macOS", "windows"],
"permissions": [
"cli:default",
"updater:default",
"global-shortcut:allow-unregister",
"global-shortcut:allow-register",
"global-shortcut:allow-unregister-all"
]
}
@@ -0,0 +1,16 @@
{
"$schema": "./schemas/mobile-schema.json",
"identifier": "run-app-mobile",
"description": "Permissions to run the app (mobile only)",
"windows": ["main"],
"platforms": ["android", "iOS"],
"permissions": [
"nfc:allow-write",
"nfc:allow-scan",
"biometric:allow-authenticate",
"barcode-scanner:allow-scan",
"barcode-scanner:allow-cancel",
"barcode-scanner:allow-request-permissions",
"barcode-scanner:allow-check-permissions"
]
}
@@ -0,0 +1,3 @@
*.json
!desktop-schema.json
!mobile-schema.json
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+12 -12
View File
@@ -7,7 +7,7 @@ mod cmd;
mod tray;
use serde::Serialize;
use tauri::{window::WindowBuilder, App, AppHandle, Manager, RunEvent, WindowUrl};
use tauri::{webview::WebviewWindowBuilder, App, AppHandle, Manager, RunEvent, WebviewUrl};
#[derive(Clone, Serialize)]
struct Reply {
@@ -51,10 +51,11 @@ pub fn run() {
app.handle().plugin(tauri_plugin_biometric::init())?;
}
let mut window_builder = WindowBuilder::new(app, "main", WindowUrl::default());
let mut webview_window_builder =
WebviewWindowBuilder::new(app, "main", WebviewUrl::default());
#[cfg(desktop)]
{
window_builder = window_builder
webview_window_builder = webview_window_builder
.user_agent(&format!("Tauri API - {}", std::env::consts::OS))
.title("Tauri API Validation")
.inner_size(1000., 800.)
@@ -64,7 +65,7 @@ pub fn run() {
#[cfg(target_os = "windows")]
{
window_builder = window_builder
webview_window_builder = webview_window_builder
.transparent(true)
.shadow(true)
.decorations(false);
@@ -72,15 +73,14 @@ pub fn run() {
#[cfg(target_os = "macos")]
{
window_builder = window_builder.transparent(true);
webview_window_builder = webview_window_builder.transparent(true);
}
let window = window_builder.build().unwrap();
let webview = webview_window_builder.build().unwrap();
#[cfg(debug_assertions)]
window.open_devtools();
webview.open_devtools();
#[cfg(desktop)]
std::thread::spawn(|| {
let server = match tiny_http::Server::http("localhost:3003") {
Ok(s) => s,
@@ -107,15 +107,15 @@ pub fn run() {
Ok(())
})
.on_page_load(|window, _| {
let window_ = window.clone();
window.listen("js-event", move |event| {
.on_page_load(|webview, _| {
let webview_ = webview.clone();
webview.listen("js-event", move |event| {
println!("got js-event with message '{:?}'", event.payload());
let reply = Reply {
data: "something else".to_string(),
};
window_
webview_
.emit("rust-event", Some(reply))
.expect("failed to emit");
});
+13 -12
View File
@@ -6,19 +6,20 @@ use std::sync::atomic::{AtomicBool, Ordering};
use tauri::{
menu::{Menu, MenuItem},
tray::{ClickType, TrayIconBuilder},
Manager, Runtime, WindowBuilder, WindowUrl,
Manager, Runtime, WebviewUrl, WebviewWindowBuilder,
};
pub fn create_tray<R: Runtime>(app: &tauri::AppHandle<R>) -> tauri::Result<()> {
let toggle_i = MenuItem::with_id(app, "toggle", "Toggle", true, None);
let new_window_i = MenuItem::with_id(app, "new-window", "New window", true, None);
let icon_i_1 = MenuItem::with_id(app, "icon-1", "Icon 1", true, None);
let icon_i_2 = MenuItem::with_id(app, "icon-2", "Icon 2", true, None);
let toggle_i = MenuItem::with_id(app, "toggle", "Toggle", true, None::<&str>)?;
let new_window_i = MenuItem::with_id(app, "new-window", "New window", true, None::<&str>)?;
let icon_i_1 = MenuItem::with_id(app, "icon-1", "Icon 1", true, None::<&str>)?;
let icon_i_2 = MenuItem::with_id(app, "icon-2", "Icon 2", true, None::<&str>)?;
#[cfg(target_os = "macos")]
let set_title_i = MenuItem::with_id(app, "set-title", "Set Title", true, None);
let switch_i = MenuItem::with_id(app, "switch-menu", "Switch Menu", true, None);
let quit_i = MenuItem::with_id(app, "quit", "Quit", true, None);
let remove_tray_i = MenuItem::with_id(app, "remove-tray", "Remove Tray icon", true, None);
let set_title_i = MenuItem::with_id(app, "set-title", "Set Title", true, None::<&str>)?;
let switch_i = MenuItem::with_id(app, "switch-menu", "Switch Menu", true, None::<&str>)?;
let quit_i = MenuItem::with_id(app, "quit", "Quit", true, None::<&str>)?;
let remove_tray_i =
MenuItem::with_id(app, "remove-tray", "Remove Tray icon", true, None::<&str>)?;
let menu1 = Menu::with_items(
app,
&[
@@ -53,7 +54,7 @@ pub fn create_tray<R: Runtime>(app: &tauri::AppHandle<R>) -> tauri::Result<()> {
app.remove_tray_by_id("tray-1");
}
"toggle" => {
if let Some(window) = app.get_window("main") {
if let Some(window) = app.get_webview_window("main") {
let new_title = if window.is_visible().unwrap_or_default() {
let _ = window.hide();
"Show"
@@ -66,7 +67,7 @@ pub fn create_tray<R: Runtime>(app: &tauri::AppHandle<R>) -> tauri::Result<()> {
}
}
"new-window" => {
let _ = WindowBuilder::new(app, "new", WindowUrl::App("index.html".into()))
let _ = WebviewWindowBuilder::new(app, "new", WebviewUrl::App("index.html".into()))
.title("Tauri")
.build();
}
@@ -104,7 +105,7 @@ pub fn create_tray<R: Runtime>(app: &tauri::AppHandle<R>) -> tauri::Result<()> {
.on_tray_icon_event(|tray, event| {
if event.click_type == ClickType::Left {
let app = tray.app_handle();
if let Some(window) = app.get_window("main") {
if let Some(window) = app.get_webview_window("main") {
let _ = window.show();
let _ = window.set_focus();
}
+3 -34
View File
@@ -72,45 +72,14 @@
}
}
},
"fs": {
"scope": {
"allow": ["$APPDATA/db/**", "$DOWNLOAD/**", "$RESOURCE/**"],
"deny": ["$APPDATA/db/*.stronghold"]
}
},
"shell": {
"open": true,
"scope": [
{
"name": "sh",
"cmd": "sh",
"args": [
"-c",
{
"validator": "\\S+"
}
]
},
{
"name": "cmd",
"cmd": "cmd",
"args": [
"/C",
{
"validator": "\\S+"
}
]
}
]
},
"http": {
"scope": ["http://localhost:3003"]
"open": true
},
"updater": {
"pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IDE5QzMxNjYwNTM5OEUwNTgKUldSWTRKaFRZQmJER1h4d1ZMYVA3dnluSjdpN2RmMldJR09hUFFlZDY0SlFqckkvRUJhZDJVZXAK",
"endpoints": [
"https://tauri-update-server.vercel.app/update/{{target}}/{{current_version}}"
],
"pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IDE5QzMxNjYwNTM5OEUwNTgKUldSWTRKaFRZQmJER1h4d1ZMYVA3dnluSjdpN2RmMldJR09hUFFlZDY0SlFqckkvRUJhZDJVZXAK"
]
}
},
"bundle": {