2021-12-29 17:31:01 -05:00
|
|
|
use std::path::PathBuf;
|
|
|
|
|
|
2022-01-02 01:46:44 -05:00
|
|
|
use gtk4::glib;
|
|
|
|
|
use std::future::Future;
|
2021-12-29 17:31:01 -05:00
|
|
|
|
2021-12-27 17:59:49 -05:00
|
|
|
use crate::DockObject;
|
2021-12-22 12:32:46 -05:00
|
|
|
use crate::Item;
|
|
|
|
|
|
2022-01-19 10:19:56 -05:00
|
|
|
#[derive(Clone, Debug, Default, glib::Boxed)]
|
|
|
|
|
#[boxed_type(name = "BoxedWindowList")]
|
2021-12-22 12:32:46 -05:00
|
|
|
pub struct BoxedWindowList(pub Vec<Item>);
|
2021-12-29 17:31:01 -05:00
|
|
|
|
2022-01-19 10:19:56 -05:00
|
|
|
#[derive(Clone, Debug, Default, glib::Boxed)]
|
|
|
|
|
#[boxed_type(name = "BoxedDockObject")]
|
2021-12-27 17:59:49 -05:00
|
|
|
pub struct BoxedDockObject(pub Option<DockObject>);
|
|
|
|
|
|
|
|
|
|
pub fn data_path() -> PathBuf {
|
|
|
|
|
let mut path = glib::user_data_dir();
|
2022-01-11 00:05:57 -05:00
|
|
|
path.push(crate::ID);
|
2021-12-27 17:59:49 -05:00
|
|
|
std::fs::create_dir_all(&path).expect("Could not create directory.");
|
|
|
|
|
path.push("data.json");
|
|
|
|
|
path
|
|
|
|
|
}
|
2022-01-02 01:46:44 -05:00
|
|
|
|
2022-01-07 12:27:16 -05:00
|
|
|
pub fn thread_context() -> glib::MainContext {
|
2022-01-02 01:46:44 -05:00
|
|
|
glib::MainContext::thread_default().unwrap_or_else(|| {
|
|
|
|
|
let ctx = glib::MainContext::new();
|
|
|
|
|
ctx
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-07 12:27:16 -05:00
|
|
|
pub fn block_on<F>(future: F) -> F::Output
|
2022-01-02 01:46:44 -05:00
|
|
|
where
|
|
|
|
|
F: Future,
|
|
|
|
|
{
|
2022-01-19 10:19:56 -05:00
|
|
|
let ctx = thread_context();
|
|
|
|
|
ctx.with_thread_default(|| ctx.block_on(future)).unwrap()
|
2022-01-02 01:46:44 -05:00
|
|
|
}
|