first commit

This commit is contained in:
编码猿
2024-09-27 01:15:47 +08:00
commit 8be1fcce6b
155 changed files with 9435 additions and 0 deletions

4
json-to-class/src-tauri/.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
# Generated by Cargo
# will have compiled files and executables
/target/

View File

@@ -0,0 +1 @@
66a6e945-2049-4334-8fa1-a7f788930e3e

5061
json-to-class/src-tauri/Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,50 @@
[package]
name = "json-to-calss"
version = "1.0.2"
description = "json转换为类或接口的桌面端工具"
authors = ["bmy"]
license = ""
repository = ""
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
name = "tauri_app_lib"
crate-type = ["staticlib", "cdylib", "rlib"]
[build-dependencies]
tauri-build = { version = "2.0.0-alpha.11", features = [] }
[dependencies]
# devtools
tauri = { version = "2.0.0-alpha.17", features = ["macos-private-api"] }
# 窗口
tauri-plugin-window = "2.0.0-alpha.2"
# shell 命令行
tauri-plugin-shell = "2.0.0-alpha.4"
# 开机自启
tauri-plugin-autostart = "2.0.0-alpha.4"
# 通知
tauri-plugin-notification = "2.0.0-alpha.5"
# fs 文件系统
tauri-plugin-fs = "2.0.0-alpha.4"
# 剪切板插件
tauri-plugin-clipboard-manager = "2.0.0-alpha.4"
# dialog
tauri-plugin-dialog = "2.0.0-alpha.4"
serde_json = "1.0"
window-vibrancy = "0.4.3"
[profile.release]
panic = "abort" # Strip expensive panic clean-up logic
codegen-units = 1 # Compile crates one after another so the compiler can optimize better
lto = true # Enables link to optimizations
opt-level = "s" # Optimize for binary size
strip = true # Remove debug symbols
[features]
# this feature is used for production builds or when `devPath` points to the filesystem
# DO NOT REMOVE!!
custom-protocol = ["tauri/custom-protocol"]

View File

@@ -0,0 +1,3 @@
fn main() {
tauri_build::build()
}

View File

@@ -0,0 +1 @@
f9e7ed09-d338-436e-855a-9f6dc62c18fd

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

View File

@@ -0,0 +1 @@
91c2e4ee-c16f-45aa-8b97-593e9240f4fe

View File

@@ -0,0 +1,76 @@
use tauri_plugin_autostart::MacosLauncher;
use std::io::Write;
use tauri::{ Manager };
use window_vibrancy::{apply_blur, apply_vibrancy, apply_acrylic, apply_mica, NSVisualEffectMaterial};
#[tauri::command]
fn greet(name: &str) -> String {
format!("Hello, {}! You've been greeted from Rust!", name)
}
// 帮助前端 将 文件保存到本地,不使用 tauri 的原因是其 fs 模块的
// 文件的访问权限控制无法实现此功能
#[tauri::command]
fn created_file(name: &str, content: &str) -> String {
let mut file = std::fs::File::create(name).expect("create file error");
file.write_all(content.as_bytes()).expect("write file error");
format!("ok")
}
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.setup(|app|
{
let splashscreen_window = app.get_window("splashscreen").unwrap();
let main_window = app.get_window("main").unwrap();
#[cfg(target_os = "macos")]
apply_vibrancy(&main_window, NSVisualEffectMaterial::HudWindow, None, None)
.expect("Unsupported platform! 'apply_vibrancy' is only supported on macOS");
#[cfg(target_os = "windows")]
apply_blur(&main_window, Some((5, 5, 5, 0)))
.expect("Unsupported platform! 'apply_blur' is only supported on Windows");
tauri::async_runtime::spawn(async move {
std::thread::sleep(std::time::Duration::from_secs(2));
splashscreen_window.close().unwrap();
main_window.show().unwrap();
// main_window.open_devtools()
});
Ok(())
})
// .on_window_event(|event| {
// let handle = event.window().app_handle();
// let label = event.window().label();
// match event.event() {
// WindowEvent::Focused(focused) => {
// println!("WindowEvent::Focused ==> {:?} {:?}", focused, label);
// if *focused {
// #[cfg(target_os = "macos")]
// match menu::setup_menu(handle, &label) {
// Ok(()) => {}
// Err(err) => println!("Failed to setup menu, {:?}", err),
// }
// }
// }
// _ => {}
// }
// })
.plugin(tauri_plugin_clipboard_manager::init())
.plugin(tauri_plugin_window::init())
.plugin(tauri_plugin_fs::init())
.plugin(tauri_plugin_shell::init())
.plugin(tauri_plugin_notification::init())
.plugin(tauri_plugin_dialog::init())
.plugin(tauri_plugin_autostart::init(MacosLauncher::LaunchAgent, Some(vec!["--flag1", "--flag2"])))
.invoke_handler(tauri::generate_handler![greet, created_file ])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

View File

@@ -0,0 +1,6 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
fn main() {
tauri_app_lib::run()
}

View File

@@ -0,0 +1,64 @@
use tauri::{
menu::{
CheckMenuItemBuilder, MenuBuilder, MenuItemBuilder, PredefinedMenuItem,
SubmenuBuilder,
},
AppHandle,
};
pub fn setup_menu(
handle: &AppHandle,
label: &str,
) -> Result<(), Box<dyn std::error::Error>> {
let pkg_info = handle.package_info();
let app_name = &pkg_info.name.clone();
let app_menu = SubmenuBuilder::new(handle, app_name).quit().build()?;
let ab_menu = SubmenuBuilder::new(handle, "关于作者")
.items(&[
&PredefinedMenuItem::about(handle, Some("关于"), None),
]).build()?;
let native_menu = SubmenuBuilder::new(handle, "NativeMenu")
.items(&[
&PredefinedMenuItem::about(handle, Some("关于"), None),
&PredefinedMenuItem::services(handle, Some("服务")),
&PredefinedMenuItem::hide(handle, Some("隐藏")),
&PredefinedMenuItem::hide_others(handle, Some("隐藏其他")),
&PredefinedMenuItem::show_all(handle, Some("显示全部")),
&PredefinedMenuItem::quit(handle, Some("退出")),
&PredefinedMenuItem::close_window(handle, Some("关闭窗口")),
&PredefinedMenuItem::undo(handle, Some("撤销")),
&PredefinedMenuItem::redo(handle, Some("重做")),
&PredefinedMenuItem::cut(handle, Some("剪切")),
&PredefinedMenuItem::copy(handle, Some("拷贝")),
&PredefinedMenuItem::paste(handle, Some("粘贴")),
&PredefinedMenuItem::select_all(handle, Some("全选")),
&PredefinedMenuItem::fullscreen(handle, Some("切换全屏")),
&PredefinedMenuItem::minimize(handle, Some("最小化")),
&PredefinedMenuItem::maximize(handle, Some("最大化")),
])
.build()?;
// only for "win_1"
let custom_menu = SubmenuBuilder::new(handle, "Test")
.item(&MenuItemBuilder::with_id("toggle", "Toggle").build(handle))
.item(&CheckMenuItemBuilder::new("Mark").build(handle))
.build()?;
let mut menus = MenuBuilder::new(handle)
.item(&app_menu)
.item(&custom_menu)
.item(&native_menu);
if label == "win1" {
menus = menus.item(&custom_menu);
}
handle.set_menu(menus.build()?)?;
handle.on_menu_event(move |handle, event| {
println!("event id: {:?}", event.id);
});
Ok(())
}

View File

@@ -0,0 +1,105 @@
{
"build": {
"beforeDevCommand": "npm run dev",
"beforeBuildCommand": "npm run build",
"devPath": "http://localhost:1420",
"distDir": "../dist",
"withGlobalTauri": true
},
"package": {
"productName": "JsonToClass",
"version": "1.0.2"
},
"tauri": {
"macOSPrivateApi": true,
"bundle": {
"active": true,
"targets": [
"app",
"dmg",
"nsis",
"msi",
"deb"
],
"windows": {
"webviewInstallMode": {
"type": "embedBootstrapper"
}
},
"deb": {},
"identifier": "com.bmy.json.to.class",
"publisher": "bmy",
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/128x128@2x.png",
"icons/JsonToClass.icns",
"icons/JsonToClass.ico"
]
},
"security": {
"csp": null
},
"windows": [
{
"label": "main",
"hiddenTitle": true,
"fullscreen": false,
"resizable": true,
"center": true,
"width": 1200,
"height": 900,
"minWidth": 1000,
"minHeight": 800,
"titleBarStyle": "Overlay",
"visible": false,
"transparent": true,
"title": ""
},
{
"title": "JsonToClass - 为API接口数据自动生成 TypeScript 类型",
"width": 300,
"height": 400,
"center": true,
"titleBarStyle": "Overlay",
"resizable": false,
"hiddenTitle": true,
"url": "splashscreen.html",
"label": "splashscreen"
}
]
},
"plugins": {
"os": {
"all": true
},
"app": {
"all": true
},
"shell": {
"open": true
},
"fs": {
"createDir": true,
"exists": true,
"writeTextFile": true,
"readTextFile": true,
"scope": [
"$HOME/.jsontoclass/*",
"$HOME/.jsontoclass",
"$HOME/*"
]
},
"window": {
"all": false,
"close": true,
"hide": true,
"show": true,
"maximize": true,
"minimize": true,
"unmaximize": true,
"unminimize": true,
"startDragging": true
}
}
}