notifications settings
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -3722,7 +3722,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wlx-overlay-s"
|
||||
version = "0.2.2"
|
||||
version = "0.2.3"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"ash",
|
||||
|
||||
@@ -4,7 +4,7 @@ debug = true
|
||||
|
||||
[package]
|
||||
name = "wlx-overlay-s"
|
||||
version = "0.2.2"
|
||||
version = "0.2.3"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
use dbus::{blocking::Connection, channel::MatchingReceiver, message::MatchRule};
|
||||
use serde::Deserialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{
|
||||
sync::{
|
||||
mpsc::{self},
|
||||
Arc,
|
||||
},
|
||||
path::PathBuf,
|
||||
sync::{mpsc, Arc},
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use crate::{overlays::toast::Toast, state::AppState};
|
||||
use crate::{config::def_true, config_io, overlays::toast::Toast, state::AppState};
|
||||
|
||||
pub struct NotificationManager {
|
||||
rx_toast: mpsc::Receiver<Toast>,
|
||||
@@ -31,9 +29,14 @@ impl NotificationManager {
|
||||
let _ = c.process(Duration::ZERO);
|
||||
}
|
||||
|
||||
if app.session.config.notifications_enabled {
|
||||
self.rx_toast.try_iter().for_each(|toast| {
|
||||
toast.submit(app);
|
||||
});
|
||||
} else {
|
||||
// consume without submitting
|
||||
self.rx_toast.try_iter().last();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run_dbus(&mut self) {
|
||||
@@ -208,3 +211,29 @@ struct XsoMessage {
|
||||
sourceApp: Option<Arc<str>>,
|
||||
alwaysShow: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct NotifiConf {
|
||||
#[serde(default = "def_true")]
|
||||
pub notifications_enabled: bool,
|
||||
|
||||
#[serde(default = "def_true")]
|
||||
pub notifications_sound_enabled: bool,
|
||||
}
|
||||
|
||||
fn get_config_path() -> PathBuf {
|
||||
let mut path = config_io::get_conf_d_path();
|
||||
path.push("notifications.yaml");
|
||||
path
|
||||
}
|
||||
pub fn save_notifications(app: &mut AppState) -> anyhow::Result<()> {
|
||||
let conf = NotifiConf {
|
||||
notifications_enabled: app.session.config.notifications_enabled,
|
||||
notifications_sound_enabled: app.session.config.notifications_sound_enabled,
|
||||
};
|
||||
|
||||
let yaml = serde_yaml::to_string(&conf)?;
|
||||
std::fs::write(get_config_path(), yaml)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ fn def_click_freeze_time_ms() -> u32 {
|
||||
300
|
||||
}
|
||||
|
||||
fn def_true() -> bool {
|
||||
pub fn def_true() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ use crate::{
|
||||
backend::{
|
||||
common::{ColorChannel, OverlaySelector, SystemTask, TaskType},
|
||||
input::PointerMode,
|
||||
notifications::save_notifications,
|
||||
overlay::RelativeTo,
|
||||
},
|
||||
overlays::{
|
||||
@@ -44,6 +45,8 @@ pub enum Axis {
|
||||
|
||||
#[derive(Deserialize, Clone)]
|
||||
pub enum SystemAction {
|
||||
ToggleNotificationSounds,
|
||||
ToggleNotifications,
|
||||
PlayspaceResetOffset,
|
||||
PlayspaceFixFloor,
|
||||
RecalculateExtent,
|
||||
@@ -315,10 +318,46 @@ fn run_system(action: &SystemAction, app: &mut AppState) {
|
||||
SystemAction::RecalculateExtent => {
|
||||
todo!()
|
||||
}
|
||||
SystemAction::ToggleNotifications => {
|
||||
app.session.config.notifications_enabled = !app.session.config.notifications_enabled;
|
||||
Toast::new(
|
||||
format!(
|
||||
"Notifications are {}.",
|
||||
if app.session.config.notifications_enabled {
|
||||
"enabled"
|
||||
} else {
|
||||
"disabled"
|
||||
}
|
||||
)
|
||||
.into(),
|
||||
"".into(),
|
||||
)
|
||||
.submit(app);
|
||||
}
|
||||
SystemAction::ToggleNotificationSounds => {
|
||||
app.session.config.notifications_sound_enabled =
|
||||
!app.session.config.notifications_sound_enabled;
|
||||
Toast::new(
|
||||
format!(
|
||||
"Notification sounds are {}.",
|
||||
if app.session.config.notifications_sound_enabled {
|
||||
"enabled"
|
||||
} else {
|
||||
"disabled"
|
||||
}
|
||||
)
|
||||
.into(),
|
||||
"".into(),
|
||||
)
|
||||
.submit(app);
|
||||
}
|
||||
SystemAction::PersistConfig => {
|
||||
if let Err(e) = save_watch(app) {
|
||||
log::error!("Failed to save watch config: {:?}", e);
|
||||
};
|
||||
if let Err(e) = save_notifications(app) {
|
||||
log::error!("Failed to save notifications config: {:?}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ impl Toast {
|
||||
|
||||
let destroy_at = instant.add(std::time::Duration::from_secs_f32(self.timeout));
|
||||
|
||||
let has_sound = self.sound;
|
||||
let has_sound = self.sound && app.session.config.notifications_sound_enabled;
|
||||
|
||||
app.tasks.enqueue_at(
|
||||
TaskType::CreateOverlay(
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
width: 0.3
|
||||
|
||||
size: [600, 520]
|
||||
size: [600, 700]
|
||||
|
||||
# +X: right, +Y: up, +Z: back
|
||||
spawn_pos: [0, -0.1, -0.5]
|
||||
@@ -502,12 +502,45 @@ elements:
|
||||
- type: System
|
||||
action: PlayspaceResetOffset
|
||||
|
||||
####### Notifications Section #######
|
||||
|
||||
- type: Panel
|
||||
rect: [50, 460, 500, 1]
|
||||
bg_color: "#c0c0c0"
|
||||
|
||||
- type: Label
|
||||
rect: [325, 480, 90, 24]
|
||||
font_size: 18
|
||||
fg_color: "#ffffff"
|
||||
source: Static
|
||||
text: Notifications
|
||||
|
||||
- type: Button
|
||||
rect: [330, 480, 220, 30]
|
||||
rect: [330, 495, 220, 30]
|
||||
font_size: 12
|
||||
fg_color: "#ffffff"
|
||||
bg_color: "#606020"
|
||||
text: "Enabled"
|
||||
click_down:
|
||||
- type: System
|
||||
action: ToggleNotifications
|
||||
|
||||
- type: Button
|
||||
rect: [330, 545, 220, 30]
|
||||
font_size: 12
|
||||
fg_color: "#ffffff"
|
||||
bg_color: "#606020"
|
||||
text: "Sound Enabled"
|
||||
click_down:
|
||||
- type: System
|
||||
action: ToggleNotificationSounds
|
||||
|
||||
- type: Panel
|
||||
rect: [50, 595, 500, 1]
|
||||
bg_color: "#c0c0c0"
|
||||
|
||||
- type: Button
|
||||
rect: [330, 615, 220, 30]
|
||||
font_size: 12
|
||||
fg_color: "#ffffff"
|
||||
bg_color: "#206060"
|
||||
|
||||
Reference in New Issue
Block a user