From e0aadd4dcbdd61dbed5c0b6fcd6042807ad1a19b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=90=91=E5=A4=9C?= <46275354+fu050409@users.noreply.github.com> Date: Fri, 12 Jul 2024 13:48:45 -0400 Subject: [PATCH] feat(WIP): add dashboard (#12) * chore(cspell): update cspell dict * chore: setup fronted end env * feat: add file size example * chore: rename to `@noctisynth/grassator` * chore(cspell): add `primeicons` to dict * feat(config): add config for grassator --- .gitignore | 3 ++ cspell.json | 3 ++ index.html | 15 ++++++-- package.json | 9 +++-- pnpm-lock.yaml | 77 ++++++++++++++++++++++++++++++++++++++++++ src-tauri/Cargo.lock | 8 ++--- src-tauri/src/lib.rs | 9 ++++- src-tauri/src/state.rs | 16 +++++++++ src/App.vue | 4 +-- src/main.ts | 17 ++++++++++ src/router/index.ts | 37 ++++++++++++++++++++ src/types/index.ts | 1 + src/types/utils.ts | 4 +++ src/views/index.vue | 20 +++++++++++ 14 files changed, 210 insertions(+), 13 deletions(-) create mode 100644 src-tauri/src/state.rs create mode 100644 src/router/index.ts create mode 100644 src/types/index.ts create mode 100644 src/types/utils.ts create mode 100644 src/views/index.vue diff --git a/.gitignore b/.gitignore index a547bf3..577fa48 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,6 @@ dist-ssr *.njsproj *.sln *.sw? + +# Unplugin +components.d.ts diff --git a/cspell.json b/cspell.json index 205506e..7041076 100644 --- a/cspell.json +++ b/cspell.json @@ -8,11 +8,14 @@ "grassator", "icns", "noctisynth", + "pinia", + "primeicons", "primevue", "reqwest", "serde", "staticlib", "tauri", + "toastservice", "unocss", "unplugin" ], diff --git a/index.html b/index.html index aa51dde..f1f33b0 100644 --- a/index.html +++ b/index.html @@ -1,14 +1,25 @@ - + - Tauri + Vue + TS + Grassator
+ diff --git a/package.json b/package.json index 4559049..b02dbcf 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { - "name": "grassator", + "name": "@noctisynth/grassator", "private": true, - "version": "0.0.0", + "version": "0.1.0", "type": "module", "scripts": { "dev": "vite", @@ -13,9 +13,12 @@ "@primevue/themes": "^4.0.0", "@tauri-apps/api": "2.0.0-beta.14", "@tauri-apps/plugin-shell": "2.0.0-beta.7", + "pinia": "^2.1.7", + "primeicons": "^7.0.0", "primevue": "^4.0.0", "unocss": "^0.61.3", - "vue": "^3.4.31" + "vue": "^3.4.31", + "vue-router": "^4.4.0" }, "devDependencies": { "@primevue/auto-import-resolver": "^4.0.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0e158fe..7010117 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -17,6 +17,12 @@ importers: '@tauri-apps/plugin-shell': specifier: 2.0.0-beta.7 version: 2.0.0-beta.7 + pinia: + specifier: ^2.1.7 + version: 2.1.7(typescript@5.5.3)(vue@3.4.31(typescript@5.5.3)) + primeicons: + specifier: ^7.0.0 + version: 7.0.0 primevue: specifier: ^4.0.0 version: 4.0.0(@primeuix/utils@0.0.5)(vue@3.4.31(typescript@5.5.3)) @@ -26,6 +32,9 @@ importers: vue: specifier: ^3.4.31 version: 3.4.31(typescript@5.5.3) + vue-router: + specifier: ^4.4.0 + version: 4.4.0(vue@3.4.31(typescript@5.5.3)) devDependencies: '@primevue/auto-import-resolver': specifier: ^4.0.0 @@ -459,46 +468,55 @@ packages: resolution: {integrity: sha512-P9bSiAUnSSM7EmyRK+e5wgpqai86QOSv8BwvkGjLwYuOpaeomiZWifEos517CwbG+aZl1T4clSE1YqqH2JRs+g==} cpu: [arm] os: [linux] + libc: [glibc] '@rollup/rollup-linux-arm-musleabihf@4.18.1': resolution: {integrity: sha512-5RnjpACoxtS+aWOI1dURKno11d7krfpGDEn19jI8BuWmSBbUC4ytIADfROM1FZrFhQPSoP+KEa3NlEScznBTyQ==} cpu: [arm] os: [linux] + libc: [musl] '@rollup/rollup-linux-arm64-gnu@4.18.1': resolution: {integrity: sha512-8mwmGD668m8WaGbthrEYZ9CBmPug2QPGWxhJxh/vCgBjro5o96gL04WLlg5BA233OCWLqERy4YUzX3bJGXaJgQ==} cpu: [arm64] os: [linux] + libc: [glibc] '@rollup/rollup-linux-arm64-musl@4.18.1': resolution: {integrity: sha512-dJX9u4r4bqInMGOAQoGYdwDP8lQiisWb9et+T84l2WXk41yEej8v2iGKodmdKimT8cTAYt0jFb+UEBxnPkbXEQ==} cpu: [arm64] os: [linux] + libc: [musl] '@rollup/rollup-linux-powerpc64le-gnu@4.18.1': resolution: {integrity: sha512-V72cXdTl4EI0x6FNmho4D502sy7ed+LuVW6Ym8aI6DRQ9hQZdp5sj0a2usYOlqvFBNKQnLQGwmYnujo2HvjCxQ==} cpu: [ppc64] os: [linux] + libc: [glibc] '@rollup/rollup-linux-riscv64-gnu@4.18.1': resolution: {integrity: sha512-f+pJih7sxoKmbjghrM2RkWo2WHUW8UbfxIQiWo5yeCaCM0TveMEuAzKJte4QskBp1TIinpnRcxkquY+4WuY/tg==} cpu: [riscv64] os: [linux] + libc: [glibc] '@rollup/rollup-linux-s390x-gnu@4.18.1': resolution: {integrity: sha512-qb1hMMT3Fr/Qz1OKovCuUM11MUNLUuHeBC2DPPAWUYYUAOFWaxInaTwTQmc7Fl5La7DShTEpmYwgdt2hG+4TEg==} cpu: [s390x] os: [linux] + libc: [glibc] '@rollup/rollup-linux-x64-gnu@4.18.1': resolution: {integrity: sha512-7O5u/p6oKUFYjRbZkL2FLbwsyoJAjyeXHCU3O4ndvzg2OFO2GinFPSJFGbiwFDaCFc+k7gs9CF243PwdPQFh5g==} cpu: [x64] os: [linux] + libc: [glibc] '@rollup/rollup-linux-x64-musl@4.18.1': resolution: {integrity: sha512-pDLkYITdYrH/9Cv/Vlj8HppDuLMDUBmgsM0+N+xLtFd18aXgM9Nyqupb/Uw+HeidhfYg2lD6CXvz6CjoVOaKjQ==} cpu: [x64] os: [linux] + libc: [musl] '@rollup/rollup-win32-arm64-msvc@4.18.1': resolution: {integrity: sha512-W2ZNI323O/8pJdBGil1oCauuCzmVd9lDmWBBqxYZcOqWD6aWqJtVBQ1dFrF4dYpZPks6F+xCZHfzG5hYlSHZ6g==} @@ -542,24 +560,28 @@ packages: engines: {node: '>= 10'} cpu: [arm64] os: [linux] + libc: [glibc] '@tauri-apps/cli-linux-arm64-musl@2.0.0-beta.21': resolution: {integrity: sha512-s1rV01RIdowlPHfw7hTBnCEm2C3mZbynF+xpyRSv9vSczu4dpfwILMRwxB4nzMzdJ7RPHsf/R+5Ww86e8QM4Gw==} engines: {node: '>= 10'} cpu: [arm64] os: [linux] + libc: [musl] '@tauri-apps/cli-linux-x64-gnu@2.0.0-beta.21': resolution: {integrity: sha512-yGh7ktUycHT3mAnKxC7cx/vjcbjJzoxQCxnjWpmIayVwq+iXLD1mK7nRXRdJpL/rnBFTqqD29CKuypCEFiq3/A==} engines: {node: '>= 10'} cpu: [x64] os: [linux] + libc: [glibc] '@tauri-apps/cli-linux-x64-musl@2.0.0-beta.21': resolution: {integrity: sha512-+79b8O3tsjbGR47pJtcSKGmtqj4rsSxB5AfMb4UCkmoNkbaOzB0YS/ZieUGAb+SHXZ/MMs7mcl96N9SqYOL7hw==} engines: {node: '>= 10'} cpu: [x64] os: [linux] + libc: [musl] '@tauri-apps/cli-win32-arm64-msvc@2.0.0-beta.21': resolution: {integrity: sha512-rKlpcjx6t1ECZciMmHT5xkXKjC+O+TVxRKmA21tEq/Ezt7XdnufGko1hduwQmVJWkHxKg6ab7uf98ImMpDC5UA==} @@ -704,6 +726,9 @@ packages: '@vue/compiler-ssr@3.4.31': resolution: {integrity: sha512-RtefmITAje3fJ8FSg1gwgDhdKhZVntIVbwupdyZDSifZTRMiWxWehAOTCc8/KZDnBOcYQ4/9VWxsTbd3wT0hAA==} + '@vue/devtools-api@6.6.3': + resolution: {integrity: sha512-0MiMsFma/HqA6g3KLKn+AGpL1kgKhFWszC9U29NfpWK5LE7bjeXxySWJrOJ77hBz+TBrBQ7o4QJqbPbqbs8rJw==} + '@vue/language-core@2.0.26': resolution: {integrity: sha512-/lt6SfQ3O1yDAhPsnLv9iSUgXd1dMHqUm/t3RctfqjuwQf1LnftZ414X3UBn6aXT4MiwXWtbNJ4Z0NZWwDWgJQ==} peerDependencies: @@ -1174,6 +1199,18 @@ packages: resolution: {integrity: sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==} engines: {node: '>=8.6'} + pinia@2.1.7: + resolution: {integrity: sha512-+C2AHFtcFqjPih0zpYuvof37SFxMQ7OEG2zV9jRI12i9BOy3YQVAHwdKtyyc8pDcDyIc33WCIsZaCFWU7WWxGQ==} + peerDependencies: + '@vue/composition-api': ^1.4.0 + typescript: '>=4.4.4' + vue: ^2.6.14 || ^3.3.0 + peerDependenciesMeta: + '@vue/composition-api': + optional: true + typescript: + optional: true + pkg-types@1.1.3: resolution: {integrity: sha512-+JrgthZG6m3ckicaOB74TwQ+tBWsFl3qVQg7mN8ulwSOElJ7gBhKzj2VkCPnZ4NlF6kEquYU+RIYNVAvzd54UA==} @@ -1181,6 +1218,9 @@ packages: resolution: {integrity: sha512-0vzE+lAiG7hZl1/9I8yzKLx3aR9Xbof3fBHKunvMfOCYAtMhrsnccJY2iTURb9EZd5+pLuiNV9/c/GZJOHsgIw==} engines: {node: ^10 || ^12 || >=14} + primeicons@7.0.0: + resolution: {integrity: sha512-jK3Et9UzwzTsd6tzl2RmwrVY/b8raJ3QZLzoDACj+oTJ0oX7L9Hy+XnVwgo4QVKlKpnP/Ur13SXV/pVh4LzaDw==} + primevue@4.0.0: resolution: {integrity: sha512-2PFmmJqyXpOcKOdF+gbps5fpSXfoXZp2LwX+hya/b5SDseMt3UNboyEgVI6B+DNbJRrib35EbDiMw+7RIANQ1w==} engines: {node: '>=12.11.0'} @@ -1385,6 +1425,22 @@ packages: vscode-uri@3.0.8: resolution: {integrity: sha512-AyFQ0EVmsOZOlAnxoFOGOq1SQDWAB7C6aqMGS23svWAllfOaxbuFvcT8D1i8z3Gyn8fraVeZNNmN6e9bxxXkKw==} + vue-demi@0.14.8: + resolution: {integrity: sha512-Uuqnk9YE9SsWeReYqK2alDI5YzciATE0r2SkA6iMAtuXvNTMNACJLJEXNXaEy94ECuBe4Sk6RzRU80kjdbIo1Q==} + engines: {node: '>=12'} + hasBin: true + peerDependencies: + '@vue/composition-api': ^1.0.0-rc.1 + vue: ^3.0.0-0 || ^2.6.0 + peerDependenciesMeta: + '@vue/composition-api': + optional: true + + vue-router@4.4.0: + resolution: {integrity: sha512-HB+t2p611aIZraV2aPSRNXf0Z/oLZFrlygJm+sZbdJaW6lcFqEDQwnzUBXn+DApw+/QzDU/I9TeWx9izEjTmsA==} + peerDependencies: + vue: ^3.2.0 + vue-template-compiler@2.7.16: resolution: {integrity: sha512-AYbUWAJHLGGQM7+cNTELw+KsOG9nl2CnSv467WobS5Cv9uk3wFcnr1Etsz2sEIHEZvw1U+o9mRlEO6QbZvUPGQ==} @@ -2106,6 +2162,8 @@ snapshots: '@vue/compiler-dom': 3.4.31 '@vue/shared': 3.4.31 + '@vue/devtools-api@6.6.3': {} + '@vue/language-core@2.0.26(typescript@5.5.3)': dependencies: '@volar/language-core': 2.4.0-alpha.15 @@ -2557,6 +2615,14 @@ snapshots: picomatch@2.3.1: {} + pinia@2.1.7(typescript@5.5.3)(vue@3.4.31(typescript@5.5.3)): + dependencies: + '@vue/devtools-api': 6.6.3 + vue: 3.4.31(typescript@5.5.3) + vue-demi: 0.14.8(vue@3.4.31(typescript@5.5.3)) + optionalDependencies: + typescript: 5.5.3 + pkg-types@1.1.3: dependencies: confbox: 0.1.7 @@ -2569,6 +2635,8 @@ snapshots: picocolors: 1.0.1 source-map-js: 1.2.0 + primeicons@7.0.0: {} + primevue@4.0.0(@primeuix/utils@0.0.5)(vue@3.4.31(typescript@5.5.3)): dependencies: '@primevue/core': 4.0.0(@primeuix/utils@0.0.5)(vue@3.4.31(typescript@5.5.3)) @@ -2772,6 +2840,15 @@ snapshots: vscode-uri@3.0.8: {} + vue-demi@0.14.8(vue@3.4.31(typescript@5.5.3)): + dependencies: + vue: 3.4.31(typescript@5.5.3) + + vue-router@4.4.0(vue@3.4.31(typescript@5.5.3)): + dependencies: + '@vue/devtools-api': 6.6.3 + vue: 3.4.31(typescript@5.5.3) + vue-template-compiler@2.7.16: dependencies: de-indent: 1.0.2 diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index a1b3cee..d0b4427 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -3611,18 +3611,18 @@ checksum = "8eaa81235c7058867fa8c0e7314f33dcce9c215f535d1913822a2b3f5e289f3c" [[package]] name = "thiserror" -version = "1.0.61" +version = "1.0.62" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709" +checksum = "f2675633b1499176c2dff06b0856a27976a8f9d436737b4cf4f312d4d91d8bbb" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.61" +version = "1.0.62" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" +checksum = "d20468752b09f49e909e55a5d338caa8bedf615594e9d80bc4c565d30faf798c" dependencies = [ "proc-macro2", "quote", diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index da038bd..6eb9554 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -1,6 +1,12 @@ mod models; +mod state; mod utils; +#[tauri::command] +fn get_config(config: tauri::State) -> Result { + Ok(config.inner().clone()) +} + #[tauri::command] async fn get_file_size(url: &str) -> Result { match utils::get_file_size(url).await { @@ -15,8 +21,9 @@ async fn get_file_size(url: &str) -> Result { #[cfg_attr(mobile, tauri::mobile_entry_point)] pub fn run() { tauri::Builder::default() + .manage(state::Config::default()) .plugin(tauri_plugin_shell::init()) - .invoke_handler(tauri::generate_handler![get_file_size]) + .invoke_handler(tauri::generate_handler![get_config, get_file_size]) .run(tauri::generate_context!()) .expect("error while running tauri application"); } diff --git a/src-tauri/src/state.rs b/src-tauri/src/state.rs new file mode 100644 index 0000000..b4bf688 --- /dev/null +++ b/src-tauri/src/state.rs @@ -0,0 +1,16 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub(crate) struct Config { + pub(crate) preset_file: String, + pub(crate) threads_count: u32, +} + +impl Default for Config { + fn default() -> Self { + Self { + preset_file: String::from("presets/default.json"), + threads_count: 1, + } + } +} diff --git a/src/App.vue b/src/App.vue index bccf406..5aeb26f 100644 --- a/src/App.vue +++ b/src/App.vue @@ -2,9 +2,7 @@ diff --git a/src/main.ts b/src/main.ts index d239914..4f3e25d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,11 +1,22 @@ +import "virtual:uno.css"; +import "primeicons/primeicons.css"; + import { createApp } from "vue"; +import { createPinia } from "pinia"; import App from "./App.vue"; +import router from "./router"; import PrimeVue from 'primevue/config'; import Aura from '@primevue/themes/aura'; +import Ripple from "primevue/ripple"; +import Toast from "primevue/toast"; +import ToastService from "primevue/toastservice"; const app = createApp(App) +const pinia = createPinia() + app.use(PrimeVue, { + ripple: true, theme: { preset: Aura, options: { @@ -15,5 +26,11 @@ app.use(PrimeVue, { } } }); +app.use(ToastService); +app.directive("ripple", Ripple); +app.component("Toast", Toast); + +app.use(pinia); +app.use(router); app.mount("#app"); diff --git a/src/router/index.ts b/src/router/index.ts new file mode 100644 index 0000000..3af9206 --- /dev/null +++ b/src/router/index.ts @@ -0,0 +1,37 @@ +import { + createRouter, + createWebHashHistory, + type RouteRecordRaw, +} from "vue-router"; + +const views = import.meta.glob([ + "../views/**/*.vue", + "../views/**/index.vue", + "../views/**/\\[*\\].vue", +]); + +const routes: RouteRecordRaw[] = Object.entries(views).map( + ([filePath, component]) => { + let path = filePath + .replace(/^\.\.\/views\//, "") + .replace(/\.vue$/, "") + .replace(/^(.*)\/?index$/, "$1") + .replace(/\[(\w+)\]$/, ":$1"); + path = "/" + path; + + return { + path, + name: filePath.replace(/^\.\.\/views\//, ""), + component, + } satisfies RouteRecordRaw; + } +); + +console.log(routes.length); + +const router = createRouter({ + history: createWebHashHistory(import.meta.env.BASE_URL), + routes: [...routes], +}); + +export default router; diff --git a/src/types/index.ts b/src/types/index.ts new file mode 100644 index 0000000..cfa334d --- /dev/null +++ b/src/types/index.ts @@ -0,0 +1 @@ +export * from './utils' \ No newline at end of file diff --git a/src/types/utils.ts b/src/types/utils.ts new file mode 100644 index 0000000..186c8ff --- /dev/null +++ b/src/types/utils.ts @@ -0,0 +1,4 @@ +export interface FileSize { + size: number; + error?: string; +} diff --git a/src/views/index.vue b/src/views/index.vue new file mode 100644 index 0000000..d5dcbe0 --- /dev/null +++ b/src/views/index.vue @@ -0,0 +1,20 @@ + + + + + \ No newline at end of file