-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ✨ Complex scene of FileSelector.
- Loading branch information
1 parent
6262349
commit 5e4e183
Showing
11 changed files
with
187 additions
and
26 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use std::{ | ||
fmt::{self, Display, Formatter}, | ||
io, | ||
}; | ||
|
||
use serde::Serialize; | ||
|
||
#[derive(Debug)] | ||
pub struct Error(anyhow::Error); | ||
|
||
pub type Result<T> = std::result::Result<T, Error>; | ||
|
||
impl From<anyhow::Error> for Error { | ||
fn from(value: anyhow::Error) -> Self { | ||
Self(value) | ||
} | ||
} | ||
|
||
impl From<digital_signature_crypto::error::Error> for Error { | ||
fn from(value: digital_signature_crypto::error::Error) -> Self { | ||
Self(anyhow::Error::from(value)) | ||
} | ||
} | ||
|
||
impl From<io::Error> for Error { | ||
fn from(value: io::Error) -> Self { | ||
Self(anyhow::Error::from(value)) | ||
} | ||
} | ||
|
||
impl Display for Error { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { | ||
write!(f, "{}", self.0) | ||
} | ||
} | ||
|
||
impl std::error::Error for Error {} | ||
|
||
impl Serialize for Error { | ||
fn serialize<S>(&self, serializer: S) -> std::prelude::v1::Result<S::Ok, S::Error> | ||
where | ||
S: serde::Serializer, | ||
{ | ||
serializer.serialize_str(&self.0.to_string()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use std::path::Path; | ||
|
||
use serde::Serialize; | ||
use tokio::fs; | ||
|
||
use crate::error::Result; | ||
|
||
#[repr(u8)] | ||
#[derive(Debug, Clone, Copy)] | ||
pub enum FileType { | ||
File = 0, | ||
Dir = 1, | ||
Other = 2, | ||
Inexist = 3, | ||
} | ||
|
||
impl Serialize for FileType { | ||
fn serialize<S>(&self, serializer: S) -> std::prelude::v1::Result<S::Ok, S::Error> | ||
where | ||
S: serde::Serializer, | ||
{ | ||
serializer.serialize_u8(*self as u8) | ||
} | ||
} | ||
|
||
#[tauri::command] | ||
pub async fn file_type(path: &Path) -> Result<FileType> { | ||
Ok(match fs::metadata(path).await { | ||
Ok(metadata) => { | ||
if metadata.is_dir() { | ||
FileType::Dir | ||
} else if metadata.is_file() { | ||
FileType::File | ||
} else { | ||
FileType::Other | ||
} | ||
} | ||
Err(_) => FileType::Inexist, | ||
}) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use std::path::PathBuf; | ||
|
||
use super::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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//! Used for key generation. | ||
use std::path::Path; | ||
|
||
use digital_signature_crypto::keygen::write_key_pair; | ||
|
||
use crate::error::Result; | ||
|
||
#[tauri::command] | ||
pub async fn generate_key_pair(name: &str, email: &str, path: &Path) -> Result<()> { | ||
write_key_pair(name, email, path).await?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters