Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix[mobile]: blank screen of death on app re-open (#1245)
Peter Chinman7fe493d5f1b8
diff --git a/js/app/packages/tauri/src/TauriProvider.tsx b/js/app/packages/tauri/src/TauriProvider.tsxindex 950f1f5774..047b0116de 100644--- a/js/app/packages/tauri/src/TauriProvider.tsx+++ b/js/app/packages/tauri/src/TauriProvider.tsx@@ -14,6 +14,7 @@ import {useContext,} from 'solid-js';import { getInsets, type Insets } from 'tauri-plugin-safe-area-insets';+import { listenForHeartbeat } from './heartbeat';import { useTauriNavigationEffect } from './navigation';import { MaybePushNotificationRegistration } from './PushNotification';@@ -40,6 +41,8 @@ function TauriProvider(props: { children: JSX.Element }) {};onMount(() => {+ listenForHeartbeat();+if (value.os === 'android') {getInsets().then((insets) => {setInsets(insets);diff --git a/js/app/packages/tauri/src/heartbeat.ts b/js/app/packages/tauri/src/heartbeat.tsnew file mode 100644index 0000000000..277ce3ccf3--- /dev/null+++ b/js/app/packages/tauri/src/heartbeat.ts@@ -0,0 +1,14 @@+import { invoke } from '@tauri-apps/api/core';+import { listen } from '@tauri-apps/api/event';++/**+ * Registers a permanent listener for heartbeat pings from the native side.+ *+ * This listener is intentionally never cleaned up — it must remain active+ * for the entire app lifecycle to respond to resume pings.+ */+export function listenForHeartbeat() {+ listen('heartbeat_ping', () => {+ invoke('heartbeat_response');+ });+}diff --git a/js/app/tauri/Cargo.lock b/js/app/tauri/Cargo.lockindex a35302a8c5..5c296bee64 100644--- a/js/app/tauri/Cargo.lock+++ b/js/app/tauri/Cargo.lock@@ -90,6 +90,7 @@ dependencies = ["serde_qs","tauri","tauri-build",+ "tauri-plugin-app-events","tauri-plugin-deep-link","tauri-plugin-haptics","tauri-plugin-http",@@ -4526,6 +4527,18 @@ dependencies = ["walkdir",]+[[package]]+name = "tauri-plugin-app-events"+version = "0.2.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "4e625f35abcfc422c7c4af8b348d2069cdf387a39c12429fdce570137d02f069"+dependencies = [+ "serde",+ "tauri",+ "tauri-plugin",+ "thiserror 1.0.69",+]+[[package]]name = "tauri-plugin-deep-link"version = "2.4.5"diff --git a/js/app/tauri/src-tauri/Cargo.toml b/js/app/tauri/src-tauri/Cargo.tomlindex 2f29b1046b..0f4c29543f 100644--- a/js/app/tauri/src-tauri/Cargo.toml+++ b/js/app/tauri/src-tauri/Cargo.toml@@ -59,4 +59,5 @@ tauri-plugin-virtual-keyboard = { git = "https://github.com/voxelbee/tauri-plugitauri-plugin-single-instance = { version = "2", features = ["deep-link"] }[target.'cfg(any(target_os = "android", target_os = "ios"))'.dependencies]+tauri-plugin-app-events = "0.2"tauri-plugin-haptics = "2"diff --git a/js/app/tauri/src-tauri/capabilities/mobile.json b/js/app/tauri/src-tauri/capabilities/mobile.jsonindex 91e227a8f4..c7bbb912f6 100644--- a/js/app/tauri/src-tauri/capabilities/mobile.json+++ b/js/app/tauri/src-tauri/capabilities/mobile.json@@ -12,6 +12,7 @@"haptics:allow-notification-feedback","haptics:allow-selection-feedback","haptics:allow-vibrate",- "log:default"+ "log:default",+ "app-events:default"]}\ No newline at end of filediff --git a/js/app/tauri/src-tauri/src/lib.rs b/js/app/tauri/src-tauri/src/lib.rsindex ad256eea4d..b9544aca84 100644--- a/js/app/tauri/src-tauri/src/lib.rs+++ b/js/app/tauri/src-tauri/src/lib.rs@@ -5,6 +5,7 @@ use reqwest::cookie::CookieStore;use reqwest::header::COOKIE;use rootcause::{Report, report};use serde::Serialize;+use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};use tauri::http::{HeaderMap, HeaderValue};use tauri::{AppHandle, Emitter};use tauri::{Manager, Runtime};@@ -13,6 +14,17 @@ use tracing_subscriber::layer::SubscriberExt;use tracing_subscriber::util::SubscriberInitExt;use url::Url;+struct HeartbeatState {+ alive: AtomicBool,+ /// Incremented on each resume event so stale check threads are ignored+ generation: AtomicU64,+}++#[tauri::command]+fn heartbeat_response(state: tauri::State<'_, HeartbeatState>) {+ state.alive.store(true, Ordering::SeqCst);+}+/// This module provides debuging utilities and should not be compiled in prodiction builds#[cfg(debug_assertions)] // do not remove thismod debug;@@ -116,6 +128,11 @@ pub fn run() {}builder+ .manage(HeartbeatState {+ alive: AtomicBool::new(true),+ generation: AtomicU64::new(0),+ })+ .invoke_handler(tauri::generate_handler![heartbeat_response]).setup(|app| {#[cfg(any(target_os = "linux", all(windows, debug_assertions)))]{@@ -128,6 +145,53 @@ pub fn run() {app.chain(attach_deep_link_handler);+ #[cfg(mobile)]+ {+ use tauri::ipc::Channel;+ use tauri_plugin_app_events::AppEventsExt;++ let app_handle = app.handle().clone();+ app_handle.plugin(tauri_plugin_app_events::init())?;++ let handle = app_handle.clone();+ app_handle+ .app_events()+ .set_resume_handler(Channel::new(move |_| {+ tracing::info!("app resumed, sending heartbeat ping");++ let state = handle.state::<HeartbeatState>();+ let current_gen = state.generation.fetch_add(1, Ordering::SeqCst) + 1;+ state.alive.store(false, Ordering::SeqCst);++ let _ = handle.emit("heartbeat_ping", ());++ let handle = handle.clone();+ tokio::spawn(async move {+ tokio::time::sleep(std::time::Duration::from_secs(1)).await;+ let state = handle.state::<HeartbeatState>();++ // A newer resume has superseded this one; bail out+ if state.generation.load(Ordering::SeqCst) != current_gen {+ tracing::debug!("heartbeat: stale generation {current_gen}, skipping");+ return;+ }++ if !state.alive.load(Ordering::SeqCst) {+ tracing::warn!(+ "heartbeat: no response from JS — content process likely dead, reloading webview"+ );+ if let Some(webview) = handle.webview_windows().values().next() {+ let _ = webview.reload();+ }+ } else {+ tracing::info!("heartbeat: JS responded, content process alive");+ }+ });++ Ok(())+ }))?;+ }+Ok(())}).run(tauri::generate_context!())