From 4cd4ccbf733e46b474ae7556b599bdac082997a2 Mon Sep 17 00:00:00 2001 From: Jisu-Woniu <31986081+Jisu-Woniu@users.noreply.github.com> Date: Wed, 22 Nov 2023 02:45:21 +0800 Subject: [PATCH] refactor: :recycle: Refactor commands into its own module. --- .vscode/settings.json | 3 +- CHANGELOG.md | 1 + package.json | 3 +- pnpm-lock.yaml | 54 ++++++++++++++++++++++++++------ src-tauri/Cargo.lock | 20 ++++++------ src-tauri/Cargo.toml | 2 +- src-tauri/src/fs.rs | 15 +++++---- src-tauri/src/main.rs | 7 +++-- src/App.vue | 6 ++-- src/command.ts | 18 +++++++++++ src/components/ColorSwitcher.vue | 6 ++-- src/components/FileSelector.vue | 46 +++++++++++---------------- src/main.ts | 23 +++++++------- src/views/KeygenView.vue | 18 +++++------ src/views/SignView.vue | 2 +- src/views/ValidateView.vue | 2 +- vite.config.ts | 6 ++-- 17 files changed, 139 insertions(+), 93 deletions(-) create mode 100644 src/command.ts diff --git a/.vscode/settings.json b/.vscode/settings.json index 2e6c844..7c35e24 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -15,5 +15,6 @@ "zeroize", "zeroizing" ], - "conventionalCommits.scopes": ["deps"] + "conventionalCommits.scopes": ["deps"], + "typescript.tsdk": "node_modules/typescript/lib" } diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ec003e..1b88a59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,7 @@ All notable changes to this project will be documented in this file. - :sparkles: Add light/dark mode switch. - :sparkles: Remember opened tab on refresh. - :sparkles: Complex scene of FileSelector. +- :sparkles: Finish key pair generation. ### Miscellaneous Tasks diff --git a/package.json b/package.json index 54c9eb1..b5137b8 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "autoprefixer": "^10.4.16", "browserslist": "^4.22.1", "eslint": "^8.54.0", + "eslint-plugin-perfectionist": "^2.4.0", "eslint-plugin-vue": "^9.18.1", "npm-run-all2": "^6.1.1", "postcss": "^8.4.31", @@ -49,7 +50,7 @@ "stylelint-prettier": "^4.0.2", "typescript": "^5.3.2", "unplugin-icons": "^0.17.4", - "vite": "^5.0.0", + "vite": "^5.0.2", "vue-tsc": "^1.8.22" }, "browserslist": [ diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d611368..f07e599 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -39,7 +39,7 @@ devDependencies: version: 20.9.3 '@vitejs/plugin-vue': specifier: ^4.5.0 - version: 4.5.0(vite@5.0.0)(vue@3.3.8) + version: 4.5.0(vite@5.0.2)(vue@3.3.8) '@vue/eslint-config-prettier': specifier: ^8.0.0 version: 8.0.0(eslint@8.54.0)(prettier@3.1.0) @@ -58,6 +58,9 @@ devDependencies: eslint: specifier: ^8.54.0 version: 8.54.0 + eslint-plugin-perfectionist: + specifier: ^2.4.0 + version: 2.4.0(eslint@8.54.0)(typescript@5.3.2) eslint-plugin-vue: specifier: ^9.18.1 version: 9.18.1(eslint@8.54.0) @@ -95,8 +98,8 @@ devDependencies: specifier: ^0.17.4 version: 0.17.4 vite: - specifier: ^5.0.0 - version: 5.0.0(@types/node@20.9.3) + specifier: ^5.0.2 + version: 5.0.2(@types/node@20.9.3) vue-tsc: specifier: ^1.8.22 version: 1.8.22(typescript@5.3.2) @@ -1245,14 +1248,14 @@ packages: resolution: {integrity: sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ==} dev: true - /@vitejs/plugin-vue@4.5.0(vite@5.0.0)(vue@3.3.8): + /@vitejs/plugin-vue@4.5.0(vite@5.0.2)(vue@3.3.8): resolution: {integrity: sha512-a2WSpP8X8HTEww/U00bU4mX1QpLINNuz/2KMNpLsdu3BzOpak3AGI1CJYBTXcc4SPhaD0eNRUp7IyQK405L5dQ==} engines: {node: ^14.18.0 || >=16.0.0} peerDependencies: vite: ^4.0.0 || ^5.0.0 vue: ^3.2.25 dependencies: - vite: 5.0.0(@types/node@20.9.3) + vite: 5.0.2(@types/node@20.9.3) vue: 3.3.8(typescript@5.3.2) dev: true @@ -1943,6 +1946,33 @@ packages: eslint: 8.54.0 dev: true + /eslint-plugin-perfectionist@2.4.0(eslint@8.54.0)(typescript@5.3.2): + resolution: {integrity: sha512-til+vyf56wAUgFv5guBA1Zo5lTw9xj2kCeK/g+9NBtsRy1rkGrlqnvxYNuFExcK3VsPhUUtx5UdScEDz9ahQ5Q==} + peerDependencies: + astro-eslint-parser: ^0.16.0 + eslint: '>=8.0.0' + svelte: '>=3.0.0' + svelte-eslint-parser: ^0.33.0 + vue-eslint-parser: '>=9.0.0' + peerDependenciesMeta: + astro-eslint-parser: + optional: true + svelte: + optional: true + svelte-eslint-parser: + optional: true + vue-eslint-parser: + optional: true + dependencies: + '@typescript-eslint/utils': 6.12.0(eslint@8.54.0)(typescript@5.3.2) + eslint: 8.54.0 + minimatch: 9.0.3 + natural-compare-lite: 1.4.0 + transitivePeerDependencies: + - supports-color + - typescript + dev: true + /eslint-plugin-prettier@5.0.1(eslint-config-prettier@8.10.0)(eslint@8.54.0)(prettier@3.1.0): resolution: {integrity: sha512-m3u5RnR56asrwV/lDC4GHorlW75DsFfmUcjfCYylTUs85dBRnB7VM6xG8eCMJdeDRnppzmxZVf1GEPJvl1JmNg==} engines: {node: ^14.18.0 || >=16.0.0} @@ -2731,6 +2761,10 @@ packages: engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1} hasBin: true + /natural-compare-lite@1.4.0: + resolution: {integrity: sha512-Tj+HTDSJJKaZnfiuw+iaF9skdPpTo2GtEly5JHnWV/hfv2Qj/9RKsGISQtLh2ox3l5EAGw487hnBee0sIJ6v2g==} + dev: true + /natural-compare@1.4.0: resolution: {integrity: sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==} dev: true @@ -3369,7 +3403,7 @@ packages: '@types/normalize-package-data': 2.4.4 normalize-package-data: 6.0.0 parse-json: 7.1.1 - type-fest: 4.8.1 + type-fest: 4.8.2 dev: true /readdirp@3.6.0: @@ -3773,8 +3807,8 @@ packages: engines: {node: '>=14.16'} dev: true - /type-fest@4.8.1: - resolution: {integrity: sha512-ShaaYnjf+0etG8W/FumARKMjjIToy/haCaTjN2dvcewOSoNqCQzdgG7m2JVOlM5qndGTHjkvsrWZs+k/2Z7E0Q==} + /type-fest@4.8.2: + resolution: {integrity: sha512-mcvrCjixA5166hSrUoJgGb9gBQN4loMYyj9zxuMs/66ibHNEFd5JXMw37YVDx58L4/QID9jIzdTBB4mDwDJ6KQ==} engines: {node: '>=16'} dev: true @@ -3864,8 +3898,8 @@ packages: spdx-expression-parse: 3.0.1 dev: true - /vite@5.0.0(@types/node@20.9.3): - resolution: {integrity: sha512-ESJVM59mdyGpsiNAeHQOR/0fqNoOyWPYesFto8FFZugfmhdHx8Fzd8sF3Q/xkVhZsyOxHfdM7ieiVAorI9RjFw==} + /vite@5.0.2(@types/node@20.9.3): + resolution: {integrity: sha512-6CCq1CAJCNM1ya2ZZA7+jS2KgnhbzvxakmlIjN24cF/PXhRMzpM/z8QgsVJA/Dm5fWUWnVEsmtBoMhmerPxT0g==} engines: {node: ^18.0.0 || >=20.0.0} hasBin: true peerDependencies: diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index e05a28f..d252458 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -2830,9 +2830,9 @@ dependencies = [ [[package]] name = "rsa" -version = "0.9.3" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86ef35bf3e7fe15a53c4ab08a998e42271eab13eb0db224126bc7bc4c4bad96d" +checksum = "6a3211b01eea83d80687da9eef70e39d65144a3894866a5153a2723e425a157f" dependencies = [ "const-oid", "digest", @@ -2960,18 +2960,18 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.192" +version = "1.0.193" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bca2a08484b285dcb282d0f67b26cadc0df8b19f8c12502c13d966bf9482f001" +checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.192" +version = "1.0.193" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6c7207fbec9faa48073f3e3074cbe553af6ea512d7c21ba46e434e70ea9fbc1" +checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" dependencies = [ "proc-macro2", "quote", @@ -3885,9 +3885,9 @@ checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" [[package]] name = "uuid" -version = "1.5.0" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ad59a7560b41a70d191093a945f0b87bc1deeda46fb237479708a1d6b6cdfc" +checksum = "5e395fcf16a7a3d8127ec99782007af141946b4795001f876d54fb0d55978560" dependencies = [ "getrandom 0.2.11", ] @@ -4374,9 +4374,9 @@ dependencies = [ [[package]] name = "wry" -version = "0.24.4" +version = "0.24.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ef04bdad49eba2e01f06e53688c8413bd6a87b0bc14b72284465cf96e3578e" +checksum = "bab99e77ec1b1b2f1ebce97a4b1ab41e29d8f8fd10c052750938654711e959dc" dependencies = [ "base64 0.13.1", "block", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 2f7a25f..87bda00 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -23,7 +23,7 @@ tauri-build = { version = "1.5.0", features = [] } [dependencies] anyhow = { version = "1.0.75", features = ["backtrace"] } -serde = { version = "1.0.192", features = ["derive"] } +serde = { version = "1.0.193", features = ["derive"] } serde_json = "1.0.108" tokio = { version = "1.34.0", features = ["fs", "macros", "rt", "rt-multi-thread"] } diff --git a/src-tauri/src/fs.rs b/src-tauri/src/fs.rs index 3a78692..b285093 100644 --- a/src-tauri/src/fs.rs +++ b/src-tauri/src/fs.rs @@ -24,7 +24,7 @@ impl Serialize for FileType { } #[tauri::command] -pub async fn file_type(path: &Path) -> Result { +pub async fn detect_file_type(path: &Path) -> Result { Ok(match fs::metadata(path).await { Ok(metadata) => { if metadata.is_dir() { @@ -43,13 +43,16 @@ pub async fn file_type(path: &Path) -> Result { mod tests { use std::path::PathBuf; - use super::file_type; + use super::detect_file_type; #[tokio::test] async fn test() { - println!("{:?}", file_type(&PathBuf::from("/home/")).await); - println!("{:?}", file_type(&PathBuf::from("/etc/fstab")).await); - println!("{:?}", file_type(&PathBuf::from("/home/inexist")).await); - println!("{:?}", file_type(&PathBuf::from("/bin/sh")).await); + println!("{:?}", detect_file_type(&PathBuf::from("/home/")).await); + println!("{:?}", detect_file_type(&PathBuf::from("/etc/fstab")).await); + println!( + "{:?}", + detect_file_type(&PathBuf::from("/home/inexist")).await + ); + println!("{:?}", detect_file_type(&PathBuf::from("/bin/sh")).await); } } diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index ba7fc42..fe08add 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -3,7 +3,7 @@ // Learn more about Tauri commands at https://tauri.app/v1/guides/features/command -use crate::{fs::file_type, keygen::generate_key_pair}; +use crate::{fs::detect_file_type, keygen::generate_key_pair}; mod error; mod fs; @@ -11,7 +11,10 @@ mod keygen; fn main() -> anyhow::Result<()> { tauri::Builder::default() - .invoke_handler(tauri::generate_handler![generate_key_pair, file_type]) + .invoke_handler(tauri::generate_handler![ + generate_key_pair, + detect_file_type + ]) .run(tauri::generate_context!())?; Ok(()) } diff --git a/src/App.vue b/src/App.vue index 292f973..734fb63 100644 --- a/src/App.vue +++ b/src/App.vue @@ -7,12 +7,12 @@ import { VWindow, VWindowItem, } from "vuetify/components"; -import { mdiFileKey, mdiFileCheck, mdiKeyChain } from "@mdi/js"; +import KeygenView from "@/views/KeygenView.vue"; import SignView from "@/views/SignView.vue"; import ValidateView from "@/views/ValidateView.vue"; -import KeygenView from "@/views/KeygenView.vue"; -import ColorSwitcher from "@/components/ColorSwitcher.vue"; +import { mdiFileCheck, mdiFileKey, mdiKeyChain } from "@mdi/js"; import { useSessionStorage } from "@vueuse/core"; +import ColorSwitcher from "@/components/ColorSwitcher.vue"; const enum Tab { sign, diff --git a/src/command.ts b/src/command.ts new file mode 100644 index 0000000..5bd0e0c --- /dev/null +++ b/src/command.ts @@ -0,0 +1,18 @@ +import { invoke } from "@tauri-apps/api"; + +export const generateKeyPair = (name: string, email: string, path: string) => + invoke("generate_key_pair", { + email, + name, + path, + }); + +export const enum FileType { + dir = 1, + file = 0, + inexist = 3, + other = 2, +} + +export const detectFileType = (path: string) => + invoke("detect_file_type", { path }); diff --git a/src/components/ColorSwitcher.vue b/src/components/ColorSwitcher.vue index 80b59cb..cd05bca 100644 --- a/src/components/ColorSwitcher.vue +++ b/src/components/ColorSwitcher.vue @@ -1,11 +1,11 @@