Skip to content

Commit

Permalink
update config
Browse files Browse the repository at this point in the history
  • Loading branch information
Sjj1024 committed Dec 20, 2024
1 parent 7b267b4 commit 57d0ff7
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 102 deletions.
33 changes: 33 additions & 0 deletions src-tauri/data/capabilities.json
Original file line number Diff line number Diff line change
@@ -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://**" }]
}
]
}
106 changes: 28 additions & 78 deletions src-tauri/data/config.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
}
82 changes: 58 additions & 24 deletions src-tauri/data/main.rs
Original file line number Diff line number Diff line change
@@ -1,46 +1,80 @@
// 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<WindowConfig, Error> {
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);
}
}
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");
}

0 comments on commit 57d0ff7

Please sign in to comment.