cosmic-applets/applets/cosmic-applet-workspaces/src/utils.rs

38 lines
779 B
Rust
Raw Normal View History

2022-06-08 10:47:16 -04:00
// SPDX-License-Identifier: MPL-2.0-only
use std::path::PathBuf;
use gtk4::glib;
use std::future::Future;
2022-06-16 12:23:25 -04:00
pub type Activate = String;
2022-06-08 10:47:16 -04:00
2022-06-20 14:42:12 -04:00
#[derive(Debug, Clone)]
pub enum WorkspaceEvent {
Activate(String),
Scroll(f64),
}
2022-06-08 10:47:16 -04:00
pub fn data_path() -> PathBuf {
let mut path = glib::user_data_dir();
path.push(crate::ID);
std::fs::create_dir_all(&path).expect("Could not create directory.");
path.push("data.json");
path
}
pub fn thread_context() -> glib::MainContext {
glib::MainContext::thread_default().unwrap_or_else(|| {
let ctx = glib::MainContext::new();
ctx
})
}
pub fn block_on<F>(future: F) -> F::Output
where
F: Future,
{
let ctx = thread_context();
ctx.with_thread_default(|| ctx.block_on(future)).unwrap()
}