Skip to content

Commit 92b4fee

Browse files
authored
Disable "start meeting" tray item when session is already started (#673)
1 parent c689f09 commit 92b4fee

File tree

5 files changed

+47
-26
lines changed

5 files changed

+47
-26
lines changed

Cargo.lock

Lines changed: 1 addition & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/listener/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ hypr-listener-interface = { workspace = true }
2323
tauri-plugin-auth = { workspace = true }
2424
tauri-plugin-connector = { workspace = true }
2525
tauri-plugin-db = { workspace = true }
26+
tauri-plugin-tray = { workspace = true }
2627

2728
hypr-audio = { workspace = true }
2829
hypr-audio-utils = { workspace = true }

plugins/listener/src/fsm.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,11 @@ impl Session {
464464
}
465465
}
466466

467-
#[state(entry_action = "enter_inactive", superstate = "common")]
467+
#[state(
468+
superstate = "common",
469+
entry_action = "enter_inactive",
470+
exit_action = "exit_inactive"
471+
)]
468472
async fn inactive(&mut self, event: &StateEvent) -> Response<State> {
469473
match event {
470474
StateEvent::Start(id) => match self.setup_resources(id).await {
@@ -484,13 +488,24 @@ impl Session {
484488

485489
#[action]
486490
async fn enter_inactive(&mut self) {
491+
{
492+
use tauri_plugin_tray::TrayPluginExt;
493+
let _ = self.app.set_start_disabled(false);
494+
}
495+
487496
self.teardown_resources().await;
488497

489498
Session::broadcast(&self.channels, SessionEvent::Stopped)
490499
.await
491500
.unwrap();
492501
}
493502

503+
#[action]
504+
async fn exit_inactive(&mut self) {
505+
use tauri_plugin_tray::TrayPluginExt;
506+
let _ = self.app.set_start_disabled(true);
507+
}
508+
494509
fn on_transition(&mut self, source: &State, target: &State) {
495510
#[cfg(debug_assertions)]
496511
tracing::info!("transitioned from `{:?}` to `{:?}`", source, target);

plugins/tray/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,3 @@ tauri-plugin-windows = { workspace = true }
2020
specta = { workspace = true }
2121
strum = { workspace = true, features = ["derive"] }
2222
tauri-specta = { workspace = true, features = ["derive", "typescript"] }
23-
24-
webbrowser = "1.0.4"

plugins/tray/src/ext.rs

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use tauri::{
55
AppHandle, Result,
66
};
77

8+
const TRAY_ID: &str = "hypr-tray";
9+
810
pub enum TrayItem {
911
Open,
1012
Start,
@@ -36,6 +38,7 @@ impl From<MenuId> for TrayItem {
3638

3739
pub trait TrayPluginExt<R: tauri::Runtime> {
3840
fn create_tray(&self) -> Result<()>;
41+
fn set_start_disabled(&self, disabled: bool) -> Result<()>;
3942
}
4043

4144
impl<T: tauri::Manager<tauri::Wry>> TrayPluginExt<tauri::Wry> for T {
@@ -46,13 +49,13 @@ impl<T: tauri::Manager<tauri::Wry>> TrayPluginExt<tauri::Wry> for T {
4649
app,
4750
&[
4851
&open_menu(app)?,
49-
&start_menu(app)?,
52+
&start_menu(app, false)?,
5053
&PredefinedMenuItem::separator(app)?,
5154
&quit_menu(app)?,
5255
],
5356
)?;
5457

55-
TrayIconBuilder::with_id("hypr-tray")
58+
TrayIconBuilder::with_id(TRAY_ID)
5659
.icon(Image::from_bytes(include_bytes!(
5760
"../icons/tray_default.png"
5861
))?)
@@ -68,7 +71,8 @@ impl<T: tauri::Manager<tauri::Wry>> TrayPluginExt<tauri::Wry> for T {
6871
TrayItem::Start => {
6972
use tauri_plugin_windows::{HyprWindow, WindowsPluginExt};
7073
if let Ok(_) = app.window_show(HyprWindow::Main) {
71-
let _ = app.window_navigate(HyprWindow::Main, "/app/new?record=true");
74+
let _ =
75+
app.window_emit_navigate(HyprWindow::Main, "/app/new?record=true");
7276
}
7377
}
7478
TrayItem::Quit => {
@@ -80,18 +84,38 @@ impl<T: tauri::Manager<tauri::Wry>> TrayPluginExt<tauri::Wry> for T {
8084

8185
Ok(())
8286
}
87+
88+
fn set_start_disabled(&self, disabled: bool) -> Result<()> {
89+
let app = self.app_handle();
90+
91+
if let Some(tray) = app.tray_by_id(TRAY_ID) {
92+
let menu = Menu::with_items(
93+
app,
94+
&[
95+
&open_menu(app)?,
96+
&start_menu(app, disabled)?,
97+
&PredefinedMenuItem::separator(app)?,
98+
&quit_menu(app)?,
99+
],
100+
)?;
101+
102+
tray.set_menu(Some(menu))?;
103+
}
104+
105+
Ok(())
106+
}
83107
}
84108

85109
fn open_menu<R: tauri::Runtime>(app: &AppHandle<R>) -> Result<MenuItem<R>> {
86110
MenuItem::with_id(app, TrayItem::Open, "Open Hyprnote", true, None::<&str>)
87111
}
88112

89-
fn start_menu<R: tauri::Runtime>(app: &AppHandle<R>) -> Result<MenuItem<R>> {
113+
fn start_menu<R: tauri::Runtime>(app: &AppHandle<R>, disabled: bool) -> Result<MenuItem<R>> {
90114
MenuItem::with_id(
91115
app,
92116
TrayItem::Start,
93117
"Start a new meeting",
94-
true,
118+
!disabled,
95119
None::<&str>,
96120
)
97121
}

0 commit comments

Comments
 (0)