mirror of
https://github.com/tinyhumansai/openhuman.git
synced 2026-07-29 22:23:01 +00:00
refactor(tauri): reduce desktop host to sidecar lifecycle + deep-link (#84)
* feat(onboarding): introduce DEV_FORCE_ONBOARDING flag to control onboarding flow - Added DEV_FORCE_ONBOARDING configuration to bypass onboarding checks during development. - Updated onboarding logic in AppRoutes to respect the new flag, ensuring onboarding is always shown when enabled. - Introduced new utility functions for managing onboarding state based on the flag. - Updated Cargo.lock and Cargo.toml to reflect dependency changes and version updates. - Removed deprecated openhuman command module and refactored related functionalities into daemon_host module for better organization. * feat(daemon): refactor daemon health monitoring and window management - Updated DaemonHealthService to use polling via `openhuman.health_snapshot` instead of event listening for health updates. - Introduced a new focusMainWindow function to centralize window focus logic across deep link handling and Tauri commands. - Replaced `invoke` calls with direct window management methods for showing, hiding, and toggling the main window. - Removed deprecated core_rpc module and related commands for improved organization and clarity. - Updated Cargo.toml and Cargo.lock to reflect dependency changes. * refactor(daemonHealthService): streamline imports and simplify tool object structure - Moved the import of `callCoreRpc` to a more appropriate location in DaemonHealthService. - Simplified the structure of the tools object in the aiGetConfig function for better readability. - Ensured consistency in Tauri command invocations by removing unnecessary line breaks.
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
//! JSON-RPC / CLI controller surface for platform service install/lifecycle.
|
||||
|
||||
use crate::openhuman::config::Config;
|
||||
use crate::openhuman::service::{self, ServiceStatus};
|
||||
use crate::openhuman::service::daemon_host::DaemonHostConfig;
|
||||
use crate::openhuman::service::{self, daemon_host, ServiceStatus};
|
||||
use crate::rpc::RpcOutcome;
|
||||
|
||||
pub async fn service_install(config: &Config) -> Result<RpcOutcome<ServiceStatus>, String> {
|
||||
@@ -31,3 +32,25 @@ pub async fn service_uninstall(config: &Config) -> Result<RpcOutcome<ServiceStat
|
||||
"service uninstall completed",
|
||||
))
|
||||
}
|
||||
|
||||
pub async fn daemon_host_get(config: &Config) -> Result<RpcOutcome<DaemonHostConfig>, String> {
|
||||
let config_dir = config
|
||||
.config_path
|
||||
.parent()
|
||||
.ok_or_else(|| "failed to resolve config directory".to_string())?;
|
||||
let current = daemon_host::load_for_config_dir(config_dir).await;
|
||||
Ok(RpcOutcome::single_log(current, "daemon host config loaded"))
|
||||
}
|
||||
|
||||
pub async fn daemon_host_set(
|
||||
config: &Config,
|
||||
show_tray: bool,
|
||||
) -> Result<RpcOutcome<DaemonHostConfig>, String> {
|
||||
let config_dir = config
|
||||
.config_path
|
||||
.parent()
|
||||
.ok_or_else(|| "failed to resolve config directory".to_string())?;
|
||||
let next = DaemonHostConfig { show_tray };
|
||||
daemon_host::save_for_config_dir(config_dir, &next).await?;
|
||||
Ok(RpcOutcome::single_log(next, "daemon host config saved"))
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use serde::Deserialize;
|
||||
use serde_json::{Map, Value};
|
||||
|
||||
use crate::core::all::{ControllerFuture, RegisteredController};
|
||||
@@ -12,6 +13,8 @@ pub fn all_controller_schemas() -> Vec<ControllerSchema> {
|
||||
schemas("stop"),
|
||||
schemas("status"),
|
||||
schemas("uninstall"),
|
||||
schemas("daemon_host_get"),
|
||||
schemas("daemon_host_set"),
|
||||
]
|
||||
}
|
||||
|
||||
@@ -37,6 +40,14 @@ pub fn all_registered_controllers() -> Vec<RegisteredController> {
|
||||
schema: schemas("uninstall"),
|
||||
handler: handle_uninstall,
|
||||
},
|
||||
RegisteredController {
|
||||
schema: schemas("daemon_host_get"),
|
||||
handler: handle_daemon_host_get,
|
||||
},
|
||||
RegisteredController {
|
||||
schema: schemas("daemon_host_set"),
|
||||
handler: handle_daemon_host_set,
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
@@ -60,6 +71,35 @@ pub fn schemas(function: &str) -> ControllerSchema {
|
||||
required: true,
|
||||
}],
|
||||
},
|
||||
"daemon_host_get" => ControllerSchema {
|
||||
namespace: "service",
|
||||
function: "daemon_host_get",
|
||||
description: "Read daemon host UI preferences.",
|
||||
inputs: vec![],
|
||||
outputs: vec![FieldSchema {
|
||||
name: "status",
|
||||
ty: TypeSchema::Ref("DaemonHostConfig"),
|
||||
comment: "Daemon host preference payload.",
|
||||
required: true,
|
||||
}],
|
||||
},
|
||||
"daemon_host_set" => ControllerSchema {
|
||||
namespace: "service",
|
||||
function: "daemon_host_set",
|
||||
description: "Update daemon host UI preferences.",
|
||||
inputs: vec![FieldSchema {
|
||||
name: "show_tray",
|
||||
ty: TypeSchema::Bool,
|
||||
comment: "Show tray icon in daemon-host mode.",
|
||||
required: true,
|
||||
}],
|
||||
outputs: vec![FieldSchema {
|
||||
name: "status",
|
||||
ty: TypeSchema::Ref("DaemonHostConfig"),
|
||||
comment: "Updated daemon host preference payload.",
|
||||
required: true,
|
||||
}],
|
||||
},
|
||||
_ => ControllerSchema {
|
||||
namespace: "service",
|
||||
function: "unknown",
|
||||
@@ -110,6 +150,27 @@ fn handle_uninstall(_params: Map<String, Value>) -> ControllerFuture {
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct DaemonHostSetParams {
|
||||
show_tray: bool,
|
||||
}
|
||||
|
||||
fn handle_daemon_host_get(_params: Map<String, Value>) -> ControllerFuture {
|
||||
Box::pin(async move {
|
||||
let config = config_rpc::load_config_with_timeout().await?;
|
||||
to_json(crate::openhuman::service::rpc::daemon_host_get(&config).await?)
|
||||
})
|
||||
}
|
||||
|
||||
fn handle_daemon_host_set(params: Map<String, Value>) -> ControllerFuture {
|
||||
Box::pin(async move {
|
||||
let payload: DaemonHostSetParams =
|
||||
serde_json::from_value(Value::Object(params)).map_err(|e| e.to_string())?;
|
||||
let config = config_rpc::load_config_with_timeout().await?;
|
||||
to_json(crate::openhuman::service::rpc::daemon_host_set(&config, payload.show_tray).await?)
|
||||
})
|
||||
}
|
||||
|
||||
fn to_json<T: serde::Serialize>(outcome: RpcOutcome<T>) -> Result<Value, String> {
|
||||
outcome.into_cli_compatible_json()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user