From 7a20655557413200c8033f4f8b18d812af04cf89 Mon Sep 17 00:00:00 2001 From: selcarpa Date: Mon, 13 Oct 2025 17:29:37 +0800 Subject: [PATCH] feat(group): Added group management functionality - Added database interaction logic, supported inserting new group data, and integrated the Tauri SQL plugin for local data storage - Added a floating button on the nodes page to redirect to the addGroup page - Modified the app icon and title to improve the user experience - Adjusted the Tauri configuration file, optimized window settings, and app identifiers --- index.html | 4 +- package.json | 11 +-- src-tauri/Cargo.toml | 4 +- src-tauri/capabilities/default.json | 10 ++- src-tauri/src/entity.rs | 1 + src-tauri/src/group.rs | 14 +++ src-tauri/src/lib.rs | 18 +++- src-tauri/src/main.rs | 7 -- src-tauri/src/spary.rs | 3 +- src-tauri/tauri.conf.json | 7 +- src/components.d.ts | 1 + src/components/index/spary.vue | 2 +- src/components/nodeEdit/addGroup.vue | 122 +++++++++++++++++++++++++++ src/pages/addGroup.vue | 7 ++ src/pages/nodes.vue | 29 ++++++- src/typed-router.d.ts | 5 ++ yarn.lock | 9 +- 17 files changed, 221 insertions(+), 33 deletions(-) create mode 100644 src-tauri/src/group.rs create mode 100644 src/components/nodeEdit/addGroup.vue create mode 100644 src/pages/addGroup.vue diff --git a/index.html b/index.html index 99f203f..0d33900 100644 --- a/index.html +++ b/index.html @@ -2,9 +2,9 @@ - + - Tauri + Vue + Typescript App + Spary🌊 diff --git a/package.json b/package.json index 8358ff8..5824d98 100644 --- a/package.json +++ b/package.json @@ -12,13 +12,15 @@ "dependencies": { "@fontsource/roboto": "5.2.7", "@mdi/font": "7.4.47", + "@tauri-apps/api": "^2", + "@tauri-apps/plugin-opener": "^2", + "@tauri-apps/plugin-sql": "~2", "vue": "^3.5.21", "vue-router": "^4.5.1", - "vuetify": "^3.10.1", - "@tauri-apps/api": "^2", - "@tauri-apps/plugin-opener": "^2" + "vuetify": "^3.10.1" }, "devDependencies": { + "@tauri-apps/cli": "^2", "@tsconfig/node22": "^22.0.0", "@types/node": "^22.9.0", "@vitejs/plugin-vue": "^6.0.1", @@ -33,7 +35,6 @@ "unplugin-vue-router": "^0.15.0", "vite": "^7.1.5", "vite-plugin-vuetify": "^2.1.2", - "vue-tsc": "^3.0.7", - "@tauri-apps/cli": "^2" + "vue-tsc": "^3.0.7" } } diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 510da19..fbad824 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -22,6 +22,4 @@ tauri = { version = "2", features = [] } tauri-plugin-opener = "2" serde = { version = "1", features = ["derive"] } serde_json = "1" -sea-orm = { version = "2.0.0-rc", features = [ "sqlx-sqlite", "runtime-tokio-native-tls", "macros" ] } -once_cell = "1.21.3" - +tauri-plugin-sql = { version = "2", features = ["sqlite"] } diff --git a/src-tauri/capabilities/default.json b/src-tauri/capabilities/default.json index 4cdbf49..2ade1f0 100644 --- a/src-tauri/capabilities/default.json +++ b/src-tauri/capabilities/default.json @@ -2,9 +2,13 @@ "$schema": "../gen/schemas/desktop-schema.json", "identifier": "default", "description": "Capability for the main window", - "windows": ["main"], + "windows": [ + "main" + ], "permissions": [ "core:default", - "opener:default" + "opener:default", + "sql:default", + "sql:allow-execute" ] -} +} \ No newline at end of file diff --git a/src-tauri/src/entity.rs b/src-tauri/src/entity.rs index e69de29..8b13789 100644 --- a/src-tauri/src/entity.rs +++ b/src-tauri/src/entity.rs @@ -0,0 +1 @@ + diff --git a/src-tauri/src/group.rs b/src-tauri/src/group.rs new file mode 100644 index 0000000..b8efdab --- /dev/null +++ b/src-tauri/src/group.rs @@ -0,0 +1,14 @@ +#[tauri::command] +pub fn add_group( + group_name: String, + group_subscribe_url: Option, + group_arguments: Option, +) { + let message = match (&group_subscribe_url, &group_arguments) { + (Some(url), Some(args)) => format!("add_group: {} {} {}", group_name, url, args), + (Some(url), None) => format!("add_group: {} {}", group_name, url), + (None, Some(args)) => format!("add_group: {} {}", group_name, args), + (None, None) => format!("add_group: {}", group_name), + }; + println!("{}", message); +} diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index a489c5a..a379f17 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -1,13 +1,29 @@ // Learn more about Tauri commands at https://tauri.app/develop/calling-rust/ +use crate::group::add_group; use crate::spary::spary_switch; +use tauri_plugin_sql::{Migration, MigrationKind}; +mod group; mod spary; #[cfg_attr(mobile, tauri::mobile_entry_point)] pub fn run() { + let migrations = vec![ + Migration { + version: 1, + description: "create_initial_tables", + sql: "CREATE TABLE `group`(id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(60) NOT NULL,url TEXT NULL, arguments JSON NOT NULL default '{}', created_at DATETIME DEFAULT CURRENT_TIMESTAMP, updated_at DATETIME DEFAULT CURRENT_TIMESTAMP)", + kind: MigrationKind::Up, + } + ]; tauri::Builder::default() + .plugin( + tauri_plugin_sql::Builder::default() + .add_migrations("sqlite:spary.db", migrations) + .build(), + ) .plugin(tauri_plugin_opener::init()) - .invoke_handler(tauri::generate_handler![spary_switch]) + .invoke_handler(tauri::generate_handler![spary_switch, add_group]) .run(tauri::generate_context!()) .expect("error while running tauri application"); } diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 5e2973d..3357118 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -1,14 +1,7 @@ // Prevents additional console window on Windows in release, DO NOT REMOVE!! #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] - -use once_cell::sync::OnceCell; -use sea_orm::DatabaseConnection; - mod entity; -static DB: OnceCell = OnceCell::new(); - - fn main() { spary_lib::run() } diff --git a/src-tauri/src/spary.rs b/src-tauri/src/spary.rs index 32b124e..2c713c1 100644 --- a/src-tauri/src/spary.rs +++ b/src-tauri/src/spary.rs @@ -1,5 +1,4 @@ - #[tauri::command] -pub fn spary_switch(status:bool) { +pub fn spary_switch(status: bool) { println!("Spraying {status}"); } diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 66db576..6efd0a1 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -2,7 +2,7 @@ "$schema": "https://schema.tauri.app/config/2", "productName": "spary", "version": "0.1.0", - "identifier": "com.tain.spary", + "identifier": "one.tain.spary", "build": { "beforeDevCommand": "yarn dev", "devUrl": "http://localhost:1420", @@ -15,11 +15,6 @@ "title": "spary", "width": 800, "height": 600 - }, - { - "title": "addGroup", - "width": 800, - "height": 600 } ], "security": { diff --git a/src/components.d.ts b/src/components.d.ts index dd585af..0a162d4 100644 --- a/src/components.d.ts +++ b/src/components.d.ts @@ -8,6 +8,7 @@ export {} /* prettier-ignore */ declare module 'vue' { export interface GlobalComponents { + AddGroup: typeof import('./components/nodeEdit/addGroup.vue')['default'] RouterLink: typeof import('vue-router')['RouterLink'] RouterView: typeof import('vue-router')['RouterView'] Spary: typeof import('./components/index/spary.vue')['default'] diff --git a/src/components/index/spary.vue b/src/components/index/spary.vue index 9d59d86..11776b6 100644 --- a/src/components/index/spary.vue +++ b/src/components/index/spary.vue @@ -1,5 +1,5 @@