Skip to content

Commit

Permalink
refactor: ♻️ Refactor commands into its own module.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jisu-Woniu committed Nov 21, 2023
1 parent 110940c commit 4cd4ccb
Show file tree
Hide file tree
Showing 17 changed files with 139 additions and 93 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
"zeroize",
"zeroizing"
],
"conventionalCommits.scopes": ["deps"]
"conventionalCommits.scopes": ["deps"],
"typescript.tsdk": "node_modules/typescript/lib"
}
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": [
Expand Down
54 changes: 44 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }

Expand Down
15 changes: 9 additions & 6 deletions src-tauri/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl Serialize for FileType {
}

#[tauri::command]
pub async fn file_type(path: &Path) -> Result<FileType> {
pub async fn detect_file_type(path: &Path) -> Result<FileType> {
Ok(match fs::metadata(path).await {
Ok(metadata) => {
if metadata.is_dir() {
Expand All @@ -43,13 +43,16 @@ pub async fn file_type(path: &Path) -> Result<FileType> {
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);
}
}
7 changes: 5 additions & 2 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@

// 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;
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(())
}
6 changes: 3 additions & 3 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 18 additions & 0 deletions src/command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { invoke } from "@tauri-apps/api";

export const generateKeyPair = (name: string, email: string, path: string) =>
invoke<void>("generate_key_pair", {
email,
name,
path,
});

export const enum FileType {
dir = 1,
file = 0,
inexist = 3,
other = 2,
}

export const detectFileType = (path: string) =>
invoke<FileType>("detect_file_type", { path });
6 changes: 3 additions & 3 deletions src/components/ColorSwitcher.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<script setup lang="ts">
import { useColorMode, useCycleList } from "@vueuse/core";
import { watchEffect } from "vue";
import { useTheme } from "vuetify";
import { watchEffect } from "vue";
import { VBtn } from "vuetify/components";
import { useColorMode, useCycleList } from "@vueuse/core";
import AutoLightMode from "~icons/ic/twotone-brightness-auto";
import LightMode from "~icons/ic/twotone-light-mode";
import DarkMode from "~icons/ic/twotone-nightlight";
import LightMode from "~icons/ic/twotone-light-mode";
const theme = useTheme();
Expand Down
Loading

0 comments on commit 4cd4ccb

Please sign in to comment.