Skip to content

Commit

Permalink
fix: attempt to fix loading ends up with a blank/white screen (#466)
Browse files Browse the repository at this point in the history
  • Loading branch information
hrzlgnm authored Oct 29, 2024
1 parent 6b48b65 commit dddf8bc
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 87 deletions.
1 change: 0 additions & 1 deletion Trunk.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ target = "./index.html"
ignore = ["./src-tauri"]

[serve]
addresses = ["127.0.0.1"]
port = 1420
open = false
22 changes: 17 additions & 5 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,21 +272,30 @@ fn browse(service_type: String, window: Window, state: State<ManagedState>) {
}
}

const METRIC_SEND_INTERVAL: Duration = Duration::from_secs(3);
const METRIC_CHECK_INTERVAL: Duration = Duration::from_secs(1);

#[tauri::command]
fn send_metrics(window: Window, state: State<ManagedState>) {
if let Ok(mdns) = state.daemon.lock() {
let mdns_for_thread = mdns.clone();
let mut old_metrics = HashMap::new();
std::thread::spawn(move || loop {
std::thread::sleep(METRIC_CHECK_INTERVAL);
if let Ok(metrics_receiver) = mdns_for_thread.get_metrics() {
if let Ok(metrics) = metrics_receiver.recv() {
window
.emit("metrics", &MetricsEvent { metrics })
.expect("To emit");
if old_metrics != metrics {
window
.emit(
"metrics",
&MetricsEvent {
metrics: metrics.clone(),
},
)
.expect("To emit");
old_metrics = metrics;
}
}
}
std::thread::sleep(METRIC_SEND_INTERVAL);
});
}
}
Expand Down Expand Up @@ -533,9 +542,12 @@ pub fn run() {
let splashscreen_window = app.get_webview_window("splashscreen").unwrap();
let main_window = app.get_webview_window("main").unwrap();
tauri::async_runtime::spawn(async move {
#[cfg(not(debug_assertions))]
tokio::time::sleep(Duration::from_millis(2000)).await;
splashscreen_window.close().unwrap();
main_window.show().unwrap();
#[cfg(debug_assertions)]
main_window.open_devtools();
});
Ok(())
})
Expand Down
Loading

0 comments on commit dddf8bc

Please sign in to comment.