diff --git a/Cargo.lock b/Cargo.lock index 2cbac99..cf0cf9b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -443,6 +443,15 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "fsevent-sys" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76ee7a02da4d231650c7cea31349b889be2f45ddb3ef3032d2ec8185f6313fd2" +dependencies = [ + "libc", +] + [[package]] name = "futures" version = "0.3.28" @@ -910,6 +919,7 @@ checksum = "5738a2795d57ea20abec2d6d76c6081186709c0024187cd5977265eda6598b51" dependencies = [ "bitflags 1.3.2", "filetime", + "fsevent-sys", "inotify", "kqueue", "libc", diff --git a/Cargo.toml b/Cargo.toml index 5d883a3..79e9b30 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,3 +50,4 @@ default-features = false [dependencies.notify] version = "6" default-features = false +features = ["macos_fsevent"] diff --git a/src/routes.rs b/src/routes.rs index 28292f1..5c4c95b 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -1,7 +1,7 @@ use crate::{ assets::ErrorTemplate, links::{next_url, previous_url}, - sites::{ Names}, + sites::get_global_names, }; use rocket::{ @@ -28,25 +28,25 @@ pub fn index() -> &'static str { } #[get("/previous?")] -pub fn previous(source_url: String) -> Result { - match previous_url(&source_url, &Names::global()) { +pub async fn previous(source_url: String) -> Result { + match previous_url(&source_url, &get_global_names().await) { Some(url) => Ok(Redirect::to(format!("https://{}", url))), None => Err(Status::NotFound), } } #[get("/next?")] -pub fn next(source_url: String) -> Result { - match next_url(&source_url, &Names::global()) { +pub async fn next(source_url: String) -> Result { + match next_url(&source_url, &get_global_names().await) { Some(url) => Ok(Redirect::to(format!("https://{}", url))), None => Err(Status::NotFound), } } #[get("/name?")] -pub fn name(source_url: String) -> Result, Status> { - let previous_site_name = previous_url(&source_url, &Names::global()); - let next_site_name = next_url(&source_url, &Names::global()); +pub async fn name(source_url: String) -> Result, Status> { + let previous_site_name = previous_url(&source_url, &get_global_names().await); + let next_site_name = next_url(&source_url, &get_global_names().await); if previous_site_name.is_none() && next_site_name.is_none() { return Err(Status::NotFound); diff --git a/src/sites.rs b/src/sites.rs index 6509ea8..94b6b04 100644 --- a/src/sites.rs +++ b/src/sites.rs @@ -1,19 +1,17 @@ +use rocket::tokio::sync::Mutex; use shared::{ directories, errors::{Error, ErrorStatus}, names::{self, Site}, }; -use std::sync::{Mutex, OnceLock}; +use std::sync::{OnceLock}; -pub struct Names {} +pub async fn get_global_names() -> Vec { + NAMES.get().unwrap().lock().await.clone() +} -impl Names { - pub fn global() -> Vec { - NAMES.get().unwrap().lock().unwrap().clone() - } - pub fn set() { - *NAMES.get().unwrap().lock().unwrap() = get_names(); - } +pub fn set_names() { + *NAMES.get().unwrap().blocking_lock() = get_names(); } static NAMES: OnceLock>> = OnceLock::new(); diff --git a/src/watcher.rs b/src/watcher.rs index b908de7..34d589b 100644 --- a/src/watcher.rs +++ b/src/watcher.rs @@ -1,7 +1,8 @@ use notify::{Result, Watcher}; use shared::directories; -use crate::sites::Names; +use crate::sites; + pub(crate) fn hot_reloading() { let (tx, rx) = std::sync::mpsc::channel(); @@ -21,7 +22,7 @@ fn watch(res: Result) { match res { Ok(event) => { if event.kind.is_modify() { - Names::set(); + sites::set_names(); } } Err(err) => println!("Error: {}", err),