build(init):项目初始化建立,迁移无需重构部分内容。
4
src-tauri/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
# Generated by Cargo
|
||||
# will have compiled files and executables
|
||||
/target/
|
||||
|
33
src-tauri/Cargo.toml
Normal file
@@ -0,0 +1,33 @@
|
||||
[package]
|
||||
name = "pylib_editor"
|
||||
version = "0.1.0"
|
||||
description = "Pinyin Input Method Library Editor."
|
||||
authors = ["midnite"]
|
||||
license = "Apache-2.0"
|
||||
repository = "https://github.com/vixalie/pylib-editor"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[build-dependencies]
|
||||
tauri-build = { version = "1.5", features = [] }
|
||||
|
||||
[dependencies]
|
||||
tauri = { version = "1.5", features = ["macos-private-api", "window-unminimize", "window-close", "window-start-dragging", "window-show", "window-hide", "window-maximize", "window-unmaximize", "window-minimize", "shell-open"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
window-vibrancy = "0.4.3"
|
||||
once_cell = "1.18.0"
|
||||
anyhow = "1.0.75"
|
||||
thiserror = "1.0.50"
|
||||
serde_repr = "0.1.17"
|
||||
tokio = { version = "1.34.0", features = ["full"] }
|
||||
uuid = "1.6.1"
|
||||
rusqlite = { version = "0.30.0", features = ["modern-full"] }
|
||||
directories = "5.0.1"
|
||||
toml = "0.8.8"
|
||||
|
||||
[features]
|
||||
# this feature is used for production builds or when `devPath` points to the filesystem
|
||||
# DO NOT REMOVE!!
|
||||
custom-protocol = ["tauri/custom-protocol"]
|
3
src-tauri/build.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
tauri_build::build()
|
||||
}
|
BIN
src-tauri/icons/128x128.png
Normal file
After Width: | Height: | Size: 3.4 KiB |
BIN
src-tauri/icons/128x128@2x.png
Normal file
After Width: | Height: | Size: 6.8 KiB |
BIN
src-tauri/icons/32x32.png
Normal file
After Width: | Height: | Size: 974 B |
BIN
src-tauri/icons/Square107x107Logo.png
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
src-tauri/icons/Square142x142Logo.png
Normal file
After Width: | Height: | Size: 3.8 KiB |
BIN
src-tauri/icons/Square150x150Logo.png
Normal file
After Width: | Height: | Size: 3.9 KiB |
BIN
src-tauri/icons/Square284x284Logo.png
Normal file
After Width: | Height: | Size: 7.6 KiB |
BIN
src-tauri/icons/Square30x30Logo.png
Normal file
After Width: | Height: | Size: 903 B |
BIN
src-tauri/icons/Square310x310Logo.png
Normal file
After Width: | Height: | Size: 8.4 KiB |
BIN
src-tauri/icons/Square44x44Logo.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
src-tauri/icons/Square71x71Logo.png
Normal file
After Width: | Height: | Size: 2.0 KiB |
BIN
src-tauri/icons/Square89x89Logo.png
Normal file
After Width: | Height: | Size: 2.4 KiB |
BIN
src-tauri/icons/StoreLogo.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
src-tauri/icons/icon.icns
Normal file
BIN
src-tauri/icons/icon.ico
Normal file
After Width: | Height: | Size: 85 KiB |
BIN
src-tauri/icons/icon.png
Normal file
After Width: | Height: | Size: 14 KiB |
67
src-tauri/src/config.rs
Normal file
@@ -0,0 +1,67 @@
|
||||
use std::{
|
||||
fs::{DirBuilder, File},
|
||||
io::{Read, Write},
|
||||
ops::Deref,
|
||||
path::{Path, PathBuf},
|
||||
sync::{Mutex, MutexGuard},
|
||||
};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::keyboard_mapping::KeyboardMapping;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct Configuration {
|
||||
pub mappings: Vec<KeyboardMapping>,
|
||||
}
|
||||
|
||||
static CONFIG_INSTANCE: Mutex<Configuration> = Mutex::new(Configuration {
|
||||
mappings: Vec::new(),
|
||||
});
|
||||
|
||||
impl Configuration {
|
||||
// 获取一个可以用于访问应用配置信息的引用。
|
||||
pub fn get() -> MutexGuard<'static, Configuration> {
|
||||
CONFIG_INSTANCE.lock().unwrap()
|
||||
}
|
||||
|
||||
// 确认应用数据目录的存在,如果数据目录不存在,那么将自动创建。
|
||||
fn ensure_data_dir() -> anyhow::Result<PathBuf> {
|
||||
let config_dir = directories::ProjectDirs::from("xyz", "archgrid", "pylib").ok_or(
|
||||
anyhow::anyhow!("unable to fetch application data directory"),
|
||||
)?;
|
||||
let data_dir = config_dir.data_dir();
|
||||
if !data_dir.exists() {
|
||||
let mut dir_creator = DirBuilder::new();
|
||||
dir_creator
|
||||
.recursive(true)
|
||||
.create(config_dir.data_dir())
|
||||
.unwrap();
|
||||
}
|
||||
Ok(data_dir.to_path_buf())
|
||||
}
|
||||
|
||||
// 确认应用配置文件存在,如果配置文件不存在,那么将自动创建一个空白的配置文件。
|
||||
fn ensure_config_file<P: AsRef<Path>>(config_path: P) -> anyhow::Result<File> {
|
||||
let config_file_path = config_path.as_ref().join("config.toml");
|
||||
if !config_file_path.exists() {
|
||||
let mut file = File::create(config_file_path.clone())?;
|
||||
let configuration = Self::get();
|
||||
let toml_string = toml::to_string(configuration.deref())?;
|
||||
file.write_all(toml_string.as_bytes())?;
|
||||
}
|
||||
let config_file = File::open(config_file_path)?;
|
||||
Ok(config_file)
|
||||
}
|
||||
|
||||
// 从应用配置文件中加载配置信息,即便应用配置文件是空白的。
|
||||
pub fn load_settings() -> anyhow::Result<()> {
|
||||
let mut config_file = Self::ensure_config_file(Self::ensure_data_dir()?)?;
|
||||
let mut config_file_content = String::new();
|
||||
config_file.read_to_string(&mut config_file_content)?;
|
||||
let config: Configuration = toml::from_str(&config_file_content).unwrap();
|
||||
let mut configuration = Self::get();
|
||||
*configuration = config;
|
||||
Ok(())
|
||||
}
|
||||
}
|
29
src-tauri/src/keyboard_mapping.rs
Normal file
@@ -0,0 +1,29 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct KeyboardMapping {
|
||||
pub name: String,
|
||||
pub keys: HashMap<String, Vec<String>>,
|
||||
}
|
||||
|
||||
impl KeyboardMapping {
|
||||
/// 创建一个新的键盘映射。
|
||||
pub fn new<S: AsRef<str>>(name: S, key: S) -> Self {
|
||||
let mut keys = HashMap::new();
|
||||
keys.insert(key.as_ref().to_string(), vec![key.as_ref().to_string()]);
|
||||
Self {
|
||||
name: name.as_ref().to_string(),
|
||||
keys,
|
||||
}
|
||||
}
|
||||
|
||||
// 重命名键盘映射。
|
||||
pub fn rename<S: AsRef<str>>(self, name: S) -> Self {
|
||||
Self {
|
||||
name: name.as_ref().to_string(),
|
||||
..self
|
||||
}
|
||||
}
|
||||
}
|
21
src-tauri/src/main.rs
Normal file
@@ -0,0 +1,21 @@
|
||||
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
#![allow(dead_code)]
|
||||
|
||||
mod config;
|
||||
mod keyboard_mapping;
|
||||
mod setup;
|
||||
|
||||
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
|
||||
#[tauri::command]
|
||||
fn greet(name: &str) -> String {
|
||||
format!("Hello, {}! You've been greeted from Rust!", name)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
tauri::Builder::default()
|
||||
.setup(setup::init)
|
||||
.invoke_handler(tauri::generate_handler![greet])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
19
src-tauri/src/setup.rs
Normal file
@@ -0,0 +1,19 @@
|
||||
use tauri::{App, Manager};
|
||||
use window_vibrancy::{self, NSVisualEffectMaterial};
|
||||
|
||||
/// setup
|
||||
pub fn init(app: &mut App) -> std::result::Result<(), Box<dyn std::error::Error>> {
|
||||
let win = app.get_window("main").unwrap();
|
||||
|
||||
// 仅在 macOS 下执行
|
||||
#[cfg(target_os = "macos")]
|
||||
window_vibrancy::apply_vibrancy(&win, NSVisualEffectMaterial::FullScreenUI, None, None)
|
||||
.expect("Unsupported platform! 'apply_vibrancy' is only supported on macOS");
|
||||
|
||||
// 仅在 windows 下执行
|
||||
#[cfg(target_os = "windows")]
|
||||
window_vibrancy::apply_blur(&win, Some((18, 18, 18, 125)))
|
||||
.expect("Unsupported platform! 'apply_blur' is only supported on Windows");
|
||||
|
||||
Ok(())
|
||||
}
|
63
src-tauri/tauri.conf.json
Normal file
@@ -0,0 +1,63 @@
|
||||
{
|
||||
"build": {
|
||||
"beforeDevCommand": "bun run dev",
|
||||
"beforeBuildCommand": "bun run build",
|
||||
"devPath": "http://localhost:1420",
|
||||
"distDir": "../dist"
|
||||
},
|
||||
"package": {
|
||||
"productName": "拼音词库工具",
|
||||
"version": "0.1.0"
|
||||
},
|
||||
"tauri": {
|
||||
"macOSPrivateApi": true,
|
||||
"allowlist": {
|
||||
"all": false,
|
||||
"shell": {
|
||||
"all": false,
|
||||
"open": true
|
||||
},
|
||||
"window": {
|
||||
"all": false,
|
||||
"close": true,
|
||||
"hide": true,
|
||||
"show": true,
|
||||
"maximize": true,
|
||||
"minimize": true,
|
||||
"unmaximize": true,
|
||||
"unminimize": true,
|
||||
"startDragging": true
|
||||
}
|
||||
},
|
||||
"bundle": {
|
||||
"active": true,
|
||||
"targets": "all",
|
||||
"identifier": "xyz.archgrid.pylib",
|
||||
"icon": [
|
||||
"icons/32x32.png",
|
||||
"icons/128x128.png",
|
||||
"icons/128x128@2x.png",
|
||||
"icons/icon.icns",
|
||||
"icons/icon.ico"
|
||||
]
|
||||
},
|
||||
"security": {
|
||||
"csp": null
|
||||
},
|
||||
"windows": [
|
||||
{
|
||||
"fullscreen": false,
|
||||
"resizable": true,
|
||||
"title": "拼音词库工具",
|
||||
"width": 1200,
|
||||
"height": 800,
|
||||
"minWidth": 1200,
|
||||
"minHeight": 800,
|
||||
"titleBarStyle": "Overlay",
|
||||
"decorations": true,
|
||||
"hiddenTitle": true,
|
||||
"transparent": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|