Add daemon discovery check

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/4/head
trivernis 3 years ago
parent faa7b4e17c
commit ce516ca498

@ -17,6 +17,7 @@ mime_guess = {version = "2.0.3", optional=true}
serde_piecewise_default = "0.2.0"
futures = {version = "0.3.17", optional=true}
url = {version = "2.2.2", optional=true }
pathsearch = {version="0.2.0", optional=true}
[dependencies.bromine]
version = "0.16.1"
@ -48,4 +49,4 @@ optional = true
[features]
tauri-plugin = ["client-api","tauri", "parking_lot", "serde_json", "tokio", "toml", "directories", "mime_guess", "futures", "url"]
client-api = ["bromine", "async-trait", "tokio"]
client-api = ["bromine", "async-trait", "tokio", "pathsearch"]

@ -1,2 +1,9 @@
use pathsearch::find_executable_in_path;
use std::path::PathBuf;
pub mod cli;
pub mod error;
pub fn find_daemon_executable() -> Option<PathBuf> {
find_executable_in_path("mediarepo-daemon")
}

@ -6,9 +6,16 @@ use std::io::ErrorKind;
use std::net::{SocketAddr, ToSocketAddrs};
use tokio::net::TcpListener;
#[tauri::command]
pub async fn has_executable(app_state: AppAccess<'_>) -> PluginResult<bool> {
let settings = app_state.settings.read().await;
Ok(settings.daemon_path.is_some())
}
#[tauri::command]
pub async fn init_repository(app_state: AppAccess<'_>, repo_path: String) -> PluginResult<()> {
let daemon = app_state.get_daemon_cli(repo_path).await;
let daemon = app_state.get_daemon_cli(repo_path).await?;
daemon.init_repo().await?;
Ok(())
@ -16,7 +23,7 @@ pub async fn init_repository(app_state: AppAccess<'_>, repo_path: String) -> Plu
#[tauri::command]
pub async fn start_daemon(app_state: AppAccess<'_>, repo_path: String) -> PluginResult<()> {
let mut daemon = app_state.get_daemon_cli(repo_path).await;
let mut daemon = app_state.get_daemon_cli(repo_path).await?;
daemon.start_daemon()?;
app_state.add_started_daemon(daemon).await;

@ -58,7 +58,8 @@ impl<R: Runtime> MediarepoPlugin<R> {
save_file_locally,
delete_thumbnails,
read_file,
delete_repository
delete_repository,
has_executable
]),
}
}

@ -1,3 +1,4 @@
use crate::daemon_management::find_daemon_executable;
use crate::tauri_plugin::error::PluginResult;
use directories::ProjectDirs;
use serde::{Deserialize, Serialize};
@ -19,14 +20,14 @@ pub struct Repository {
#[derive(DeserializePiecewiseDefault, Debug, Serialize)]
pub struct Settings {
pub daemon_path: String,
pub daemon_path: Option<String>,
pub repositories: HashMap<String, Repository>,
}
impl Default for Settings {
fn default() -> Self {
Self {
daemon_path: String::from("mediarepo-daemon"),
daemon_path: find_daemon_executable().map(|e| e.to_string_lossy().to_string()),
repositories: HashMap::new(),
}
}

@ -179,11 +179,15 @@ impl AppState {
}
/// Returns the daemon cli client
pub async fn get_daemon_cli(&self, repo_path: String) -> DaemonCli {
pub async fn get_daemon_cli(&self, repo_path: String) -> PluginResult<DaemonCli> {
let settings = self.settings.read().await;
let path = settings.daemon_path.clone();
let path = settings
.daemon_path
.clone()
.ok_or_else(|| PluginError::from("Missing daemon executable"))?;
let cli = DaemonCli::new(path, repo_path);
DaemonCli::new(path, repo_path)
Ok(cli)
}
/// Adds a started daemon to the running daemons

Loading…
Cancel
Save