Skip to content

Commit

Permalink
feat: support build pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
Decodetalkers committed Dec 3, 2024
1 parent cc725f5 commit 36d2fd5
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 40 deletions.
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lala_bar/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ iced = { version = "0.13.1", features = [
"markdown",
] }
iced_runtime = "0.13.2"
iced_layershell = "0.11.0-rc3"
iced_layershell = "0.11.0-rc5"
tokio = { version = "1.41", features = ["full"] }
iced_futures = "0.13.2"
env_logger = "0.11.5"
Expand Down
17 changes: 1 addition & 16 deletions lala_bar/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ use zbus_mpirs::ServiceInfo;
use futures::channel::mpsc::Sender;
use iced_aw::date_picker::Date;
use iced_aw::time_picker::Time;
use iced_layershell::reexport::{Anchor, Layer};
use iced_layershell::settings::{LayerShellSettings, Settings, StartMode};
use iced_layershell::MultiApplication;
use iced_layershell::{to_layer_message, LayerSingleton};

mod aximer;
Expand All @@ -35,19 +32,7 @@ pub fn main() -> Result<(), iced_layershell::Error> {
.add_directive("usvg=off".parse().unwrap()),
)
.init();
LalaMusicBar::run(Settings {
layer_settings: LayerShellSettings {
size: Some((0, 35)),
exclusive_zone: 35,
anchor: Anchor::Bottom | Anchor::Left | Anchor::Right,
layer: Layer::Top,
start_mode: StartMode::AllScreens,

..Default::default()
},
fonts: vec![std::borrow::Cow::Borrowed(iced_fonts::REQUIRED_FONT_BYTES)],
..Default::default()
})
music_bar::run_lalabar()
}

#[derive(Debug, Clone, PartialEq, LayerSingleton)]
Expand Down
49 changes: 35 additions & 14 deletions lala_bar/src/music_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ use iced::widget::{
button, checkbox, column, container, image, markdown, row, scrollable, slider, svg, text,
text_input, Space,
};
use iced::{executor, Alignment, Element, Font, Length, Task as Command, Theme};
use iced::{Alignment, Element, Font, Length, Task as Command, Theme};
use iced_aw::{date_picker::Date, helpers::date_picker, time_picker, time_picker::Time};
use iced_layershell::reexport::{Anchor, KeyboardInteractivity, Layer, NewLayerShellSettings};
use iced_layershell::MultiApplication;
use iced_layershell::settings::LayerShellSettings;
use iced_layershell::settings::StartMode;
use iced_runtime::window::Action as WindowAction;
use iced_runtime::Action;
use iced_zbus_notification::{
Expand All @@ -29,6 +30,32 @@ use iced_zbus_notification::{
};
use std::collections::HashMap;

use iced_layershell::build_pattern::daemon;

pub fn run_lalabar() -> iced_layershell::Result {
daemon(
LalaMusicBar::namespace,
LalaMusicBar::update,
LalaMusicBar::view,
LalaMusicBar::id_info,
LalaMusicBar::set_id_info,
LalaMusicBar::remove_id,
)
.layer_settings(LayerShellSettings {
size: Some((0, 35)),
exclusive_zone: 35,
anchor: Anchor::Bottom | Anchor::Left | Anchor::Right,
layer: Layer::Top,
start_mode: StartMode::AllScreens,

..Default::default()
})
.theme(LalaMusicBar::theme)
.subscription(LalaMusicBar::subscription)
.font(iced_fonts::REQUIRED_FONT_BYTES)
.run_with(LalaMusicBar::new)
}

pub struct LalaMusicBar {
pub(crate) service_data: Option<ServiceInfo>,
pub(crate) left: i64,
Expand Down Expand Up @@ -475,14 +502,8 @@ impl LalaMusicBar {
}
}

impl MultiApplication for LalaMusicBar {
type Message = Message;
type Flags = ();
type Executor = executor::Default;
type Theme = Theme;
type WindowInfo = LaLaInfo;

fn new(_flags: Self::Flags) -> (Self, Command<Message>) {
impl LalaMusicBar {
fn new() -> (Self, Command<Message>) {
(
Self {
service_data: None,
Expand Down Expand Up @@ -520,7 +541,7 @@ impl MultiApplication for LalaMusicBar {
String::from("Mpirs_panel")
}

fn id_info(&self, id: iced::window::Id) -> Option<Self::WindowInfo> {
fn id_info(&self, id: iced::window::Id) -> Option<LaLaInfo> {
if self.launcherid.is_some_and(|tid| tid == id) {
Some(LaLaInfo::Launcher)
} else if self.hiddenid.is_some_and(|tid| tid == id) {
Expand All @@ -546,7 +567,7 @@ impl MultiApplication for LalaMusicBar {
}
}

fn set_id_info(&mut self, id: iced::window::Id, info: Self::WindowInfo) {
fn set_id_info(&mut self, id: iced::window::Id, info: LaLaInfo) {
match info {
LaLaInfo::Launcher => {
self.launcherid = Some(id);
Expand Down Expand Up @@ -1195,7 +1216,7 @@ impl MultiApplication for LalaMusicBar {
self.main_view()
}

fn subscription(&self) -> iced::Subscription<Self::Message> {
fn subscription(&self) -> iced::Subscription<Message> {
iced::Subscription::batch([
iced::time::every(std::time::Duration::from_secs(1))
.map(|_| Message::RequestDBusInfoUpdate),
Expand Down Expand Up @@ -1290,7 +1311,7 @@ impl MultiApplication for LalaMusicBar {
])
}

fn theme(&self) -> Self::Theme {
pub fn theme(&self) -> iced::Theme {
Theme::TokyoNight
}
}
1 change: 0 additions & 1 deletion lala_bar/src/notify.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::{LalaMusicBar, Message};
use iced::widget::{button, column, image, markdown, row, svg, text, Space, Stack};
use iced::{Font, Length};
use iced_layershell::MultiApplication;
use iced_zbus_notification::{ImageInfo, NotifyUnit};

#[derive(Debug, Clone, PartialEq)]
Expand Down

0 comments on commit 36d2fd5

Please sign in to comment.