make gsettings a thread local
This commit is contained in:
parent
d2d1cee3a6
commit
f8a6e09866
7 changed files with 35 additions and 28 deletions
|
@ -57,7 +57,7 @@ glib::wrapper! {
|
|||
impl Default for Application {
|
||||
fn default() -> Self {
|
||||
glib::Object::builder::<Self>()
|
||||
.property("application-id", crate::APP_ID)
|
||||
.property("application-id", audrey::APP_ID)
|
||||
.property("flags", gio::ApplicationFlags::default())
|
||||
.build()
|
||||
}
|
||||
|
|
10
src/lib.rs
10
src/lib.rs
|
@ -1,7 +1,17 @@
|
|||
pub const VERSION: &str = "0.1.0"; // AUDREY_VERSION
|
||||
pub const USER_AGENT: &str = "audrey/linux";
|
||||
pub const APP_ID: &str = "eu.callcc.audrey";
|
||||
|
||||
pub mod globals {
|
||||
use adw::gio;
|
||||
use std::path::PathBuf;
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
// can't use LazyLock sinze glib objects aren't thread safe
|
||||
thread_local! {
|
||||
pub static SETTINGS: gio::Settings = gio::Settings::new(crate::APP_ID);
|
||||
}
|
||||
|
||||
pub fn xdg_dirs() -> &'static xdg::BaseDirectories {
|
||||
static DIRS: std::sync::LazyLock<xdg::BaseDirectories> = std::sync::LazyLock::new(|| {
|
||||
xdg::BaseDirectories::with_prefix("audrey").expect("failed to get xdg dirs")
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
pub const VERSION: &str = "0.1.0"; // AUDREY_VERSION
|
||||
pub const USER_AGENT: &str = "audrey/linux";
|
||||
pub const APP_ID: &str = "eu.callcc.audrey";
|
||||
|
||||
mod application;
|
||||
pub use application::Application;
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@ impl Mpris {
|
|||
|
||||
#[zbus(property)]
|
||||
fn desktop_entry(&self) -> String {
|
||||
crate::APP_ID.to_string()
|
||||
audrey::APP_ID.to_string()
|
||||
}
|
||||
|
||||
#[zbus(property)]
|
||||
|
|
|
@ -107,7 +107,7 @@ impl Client {
|
|||
("t", token),
|
||||
("s", salt),
|
||||
("v", "1.16.1"),
|
||||
("c", crate::APP_ID),
|
||||
("c", audrey::APP_ID),
|
||||
("f", "json"),
|
||||
],
|
||||
)
|
||||
|
@ -139,7 +139,7 @@ impl Client {
|
|||
});
|
||||
|
||||
let reqwest_client = reqwest::Client::builder()
|
||||
.user_agent(crate::USER_AGENT)
|
||||
.user_agent(audrey::USER_AGENT)
|
||||
.build()?;
|
||||
|
||||
let client = reqwest_middleware::ClientBuilder::new(reqwest_client)
|
||||
|
|
|
@ -98,7 +98,7 @@ mod imp {
|
|||
|
||||
// FIXME: remove unwraps
|
||||
let keyring = oo7::Keyring::new().await.unwrap();
|
||||
let mut attributes = vec![("xdg:schema", crate::APP_ID.to_string())];
|
||||
let mut attributes = vec![("xdg:schema", audrey::APP_ID.to_string())];
|
||||
// clear previous passwords
|
||||
keyring.delete(&attributes).await.unwrap();
|
||||
|
||||
|
@ -149,7 +149,7 @@ impl Setup {
|
|||
let keyring = oo7::Keyring::new().await.unwrap();
|
||||
// make sure the keyring is unlocked
|
||||
keyring.unlock().await.unwrap();
|
||||
let attributes = vec![("xdg:schema", crate::APP_ID)];
|
||||
let attributes = vec![("xdg:schema", audrey::APP_ID)];
|
||||
let items = keyring.search_items(&attributes).await.unwrap();
|
||||
|
||||
if items.is_empty() {
|
||||
|
|
|
@ -93,7 +93,7 @@ mod imp {
|
|||
fn default() -> Self {
|
||||
let mpv = mpv::Handle::new();
|
||||
mpv.set_property("audio-client-name", "audrey").unwrap();
|
||||
mpv.set_property("user-agent", crate::USER_AGENT).unwrap();
|
||||
mpv.set_property("user-agent", audrey::USER_AGENT).unwrap();
|
||||
mpv.set_property("vid", false).unwrap();
|
||||
mpv.set_property("prefetch-playlist", true).unwrap();
|
||||
|
||||
|
@ -226,7 +226,7 @@ mod imp {
|
|||
None::<&glib::Object>,
|
||||
);
|
||||
|
||||
let settings = gio::Settings::new(crate::APP_ID);
|
||||
audrey::globals::SETTINGS.with(|settings| {
|
||||
settings.bind("mute", self.obj().as_ref(), "mute").build();
|
||||
settings
|
||||
.bind("volume", self.obj().as_ref(), "volume")
|
||||
|
@ -237,6 +237,7 @@ mod imp {
|
|||
if settings.boolean("is-maximized") {
|
||||
self.obj().maximize();
|
||||
}
|
||||
});
|
||||
|
||||
// update time-pos every 100 ms
|
||||
let window = self.obj().downgrade();
|
||||
|
@ -362,13 +363,13 @@ mod imp {
|
|||
impl WindowImpl for Window {
|
||||
fn close_request(&self) -> glib::Propagation {
|
||||
let size = self.obj().default_size();
|
||||
// TODO: don't instantiate this so many times maybe? OnceCell in imp struct?
|
||||
let settings = gio::Settings::new(crate::APP_ID);
|
||||
audrey::globals::SETTINGS.with(|settings| {
|
||||
settings.set_int("window-width", size.0).unwrap();
|
||||
settings.set_int("window-height", size.1).unwrap();
|
||||
settings
|
||||
.set_boolean("is-maximized", self.obj().is_maximized())
|
||||
.unwrap();
|
||||
});
|
||||
|
||||
glib::Propagation::Proceed
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue