11use std:: collections:: HashMap ;
22use std:: fs:: File ;
33use std:: sync:: Arc ;
4+ use std:: time:: Duration ;
5+ use std:: vec;
46
57use anyhow:: Context ;
68use anyhow:: anyhow;
@@ -50,6 +52,7 @@ use serde::Serialize;
5052use tokio:: sync:: Mutex ;
5153
5254use crate :: model:: IntermediateUiEvent ;
55+ use crate :: plugins:: Settings ;
5356use crate :: plugins:: binary_data_gatherer:: BinaryDataGatherer ;
5457use crate :: plugins:: clipboard:: Clipboard ;
5558use crate :: plugins:: data_db_repository:: DataDbRepository ;
@@ -78,6 +81,7 @@ pub struct PluginRuntimeData {
7881 pub db_repository : DataDbRepository ,
7982 pub search_index : SearchIndex ,
8083 pub icon_cache : IconCache ,
84+ pub settings : Settings ,
8185 pub frontend_api : FrontendApiProxy ,
8286 pub dirs : Dirs ,
8387 pub clipboard : Clipboard ,
@@ -159,6 +163,7 @@ pub async fn start_plugin_runtime(data: PluginRuntimeData, run_status_guard: Run
159163 data. search_index ,
160164 data. clipboard ,
161165 data. frontend_api ,
166+ data. settings ,
162167 data. uuid . clone ( ) ,
163168 data. id . clone ( ) ,
164169 data. name ,
@@ -601,6 +606,7 @@ pub struct BackendForPluginRuntimeApiImpl {
601606 search_index : SearchIndex ,
602607 clipboard : Clipboard ,
603608 frontend_api : FrontendApiProxy ,
609+ settings : Settings ,
604610 #[ allow( unused) ]
605611 plugin_uuid : String ,
606612 plugin_id : PluginId ,
@@ -614,6 +620,7 @@ impl BackendForPluginRuntimeApiImpl {
614620 search_index : SearchIndex ,
615621 clipboard : Clipboard ,
616622 frontend_api : FrontendApiProxy ,
623+ settings : Settings ,
617624 plugin_uuid : String ,
618625 plugin_id : PluginId ,
619626 plugin_name : String ,
@@ -624,6 +631,7 @@ impl BackendForPluginRuntimeApiImpl {
624631 search_index,
625632 clipboard,
626633 frontend_api,
634+ settings,
627635 plugin_uuid,
628636 plugin_id,
629637 plugin_name,
@@ -961,7 +969,16 @@ impl BackendForPluginRuntimeApi for BackendForPluginRuntimeApiImpl {
961969 }
962970
963971 async fn ui_show_hud ( & self , display : String ) -> RequestResult < ( ) > {
964- self . frontend_api . show_hud ( display) . await ?;
972+ if cfg ! ( target_os = "linux" ) {
973+ if self . settings . config ( ) . linux_native_hud {
974+ #[ cfg( target_os = "linux" ) ]
975+ show_linux_native_hud ( display) . await ?;
976+ } else {
977+ self . frontend_api . show_hud ( display) . await ?;
978+ }
979+ } else {
980+ self . frontend_api . show_hud ( display) . await ?;
981+ }
965982
966983 Ok ( ( ) )
967984 }
@@ -1201,3 +1218,27 @@ fn any_preferences_missing_value(
12011218
12021219 false
12031220}
1221+
1222+ #[ cfg( target_os = "linux" ) ]
1223+ async fn show_linux_native_hud ( display : String ) -> anyhow:: Result < ( ) > {
1224+ use ashpd:: desktop:: notification:: DisplayHint ;
1225+ use ashpd:: desktop:: notification:: Notification ;
1226+ use ashpd:: desktop:: notification:: NotificationProxy ;
1227+ use ashpd:: desktop:: notification:: Priority ;
1228+
1229+ let proxy = NotificationProxy :: new ( ) . await ?;
1230+
1231+ let notification_id = "sh.gauntlet.Hud" ;
1232+ let notification = Notification :: new ( & display)
1233+ . priority ( Priority :: Urgent )
1234+ . display_hint ( vec ! [ DisplayHint :: Transient , DisplayHint :: ShowAsNew ] ) ;
1235+
1236+ proxy. add_notification ( notification_id, notification) . await ?;
1237+
1238+ tokio:: spawn ( async move {
1239+ tokio:: time:: sleep ( Duration :: from_secs ( 2 ) ) . await ;
1240+ let _ = proxy. remove_notification ( notification_id) . await ;
1241+ } ) ;
1242+
1243+ Ok ( ( ) )
1244+ }
0 commit comments