Unread counts, a window margin, blurred dialogs, softer group names
Each rise in an app's unread count while you are elsewhere adds to a tally beside its name, and a dot on its icon in the rail. Looking at the app is the only thing that clears it. The window has no frame of its own, so the shell now keeps a 6px margin in a normal window - the only part of it that is not a web page, and so the only place left to grab. Full screen gives the room back. Dialogs get the app blurred behind them. An app's webview paints above the shell, so it has to be moved aside before a dialog can be seen at all, and once moved there is nothing left to blur - a still taken on the way out is the only way to keep the background there. It runs on a blocking worker: its completion handler is on the main thread, and waiting there deadlocks until the timeout and returns nothing. Settings is much larger, the cog moved to the foot of the nav, group names read as names rather than shouted headings, and "Refresh icons" bumps a version every favicon URL carries, for the ones that cache wrong.
This commit is contained in:
@@ -24,6 +24,10 @@ pub struct AppState {
|
||||
pub diag: Mutex<std::collections::HashMap<String, String>>,
|
||||
/// The last notification a page raised, and what macOS did with it.
|
||||
pub last_notification: Mutex<String>,
|
||||
/// How much has arrived in each app since you last looked at it.
|
||||
pub unread: Mutex<std::collections::HashMap<String, u32>>,
|
||||
/// Size of the last dialog backdrop still, or why there wasn't one.
|
||||
pub last_snapshot: Mutex<String>,
|
||||
}
|
||||
|
||||
impl AppState {
|
||||
@@ -67,6 +71,8 @@ pub fn build_state(handle: &AppHandle) -> Result<AppState, String> {
|
||||
booted: Mutex::new(false),
|
||||
diag: Mutex::new(std::collections::HashMap::new()),
|
||||
last_notification: Mutex::new(String::new()),
|
||||
unread: Mutex::new(std::collections::HashMap::new()),
|
||||
last_snapshot: Mutex::new(String::new()),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -155,9 +161,67 @@ pub fn set_active(app_id: String, app: AppHandle, state: State<'_, AppState>) {
|
||||
let stage = *state.stage.lock().unwrap();
|
||||
*state.active.lock().unwrap() = Some(app_id.clone());
|
||||
webviews::show_only(&app, Some(&app_id), &cfg, stage);
|
||||
|
||||
// Looking at an app is what clears its count. Nothing else does.
|
||||
state.unread.lock().unwrap().remove(&app_id);
|
||||
let _ = app.emit("unread-changed", unread_list(&state));
|
||||
}
|
||||
|
||||
/// Every app's count, in the shape the nav wants.
|
||||
pub fn unread_list(state: &AppState) -> Vec<(String, u32)> {
|
||||
state
|
||||
.unread
|
||||
.lock()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.map(|(k, v)| (k.clone(), *v))
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn unread_counts(state: State<'_, AppState>) -> Vec<(String, u32)> {
|
||||
unread_list(&state)
|
||||
}
|
||||
|
||||
/// Bumps the version every favicon URL carries, so a wrong one is refetched.
|
||||
#[tauri::command]
|
||||
pub fn refresh_favicons(state: State<'_, AppState>) -> Result<Config, String> {
|
||||
{
|
||||
let mut cfg = state.config.lock().unwrap();
|
||||
cfg.settings.favicon_version = cfg.settings.favicon_version.wrapping_add(1);
|
||||
}
|
||||
state.persist()?;
|
||||
Ok(state.cfg())
|
||||
}
|
||||
|
||||
/// Hides every app, so a dialog is not painted over by a native view.
|
||||
/// A still of the app on screen, taken before a dialog covers it.
|
||||
///
|
||||
/// Async, and the wait happens on a blocking worker: the snapshot's completion
|
||||
/// handler runs on the main thread, so waiting for it *on* the main thread
|
||||
/// deadlocks until the timeout and returns nothing every time.
|
||||
#[tauri::command]
|
||||
pub async fn stage_snapshot(app: AppHandle) -> Option<String> {
|
||||
let id = {
|
||||
let state = app.state::<AppState>();
|
||||
let active = state.active.lock().unwrap();
|
||||
active.clone()?
|
||||
};
|
||||
let handle = app.clone();
|
||||
let shot = tauri::async_runtime::spawn_blocking(move || webviews::snapshot(&app, &id))
|
||||
.await
|
||||
.ok()
|
||||
.flatten();
|
||||
|
||||
// Recorded so the diagnostic can say whether the still was taken at all,
|
||||
// rather than leaving a flat backdrop to be interpreted by eye.
|
||||
*handle.state::<AppState>().last_snapshot.lock().unwrap() = match &shot {
|
||||
Some(d) => format!("{} bytes", d.len()),
|
||||
None => "none".into(),
|
||||
};
|
||||
shot
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn hide_stage(app: AppHandle, state: State<'_, AppState>) {
|
||||
let stage = *state.stage.lock().unwrap();
|
||||
@@ -443,7 +507,9 @@ pub fn notification_status(app: AppHandle) -> String {
|
||||
let app_state = app.state::<AppState>();
|
||||
let last = app_state.last_notification.lock().unwrap().clone();
|
||||
let from_page = if last.is_empty() { "none yet".into() } else { last };
|
||||
format!("permission: {state} · direct: {raised} · from page: {from_page}")
|
||||
let shot = app_state.last_snapshot.lock().unwrap().clone();
|
||||
let shot = if shot.is_empty() { "not taken".into() } else { shot };
|
||||
format!("permission: {state} · direct: {raised} · from page: {from_page} · backdrop: {shot}")
|
||||
}
|
||||
|
||||
/// Asks macOS for notification permission, and claims this app's identity.
|
||||
|
||||
Reference in New Issue
Block a user