From 57d0ff7a42fc199e711246edacf02914acfe5e63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?1024=E5=B0=8F=E7=A5=9E?= <15670339118@163.com> Date: Fri, 20 Dec 2024 11:40:02 +0800 Subject: [PATCH] update config --- src-tauri/data/capabilities.json | 33 ++++++++++ src-tauri/data/config.json | 106 ++++++++----------------------- src-tauri/data/main.rs | 82 +++++++++++++++++------- 3 files changed, 119 insertions(+), 102 deletions(-) create mode 100644 src-tauri/data/capabilities.json diff --git a/src-tauri/data/capabilities.json b/src-tauri/data/capabilities.json new file mode 100644 index 00000000..2c574a39 --- /dev/null +++ b/src-tauri/data/capabilities.json @@ -0,0 +1,33 @@ +{ + "$schema": "../gen/schemas/desktop-schema.json", + "identifier": "default", + "description": "Capability for the main window", + "windows": ["main"], + "permissions": [ + "core:default", + "core:app:allow-set-app-theme", + "core:app:allow-name", + "opener:default", + "http:allow-fetch", + "http:allow-fetch-cancel", + "http:allow-fetch-read-body", + "http:allow-fetch-send", + "dialog:allow-open", + "os:allow-locale", + "shell:allow-open", + "fs:allow-app-write", + "fs:allow-app-read", + "fs:allow-app-read-recursive", + "fs:allow-app-write-recursive", + "fs:allow-appcache-write", + "fs:allow-appcache-write-recursive", + "fs:allow-appconfig-write", + "fs:allow-appconfig-write-recursive", + "fs:allow-appdata-write", + "fs:allow-appdata-write-recursive", + { + "identifier": "http:default", + "allow": [{ "url": "https://**" }] + } + ] +} diff --git a/src-tauri/data/config.json b/src-tauri/data/config.json index c424679a..38fde6af 100644 --- a/src-tauri/data/config.json +++ b/src-tauri/data/config.json @@ -1,83 +1,33 @@ { - "package": { - "productName": "PROJECTNAME", - "version": "PROJECTVERSION" - }, - "tauri": { - "allowlist": { - "all": false, - "path": { - "all": true - }, - "fs": { - "all": true, - "readFile": true, - "writeFile": true, - "readDir": true, - "copyFile": true, - "createDir": true, - "removeDir": true, - "removeFile": true, - "renameFile": true, - "exists": true, - "scope": [ - "$APPDATA/*", - "$APPDATA/**/*", - "$APPDATA/assets/*", - "$DOWNLOAD/*" - ] - }, - "http": { - "all": true - }, - "dialog": { - "all": true, - "ask": true, - "confirm": true, - "message": true, - "open": true, - "save": true - }, - "protocol": { - "all": true, - "asset": true, - "assetScope": [ - "$APPDATA/*", - "$APPDATA/**/*", - "$APPDATA/assets/*", - "$DOWNLOAD/*" - ] - }, - "shell": { - "all": false, - "open": true - }, - "clipboard": { - "all": true, - "writeText": true, - "readText": true - }, - "window": { - "all": true, - "create": true, - "center": true, - "setResizable": true - } - }, + "$schema": "https://schema.tauri.app/config/2", + "productName": "PakePlus", + "version": "0.0.1", + "identifier": "com.pakeplus.app", + "app": { "security": { - "csp": "default-src 'self' 'unsafe-inline' 'unsafe-eval'; img-src 'self' asset://localhost data:; font-src 'self' asset://localhost data:; asset: https://asset.localhost" - }, - "bundle": { - "active": true, - "targets": -3, - "identifier": "PROJECTID", - "icon": [ - "icons/32x32.png", - "icons/128x128.png", - "icons/128x128@2x.png", - "icons/icon.icns", - "icons/icon.ico" - ] + "assetProtocol": { + "enable": true, + "scope": { + "allow": [ + "$APPDATA/assets/**", + "$APPDATA/**", + "$DOWNLOAD/*" + ] + } + }, + "csp": "default-src 'self' 'unsafe-inline' 'unsafe-eval' ipc: http://ipc.localhost; img-src 'self' asset: http://asset.localhost blob: data: http://asset.localhost; font-src 'self' asset: http//localhost data:;" } + }, + "bundle": { + "active": true, + "targets": "all", + "resources": ["./data/*"], + "icon": [ + "icons/32x32.png", + "icons/128x128.png", + "icons/128x128@2x.png", + "icons/icon.icns", + "icons/icon.ico" + ] } } diff --git a/src-tauri/data/main.rs b/src-tauri/data/main.rs index 81d4ee65..edd94d0b 100644 --- a/src-tauri/data/main.rs +++ b/src-tauri/data/main.rs @@ -1,38 +1,55 @@ -// Prevents additional console window on Windows in release, DO NOT REMOVE!! -#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] +// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/ + +mod command; use serde_json::Error; -use tauri::{utils::config::WindowConfig, Menu, MenuItem, Submenu, WindowBuilder}; +use tauri::{menu::*, utils::config::WindowConfig}; fn json_to_window_config(window_json: &str) -> Result { serde_json::from_str(window_json) } -fn main() { - #[cfg(any(target_os = "linux", target_os = "windows"))] - let menu = Menu::new(); - #[cfg(target_os = "macos")] - let menu = Menu::new().add_submenu(Submenu::new( - "Edit", - Menu::new() - .add_native_item(MenuItem::Undo) - .add_native_item(MenuItem::Redo) - .add_native_item(MenuItem::Copy) - .add_native_item(MenuItem::Cut) - .add_native_item(MenuItem::Paste) - .add_native_item(MenuItem::SelectAll) - .add_native_item(MenuItem::CloseWindow) - .add_native_item(MenuItem::Quit), - )); +#[cfg_attr(mobile, tauri::mobile_entry_point)] +pub fn run() { tauri::Builder::default() + .menu(|handle| { + let menu = Menu::with_items( + handle, + &[ + #[cfg(target_os = "macos")] + &Submenu::with_items( + handle, + "Edit", + true, + &[ + &PredefinedMenuItem::undo(handle, None)?, + &PredefinedMenuItem::redo(handle, None)?, + &PredefinedMenuItem::cut(handle, None)?, + &PredefinedMenuItem::copy(handle, None)?, + &PredefinedMenuItem::paste(handle, None)?, + &PredefinedMenuItem::select_all(handle, None)?, + ], + )?, + ], + ); + menu + }) .setup(|app| { let app_handle = app.handle(); - let window_json = r#"WINDOWCONFIG"#; + let window_json = r#"{ + "title": "PakePlus", + "label": "PakePlus", + "width": 800, + "height": 600, + "url": "https://juejin.cn/" +}"#; match json_to_window_config(window_json) { Ok(config) => { println!("Parsed WindowConfig: {:?}", config); - let _main_window = WindowBuilder::from_config(&app_handle, config) - .build() - .unwrap(); + let _main_window = + tauri::WebviewWindowBuilder::from_config(app_handle, &config) + .unwrap() + .build() + .unwrap(); } Err(err) => { eprintln!("Failed to parse JSON: {}", err); @@ -40,7 +57,24 @@ fn main() { } Ok(()) }) - .menu(menu) + .plugin(tauri_plugin_opener::init()) + .plugin(tauri_plugin_os::init()) + .plugin(tauri_plugin_fs::init()) + .plugin(tauri_plugin_shell::init()) + .plugin(tauri_plugin_dialog::init()) + .plugin(tauri_plugin_http::init()) + .invoke_handler(tauri::generate_handler![ + command::pakeplus::open_window, + command::pakeplus::preview_from_config, + command::pakeplus::update_build_file, + command::pakeplus::update_config_file, + command::pakeplus::update_cargo_file, + command::pakeplus::update_main_rust, + command::pakeplus::update_custom_js, + command::pakeplus::content_to_base64, + command::pakeplus::update_config_json, + command::pakeplus::rust_main_window, + ]) .run(tauri::generate_context!()) .expect("error while running tauri application"); }