feat: integrate app initialization into Tauri setup
Startup sequence now: 1. Creates data directories (~/.local/share/mc/) 2. Cleans up orphaned tmp files from crashes 3. Verifies CLI dependencies (lore, br, bv) asynchronously 4. Emits startup-warnings event with missing CLI warnings 5. Emits cli-availability event with tool status 6. Emits startup-sync-ready when CLIs available This enables the frontend to: - Display warnings for missing tools - Know which features are available - Trigger reconciliation when ready bd-3jh Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -165,12 +165,19 @@ pub fn run() {
|
|||||||
.build(),
|
.build(),
|
||||||
)
|
)
|
||||||
.setup(|app| {
|
.setup(|app| {
|
||||||
// Clean up orphaned tmp files from previous crashes
|
|
||||||
{
|
|
||||||
use data::beads::RealBeadsCli;
|
use data::beads::RealBeadsCli;
|
||||||
use data::bridge::Bridge;
|
use data::bridge::Bridge;
|
||||||
use data::lore::RealLoreCli;
|
use data::lore::RealLoreCli;
|
||||||
|
|
||||||
|
// 1. Ensure data directories exist
|
||||||
|
let config = app::AppConfig::default();
|
||||||
|
if let Err(e) = app::ensure_data_dir(&config) {
|
||||||
|
tracing::error!("Failed to create data directory: {}", e);
|
||||||
|
// Continue anyway - commands will fail gracefully
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Clean up orphaned tmp files from previous crashes
|
||||||
|
{
|
||||||
let bridge: Bridge<RealLoreCli, RealBeadsCli> =
|
let bridge: Bridge<RealLoreCli, RealBeadsCli> =
|
||||||
Bridge::new(RealLoreCli, RealBeadsCli);
|
Bridge::new(RealLoreCli, RealBeadsCli);
|
||||||
if let Err(e) = bridge.cleanup_tmp_files() {
|
if let Err(e) = bridge.cleanup_tmp_files() {
|
||||||
@@ -178,6 +185,49 @@ pub fn run() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 3. Verify CLI dependencies (async, spawned to not block startup)
|
||||||
|
let app_handle = app.handle().clone();
|
||||||
|
tauri::async_runtime::spawn(async move {
|
||||||
|
let (cli_available, warnings) = app::verify_cli_dependencies().await;
|
||||||
|
|
||||||
|
// Log warnings
|
||||||
|
for warning in &warnings {
|
||||||
|
match warning {
|
||||||
|
app::StartupWarning::LoreMissing => {
|
||||||
|
tracing::warn!("lore CLI not found - GitLab sync will be unavailable");
|
||||||
|
}
|
||||||
|
app::StartupWarning::BrMissing => {
|
||||||
|
tracing::warn!("br CLI not found - beads integration will be unavailable");
|
||||||
|
}
|
||||||
|
app::StartupWarning::BvMissing => {
|
||||||
|
tracing::warn!("bv CLI not found - triage features will be unavailable");
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Emit startup warnings to frontend
|
||||||
|
if !warnings.is_empty() {
|
||||||
|
if let Err(e) = app_handle.emit("startup-warnings", &warnings) {
|
||||||
|
tracing::error!("Failed to emit startup warnings: {}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Emit CLI availability to frontend
|
||||||
|
if let Err(e) = app_handle.emit("cli-availability", &cli_available) {
|
||||||
|
tracing::error!("Failed to emit CLI availability: {}", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. Trigger startup reconciliation if CLIs are available
|
||||||
|
if cli_available.lore && cli_available.br {
|
||||||
|
tracing::info!("Triggering startup reconciliation");
|
||||||
|
// The frontend will call reconcile() command when ready
|
||||||
|
if let Err(e) = app_handle.emit("startup-sync-ready", ()) {
|
||||||
|
tracing::error!("Failed to emit startup-sync-ready: {}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Set up system tray
|
// Set up system tray
|
||||||
if let Err(e) = setup_tray(app) {
|
if let Err(e) = setup_tray(app) {
|
||||||
tracing::error!("Failed to setup system tray: {}", e);
|
tracing::error!("Failed to setup system tray: {}", e);
|
||||||
|
|||||||
Reference in New Issue
Block a user