From ebc16ebadb9c6f4f62dedf4bc9e711f37fa043cc Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 27 Jan 2024 12:50:35 +0100 Subject: [PATCH 1/4] add config file support --- src-tauri/Cargo.lock | 30 ++++++++ src-tauri/Cargo.toml | 2 + src-tauri/src/config.rs | 158 ++++++++++++++++++++++++++++++++++++++++ src-tauri/src/main.rs | 14 +++- 4 files changed, 200 insertions(+), 4 deletions(-) create mode 100644 src-tauri/src/config.rs diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 07cd984..79a2034 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -1146,6 +1146,15 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "home" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" +dependencies = [ + "windows-sys 0.52.0", +] + [[package]] name = "html5ever" version = "0.26.0" @@ -1565,8 +1574,10 @@ checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb" name = "note-rs" version = "0.1.0" dependencies = [ + "home", "serde", "serde_json", + "serde_yaml", "tauri", "tauri-build", ] @@ -2315,6 +2326,19 @@ dependencies = [ "syn 2.0.48", ] +[[package]] +name = "serde_yaml" +version = "0.9.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1bf28c79a99f70ee1f1d83d10c875d2e70618417fda01ad1785e027579d9d38" +dependencies = [ + "indexmap 2.1.0", + "itoa 1.0.10", + "ryu", + "serde", + "unsafe-libyaml", +] + [[package]] name = "serialize-to-javascript" version = "0.1.1" @@ -3063,6 +3087,12 @@ version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" +[[package]] +name = "unsafe-libyaml" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab4c90930b95a82d00dc9e9ac071b4991924390d46cbd0dfe566148667605e4b" + [[package]] name = "url" version = "2.5.0" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 2595459..aae8107 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -18,6 +18,8 @@ tauri-build = { version = "1.5.0", features = [] } serde_json = "1.0" serde = { version = "1.0", features = ["derive"] } tauri = { version = "1.5.3", features = [ "window-unminimize", "window-unmaximize", "window-maximize", "window-show", "window-minimize", "window-close", "window-start-dragging", "window-hide"] } +serde_yaml = "0.9.30" +home = "0.5.9" [features] # this feature is used for production builds or when `devPath` points to the filesystem and the built-in dev server is disabled. diff --git a/src-tauri/src/config.rs b/src-tauri/src/config.rs new file mode 100644 index 0000000..87348f7 --- /dev/null +++ b/src-tauri/src/config.rs @@ -0,0 +1,158 @@ +use serde::{Serialize, Deserialize}; +use home::{home_dir}; + +use std::fs; +use std::path::{Path, PathBuf}; +use core::fmt::Display; + +const DEFAULT_CONFIG_FILENAME: &str = ".noters.yaml"; + +pub struct Config { + filename: Box, + config_file: ConfigFile +} + +#[derive(Serialize, Deserialize, Debug)] +struct ConfigFile { + meta: MetaInfo, + values: ConfigValues +} + +#[derive(Serialize, Deserialize, Debug)] +struct MetaInfo { + version: u32 +} + +#[derive(Serialize, Deserialize, Debug)] +struct ConfigValues { + base_dir: String +} + +fn get_home_dir() -> PathBuf { + home_dir().unwrap_or(PathBuf::from(".")) +} + +struct ConfigError { + message: String +} + +impl ConfigError { + fn new(message: &str) -> Self { + ConfigError { message: message.into() } + } +} + +impl From for ConfigError { + fn from(value: E) -> Self { + ConfigError { message: value.to_string() } + } +} + +impl Config { + + /// Creates a new config with default values. + fn new() -> Self { + Config { + filename: get_home_dir().join(DEFAULT_CONFIG_FILENAME).as_path().into(), + config_file: { + ConfigFile { + meta: { + MetaInfo { + version: 1 + } + }, + values: { + ConfigValues { + base_dir: String::from("{home}/.notes") + } + } + } + } + } + } + + /// Loads the config from the default config file. + /// + /// The default config file is located at ~/.noters.yaml. + /// When the file does not exist, a default config is created and stored + /// at the default config file location. + pub fn from_default_file() -> Self { + let filename = get_home_dir().join(DEFAULT_CONFIG_FILENAME); + + match Config::from_file(filename.as_path()) { + Ok(config) => config, + Err(error) => { + eprintln!("warning: failed to load config {:?}: {}", filename, error.message); + let config = Config::new(); + config.save(); + config + } + } + } + + /// Try to load the config from a given path. + fn from_file(filename: &Path) -> Result { + let text = fs::read_to_string(filename)?; + let config_file = serde_yaml::from_str::(&text)?; + + if config_file.meta.version != 1 { + return Err(ConfigError::new("unknown file format (version mismatch)")); + } + + Ok(Config { + filename: filename.into(), + config_file: config_file + }) + } + + /// Returns the base path, where the notes are stored. + pub fn get_base_path(&self) -> PathBuf { + let home_dir = get_home_dir(); + let base_dir = &self.config_file.values.base_dir; + + PathBuf::from(base_dir.replace("{home}", &home_dir.to_string_lossy())) + } + + /// Tries to save the configuration. + /// + /// Note that this function will not fail, even when the config file is not written. + /// This behavior is intended, since there is no good way to handle those errors. + /// At least, an error message is emitted. + fn save(&self) { + let text = serde_yaml::to_string(&self.config_file).unwrap(); + if let Err(error) = fs::write(self.filename.as_ref(), text.as_bytes()) { + eprintln!("error: failed to save config: {:?}: {}", self.filename, error.to_string()); + } + else { + eprintln!("info: saved config: {:?}", self.filename); + } + } +} + +#[cfg(test)] +mod tests { + +use crate::Config; +use crate::config::{get_home_dir}; + +#[test] +fn create_default_config() { + let config = Config::new(); + + assert_eq!(1, config.config_file.meta.version); + assert_eq!(".noters.yaml", config.filename.file_name().unwrap()); + assert_eq!("{home}/.notes", config.config_file.values.base_dir); +} + +#[test] +fn get_base_path_resolves_home() { + let config = Config::new(); + + let expected = get_home_dir().join(".notes"); + let actual = config.get_base_path(); + + assert_eq!(expected, actual); +} + + +} \ No newline at end of file diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index ca85ce4..079376e 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -2,10 +2,15 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] use std::{fs::DirEntry, io::{Error, Result}, path::{Path, PathBuf}}; -use tauri::api::path::home_dir; + +mod config; +use config::{Config}; fn main() { + let config = Config::from_default_file(); + tauri::Builder::default() + .manage(config) .invoke_handler(tauri::generate_handler![ list ]) @@ -17,13 +22,14 @@ fn main() { /// /// list all directories in the base directory that have a `README.md` file inside #[tauri::command] -async fn list() -> Vec { - let base_path = Path::new(home_dir().unwrap().as_path()).join(".notes"); +fn list(config: tauri::State<'_, Config>) -> Vec { + let base_path = config.get_base_path().join(".notes"); match get_note_names(base_path) { Ok(note_names) => return note_names, Err(e) => error_handling(e.to_string()) } - return Vec::::new(); + + Vec::::new() } /// list all directories in `base_path` that have a `README.md` file inside From 1c200241f3a8b0f89a5cbf0302a4f8740f1649c1 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 27 Jan 2024 14:21:26 +0100 Subject: [PATCH 2/4] add unit tests --- src-tauri/Cargo.lock | 63 ++++++++++++++++++++++++ src-tauri/Cargo.toml | 3 ++ src-tauri/src/config.rs | 105 +++++++++++++++++++++++++++++++++++++--- 3 files changed, 165 insertions(+), 6 deletions(-) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 79a2034..48734d8 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -728,6 +728,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "fuchsia-cprng" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" + [[package]] name = "futf" version = "0.1.5" @@ -1580,6 +1586,7 @@ dependencies = [ "serde_yaml", "tauri", "tauri-build", + "tempdir", ] [[package]] @@ -1999,6 +2006,19 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rand" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" +dependencies = [ + "fuchsia-cprng", + "libc", + "rand_core 0.3.1", + "rdrand", + "winapi", +] + [[package]] name = "rand" version = "0.7.3" @@ -2044,6 +2064,21 @@ dependencies = [ "rand_core 0.6.4", ] +[[package]] +name = "rand_core" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" +dependencies = [ + "rand_core 0.4.2", +] + +[[package]] +name = "rand_core" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" + [[package]] name = "rand_core" version = "0.5.1" @@ -2086,6 +2121,15 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2ff9a1f06a88b01621b7ae906ef0211290d1c8a168a15542486a8f61c0833b9" +[[package]] +name = "rdrand" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" +dependencies = [ + "rand_core 0.3.1", +] + [[package]] name = "redox_syscall" version = "0.4.1" @@ -2150,6 +2194,15 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" +[[package]] +name = "remove_dir_all" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" +dependencies = [ + "winapi", +] + [[package]] name = "rustc-demangle" version = "0.1.23" @@ -2800,6 +2853,16 @@ dependencies = [ "toml 0.7.8", ] +[[package]] +name = "tempdir" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8" +dependencies = [ + "rand 0.4.6", + "remove_dir_all", +] + [[package]] name = "tempfile" version = "3.9.0" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index aae8107..cdffc20 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -26,3 +26,6 @@ home = "0.5.9" # If you use cargo directly instead of tauri's cli you can use this feature flag to switch between tauri's `dev` and `build` modes. # DO NOT REMOVE!! custom-protocol = [ "tauri/custom-protocol" ] + +[dev-dependencies] +tempdir = "0.3.7" diff --git a/src-tauri/src/config.rs b/src-tauri/src/config.rs index 87348f7..3eb2f1c 100644 --- a/src-tauri/src/config.rs +++ b/src-tauri/src/config.rs @@ -32,6 +32,7 @@ fn get_home_dir() -> PathBuf { home_dir().unwrap_or(PathBuf::from(".")) } +#[derive(Debug)] struct ConfigError { message: String } @@ -51,9 +52,9 @@ impl From for ConfigError { impl Config { /// Creates a new config with default values. - fn new() -> Self { + fn new(filename: &Path) -> Self { Config { - filename: get_home_dir().join(DEFAULT_CONFIG_FILENAME).as_path().into(), + filename: filename.into(), config_file: { ConfigFile { meta: { @@ -83,7 +84,7 @@ impl Config { Ok(config) => config, Err(error) => { eprintln!("warning: failed to load config {:?}: {}", filename, error.message); - let config = Config::new(); + let config = Config::new(filename.as_path()); config.save(); config } @@ -134,19 +135,24 @@ mod tests { use crate::Config; use crate::config::{get_home_dir}; +use tempdir::TempDir; +use std::fs; +use std::path::{PathBuf}; #[test] fn create_default_config() { - let config = Config::new(); + let path = PathBuf::from("/test/config.yaml"); + let config = Config::new(path.as_path()); assert_eq!(1, config.config_file.meta.version); - assert_eq!(".noters.yaml", config.filename.file_name().unwrap()); + assert_eq!(*path, *config.filename); assert_eq!("{home}/.notes", config.config_file.values.base_dir); } #[test] fn get_base_path_resolves_home() { - let config = Config::new(); + let path = PathBuf::from("/test/config.yaml"); + let config = Config::new(path.as_path()); let expected = get_home_dir().join(".notes"); let actual = config.get_base_path(); @@ -154,5 +160,92 @@ fn get_base_path_resolves_home() { assert_eq!(expected, actual); } +#[test] +fn load_config_from_file() { + let text = br##"meta: + version: 1 +values: + base_dir: '/path/to/notes'"##; + + let temp_dir = TempDir::new("noters-test").unwrap(); + let config_path = temp_dir.path().join("config.yaml"); + fs::write(config_path.clone(), text).unwrap(); + + let config = Config::from_file(config_path.as_path()).unwrap(); + assert_eq!("/path/to/notes", config.config_file.values.base_dir); + + let _ = temp_dir.close(); +} + +#[test] +fn fail_to_load_non_existing_config_file() { + let temp_dir = TempDir::new("noters-test").unwrap(); + let config_path = temp_dir.path().join("config.yaml"); + + let config = Config::from_file(config_path.as_path()); + assert!(config.is_err()); + + let _ = temp_dir.close(); +} + +#[test] +fn fail_to_load_invalid_config_file() { + let text = br##"\t this is not yaml"##; + + let temp_dir = TempDir::new("noters-test").unwrap(); + let config_path = temp_dir.path().join("config.yaml"); + fs::write(config_path.clone(), text).unwrap(); + + let config = Config::from_file(config_path.as_path()); + assert!(config.is_err()); + + let _ = temp_dir.close(); +} + +#[test] +fn fail_to_load_config_file_with_wrong_version() { + let text = br##"meta: + version: 0 +values: + base_dir: '/path/to/notes'"##; + + let temp_dir = TempDir::new("noters-test").unwrap(); + let config_path = temp_dir.path().join("config.yaml"); + fs::write(config_path.clone(), text).unwrap(); + + let config = Config::from_file(config_path.as_path()); + assert!(config.is_err()); + + let _ = temp_dir.close(); +} + +#[test] +fn save_config_file() { + let temp_dir = TempDir::new("noters-test").unwrap(); + let config_path = temp_dir.path().join("config.yaml"); + + let config = Config::new(config_path.as_path()); + config.save(); + + let config = Config::from_file(config_path.as_path()); + assert!(config.is_ok()); + + let _ = temp_dir.close(); +} + +#[test] +fn save_does_not_fail_if_config_file_cannot_be_written() { + let temp_dir = TempDir::new("noters-test").unwrap(); + let config_path = temp_dir.path().join("non-existing-dir").join("config.yaml"); + + let config = Config::new(config_path.as_path()); + config.save(); + + let config = Config::from_file(config_path.as_path()); + assert!(config.is_err()); + + let _ = temp_dir.close(); +} + } \ No newline at end of file From 8ca929b62e00ffa3ae5ed8fffb5e5a4085da5dc5 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 27 Jan 2024 14:27:44 +0100 Subject: [PATCH 3/4] use temfile instead of tempdir (crate tempdir is deprecated) --- src-tauri/Cargo.lock | 64 +---------------------------------------- src-tauri/Cargo.toml | 2 +- src-tauri/src/config.rs | 14 ++++----- 3 files changed, 9 insertions(+), 71 deletions(-) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 48734d8..78e12ee 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -728,12 +728,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "fuchsia-cprng" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" - [[package]] name = "futf" version = "0.1.5" @@ -1586,7 +1580,7 @@ dependencies = [ "serde_yaml", "tauri", "tauri-build", - "tempdir", + "tempfile", ] [[package]] @@ -2006,19 +2000,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "rand" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" -dependencies = [ - "fuchsia-cprng", - "libc", - "rand_core 0.3.1", - "rdrand", - "winapi", -] - [[package]] name = "rand" version = "0.7.3" @@ -2064,21 +2045,6 @@ dependencies = [ "rand_core 0.6.4", ] -[[package]] -name = "rand_core" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" -dependencies = [ - "rand_core 0.4.2", -] - -[[package]] -name = "rand_core" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" - [[package]] name = "rand_core" version = "0.5.1" @@ -2121,15 +2087,6 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2ff9a1f06a88b01621b7ae906ef0211290d1c8a168a15542486a8f61c0833b9" -[[package]] -name = "rdrand" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" -dependencies = [ - "rand_core 0.3.1", -] - [[package]] name = "redox_syscall" version = "0.4.1" @@ -2194,15 +2151,6 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" -[[package]] -name = "remove_dir_all" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" -dependencies = [ - "winapi", -] - [[package]] name = "rustc-demangle" version = "0.1.23" @@ -2853,16 +2801,6 @@ dependencies = [ "toml 0.7.8", ] -[[package]] -name = "tempdir" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8" -dependencies = [ - "rand 0.4.6", - "remove_dir_all", -] - [[package]] name = "tempfile" version = "3.9.0" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index cdffc20..e6f5e5a 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -28,4 +28,4 @@ home = "0.5.9" custom-protocol = [ "tauri/custom-protocol" ] [dev-dependencies] -tempdir = "0.3.7" +tempfile = "3.9.0" diff --git a/src-tauri/src/config.rs b/src-tauri/src/config.rs index 3eb2f1c..20c348e 100644 --- a/src-tauri/src/config.rs +++ b/src-tauri/src/config.rs @@ -135,7 +135,7 @@ mod tests { use crate::Config; use crate::config::{get_home_dir}; -use tempdir::TempDir; +use tempfile::tempdir; use std::fs; use std::path::{PathBuf}; @@ -167,7 +167,7 @@ fn load_config_from_file() { values: base_dir: '/path/to/notes'"##; - let temp_dir = TempDir::new("noters-test").unwrap(); + let temp_dir = tempdir().unwrap(); let config_path = temp_dir.path().join("config.yaml"); fs::write(config_path.clone(), text).unwrap(); @@ -179,7 +179,7 @@ values: #[test] fn fail_to_load_non_existing_config_file() { - let temp_dir = TempDir::new("noters-test").unwrap(); + let temp_dir = tempdir().unwrap(); let config_path = temp_dir.path().join("config.yaml"); let config = Config::from_file(config_path.as_path()); @@ -192,7 +192,7 @@ fn fail_to_load_non_existing_config_file() { fn fail_to_load_invalid_config_file() { let text = br##"\t this is not yaml"##; - let temp_dir = TempDir::new("noters-test").unwrap(); + let temp_dir = tempdir().unwrap(); let config_path = temp_dir.path().join("config.yaml"); fs::write(config_path.clone(), text).unwrap(); @@ -209,7 +209,7 @@ fn fail_to_load_config_file_with_wrong_version() { values: base_dir: '/path/to/notes'"##; - let temp_dir = TempDir::new("noters-test").unwrap(); + let temp_dir = tempdir().unwrap(); let config_path = temp_dir.path().join("config.yaml"); fs::write(config_path.clone(), text).unwrap(); @@ -221,7 +221,7 @@ values: #[test] fn save_config_file() { - let temp_dir = TempDir::new("noters-test").unwrap(); + let temp_dir = tempdir().unwrap(); let config_path = temp_dir.path().join("config.yaml"); let config = Config::new(config_path.as_path()); @@ -235,7 +235,7 @@ fn save_config_file() { #[test] fn save_does_not_fail_if_config_file_cannot_be_written() { - let temp_dir = TempDir::new("noters-test").unwrap(); + let temp_dir = tempdir().unwrap(); let config_path = temp_dir.path().join("non-existing-dir").join("config.yaml"); let config = Config::new(config_path.as_path()); From 7ee0af8510b24ec1cf8219717d95cb3a87a3ad14 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 27 Jan 2024 19:25:45 +0100 Subject: [PATCH 4/4] make list command async again --- src-tauri/src/main.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 079376e..d589cdb 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -22,14 +22,14 @@ fn main() { /// /// list all directories in the base directory that have a `README.md` file inside #[tauri::command] -fn list(config: tauri::State<'_, Config>) -> Vec { +async fn list(config: tauri::State<'_, Config>) -> std::result::Result, String> { let base_path = config.get_base_path().join(".notes"); match get_note_names(base_path) { - Ok(note_names) => return note_names, + Ok(note_names) => return Ok(note_names), Err(e) => error_handling(e.to_string()) } - Vec::::new() + Ok(Vec::::new()) } /// list all directories in `base_path` that have a `README.md` file inside