-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make a few retries if Gnome Wayland is certain
- Loading branch information
Showing
4 changed files
with
62 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// The extension may not be loaded and available right away in Gnome, this mod will retry a few times. | ||
pub trait GnomeWatcher { | ||
async fn load() -> anyhow::Result<Self> | ||
where | ||
Self: Sized; | ||
} | ||
|
||
fn is_gnome() -> bool { | ||
if let Ok(de) = std::env::var("XDG_CURRENT_DESKTOP") { | ||
de.to_lowercase().contains("gnome") | ||
} else { | ||
false | ||
} | ||
} | ||
|
||
fn is_wayland() -> bool { | ||
std::env::var("WAYLAND_DISPLAY").is_ok() | ||
&& !std::env::var("XDG_SESSION_TYPE") | ||
.unwrap_or("".into()) | ||
.to_lowercase() | ||
.contains("x11") | ||
} | ||
|
||
pub async fn load_watcher<T: GnomeWatcher>() -> anyhow::Result<T> { | ||
if is_gnome() && is_wayland() { | ||
let mut watcher = Err(anyhow::anyhow!("")); | ||
for _ in 0..3 { | ||
watcher = T::load().await; | ||
if watcher.is_err() { | ||
tokio::time::sleep(tokio::time::Duration::from_secs(3)).await; | ||
} | ||
} | ||
|
||
watcher | ||
} else { | ||
T::load().await | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters