Can apply changes to obs settings now
Some checks are pending
/ test (push) Waiting to run

This commit is contained in:
Chris Cochrun 2025-10-22 06:42:01 -05:00
parent 15d35f63ff
commit 1c319d8b78
3 changed files with 141 additions and 37 deletions

View file

@ -5,6 +5,7 @@ pub mod kinds;
pub mod model; pub mod model;
pub mod presentations; pub mod presentations;
pub mod service_items; pub mod service_items;
pub mod settings;
pub mod slide; pub mod slide;
pub mod songs; pub mod songs;
pub mod thumbnail; pub mod thumbnail;

View file

@ -5,6 +5,7 @@ use core::slide::{
}; };
use cosmic::app::context_drawer::ContextDrawer; use cosmic::app::context_drawer::ContextDrawer;
use cosmic::app::{Core, Settings, Task}; use cosmic::app::{Core, Settings, Task};
use cosmic::cosmic_config::{Config, CosmicConfigEntry};
use cosmic::dialog::file_chooser::save; use cosmic::dialog::file_chooser::save;
use cosmic::iced::alignment::Vertical; use cosmic::iced::alignment::Vertical;
use cosmic::iced::keyboard::{Key, Modifiers}; use cosmic::iced::keyboard::{Key, Modifiers};
@ -16,13 +17,14 @@ use cosmic::iced::{
use cosmic::iced_core::text::Wrapping; use cosmic::iced_core::text::Wrapping;
use cosmic::iced_futures::Subscription; use cosmic::iced_futures::Subscription;
use cosmic::iced_widget::{column, row, stack}; use cosmic::iced_widget::{column, row, stack};
use cosmic::theme;
use cosmic::widget::dnd_destination::dnd_destination; use cosmic::widget::dnd_destination::dnd_destination;
use cosmic::widget::menu::key_bind::Modifier; use cosmic::widget::menu::key_bind::Modifier;
use cosmic::widget::menu::{ItemWidth, KeyBind}; use cosmic::widget::menu::{ItemWidth, KeyBind};
use cosmic::widget::nav_bar::nav_bar_style; use cosmic::widget::nav_bar::nav_bar_style;
use cosmic::widget::tooltip::Position as TPosition; use cosmic::widget::tooltip::Position as TPosition;
use cosmic::widget::{Container, divider, menu}; use cosmic::widget::{
Container, divider, menu, settings, text_input,
};
use cosmic::widget::{ use cosmic::widget::{
Space, button, context_menu, horizontal_space, mouse_area, Space, button, context_menu, horizontal_space, mouse_area,
nav_bar, nav_bar_toggle, responsive, scrollable, search_input, nav_bar, nav_bar_toggle, responsive, scrollable, search_input,
@ -31,6 +33,7 @@ use cosmic::widget::{
use cosmic::widget::{container, text}; use cosmic::widget::{container, text};
use cosmic::widget::{icon, slider}; use cosmic::widget::{icon, slider};
use cosmic::{Application, ApplicationExt, Element, executor}; use cosmic::{Application, ApplicationExt, Element, executor};
use cosmic::{cosmic_config, theme};
use crisp::types::Value; use crisp::types::Value;
use lisp::parse_lisp; use lisp::parse_lisp;
use miette::{IntoDiagnostic, Result, miette}; use miette::{IntoDiagnostic, Result, miette};
@ -143,6 +146,11 @@ struct App {
menu_keys: HashMap<KeyBind, MenuAction>, menu_keys: HashMap<KeyBind, MenuAction>,
context_menu: Option<usize>, context_menu: Option<usize>,
modifiers_pressed: Option<Modifiers>, modifiers_pressed: Option<Modifiers>,
settings_open: bool,
settings: core::settings::Settings,
config_handler: Option<Config>,
obs_url_id: cosmic::widget::Id,
obs_connection: String,
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@ -190,6 +198,9 @@ enum Message {
SaveAsDialog, SaveAsDialog,
SaveAs(PathBuf), SaveAs(PathBuf),
OpenSettings, OpenSettings,
CloseSettings,
SetObsUrl(String),
SetObsConnection(String),
ModifiersPressed(Modifiers), ModifiersPressed(Modifiers),
} }
@ -250,6 +261,36 @@ impl cosmic::Application for App {
windows.push(core.main_window_id().unwrap()); windows.push(core.main_window_id().unwrap());
} }
let (config_handler, settings) =
match cosmic_config::Config::new(
Self::APP_ID,
core::settings::SETTINGS_VERSION,
) {
Ok(config_handler) => {
let config =
match core::settings::Settings::get_entry(
&config_handler,
) {
Ok(ok) => ok,
Err((errs, config)) => {
error!(
"errors loading settings: {:?}",
errs
);
config
}
};
(Some(config_handler), config)
}
Err(err) => {
error!(
"failed to create settings handler: {}",
err
);
(None, core::settings::Settings::default())
}
};
let items = if let Some(file) = input.file { let items = if let Some(file) = input.file {
match read_to_string(file) { match read_to_string(file) {
Ok(lisp) => { Ok(lisp) => {
@ -359,6 +400,11 @@ impl cosmic::Application for App {
hovered_dnd: None, hovered_dnd: None,
context_menu: None, context_menu: None,
modifiers_pressed: None, modifiers_pressed: None,
settings_open: false,
settings,
config_handler,
obs_url_id: cosmic::widget::Id::unique(),
obs_connection: "".into(),
}; };
let mut batch = vec![]; let mut batch = vec![];
@ -658,6 +704,18 @@ impl cosmic::Application for App {
} }
fn dialog(&self) -> Option<Element<'_, Self::Message>> { fn dialog(&self) -> Option<Element<'_, Self::Message>> {
let cosmic::cosmic_theme::Spacing {
space_none,
space_xxxs,
space_xxs,
space_xs,
space_s,
space_m,
space_l,
space_xl,
space_xxl,
space_xxxl,
} = cosmic::theme::spacing();
if self.searching { if self.searching {
let items: Vec<Element<Message>> = self let items: Vec<Element<Message>> = self
.search_results .search_results
@ -667,22 +725,15 @@ impl cosmic::Application for App {
let subtitle = text::body(item.to_string()); let subtitle = text::body(item.to_string());
Element::from(Container::new( Element::from(Container::new(
row![ row![
column![title, subtitle].spacing( column![title, subtitle]
cosmic::theme::active() .spacing(space_xxs),
.cosmic()
.space_xxs(),
),
horizontal_space(), horizontal_space(),
tooltip( tooltip(
button::icon( button::icon(
icon::from_name("add") icon::from_name("add")
.symbolic(true) .symbolic(true)
) )
.icon_size( .icon_size(space_l)
cosmic::theme::active()
.cosmic()
.space_l()
)
.on_press( .on_press(
Message::AppendServiceItemKind( Message::AppendServiceItemKind(
item.clone() item.clone()
@ -696,11 +747,7 @@ impl cosmic::Application for App {
icon::from_name("edit") icon::from_name("edit")
.symbolic(true) .symbolic(true)
) )
.icon_size( .icon_size(space_l)
cosmic::theme::active()
.cosmic()
.space_l()
)
.on_press(Message::OpenEditorKind( .on_press(Message::OpenEditorKind(
item.clone() item.clone()
)), )),
@ -714,27 +761,19 @@ impl cosmic::Application for App {
.collect(); .collect();
let modal = Container::new( let modal = Container::new(
column![ column![
search_input( search_input("Amazing Grace", &self.search_query)
"Amazing Grace",
self.search_query.clone()
)
.id(self.search_id.clone()) .id(self.search_id.clone())
.select_on_focus(true) .select_on_focus(true)
.on_input(Message::Search) .on_input(Message::Search)
.on_submit(Message::Search), .on_submit(Message::Search),
column(items).spacing( column(items).spacing(space_xxs)
cosmic::theme::active().cosmic().space_xxs()
)
] ]
.spacing(cosmic::theme::active().cosmic().space_s()), .spacing(space_s),
) )
.padding(cosmic::theme::active().cosmic().space_xl()) .padding(space_xl)
.style(nav_bar_style); .style(nav_bar_style);
let modal = Container::new(modal) let modal = Container::new(modal)
.padding([ .padding([space_xxl, space_xxxl * 2])
cosmic::theme::active().cosmic().space_xxl(),
cosmic::theme::active().cosmic().space_xxxl() * 2,
])
.center_x(Length::Fill) .center_x(Length::Fill)
.align_top(Length::Fill); .align_top(Length::Fill);
let mouse_stack = stack!( let mouse_stack = stack!(
@ -753,6 +792,52 @@ impl cosmic::Application for App {
modal modal
); );
Some(mouse_stack.into()) Some(mouse_stack.into())
} else if self.settings_open {
let obs_url =
if let Some(url) = self.settings.obs_url.clone() {
url.to_string()
} else {
"".to_string()
};
let obs_socket = settings::item(
"Obs Connection",
text_input("127.0.0.1", &self.obs_connection)
.select_on_focus(true)
.on_input(Message::SetObsConnection)
.on_submit(Message::SetObsConnection),
);
let apply_button = settings::item::builder("").control(
button::standard("Connect").on_press(
Message::SetObsUrl(self.obs_connection.clone()),
),
);
let settings_column = settings::section()
.title("Obs Settings")
.add(obs_socket)
.add(apply_button);
let settings_container = Container::new(settings_column)
.padding([space_xxl, space_xxxl * 2])
.style(nav_bar_style)
.center_x(Length::Fill)
.align_top(Length::Fill);
let modal = Container::new(settings_container)
.padding([space_xxl, space_xxxl * 2]);
let mouse_stack = stack!(
mouse_area(
container(Space::new(Length::Fill, Length::Fill))
.style(|_| {
container::background(
cosmic::iced::Background::Color(
Color::BLACK,
)
.scale_alpha(0.3),
)
})
)
.on_press(Message::CloseSettings),
modal
);
Some(mouse_stack.into())
} else { } else {
None None
} }
@ -1404,7 +1489,26 @@ impl cosmic::Application for App {
}) })
} }
Message::OpenSettings => { Message::OpenSettings => {
debug!("Opening settings"); self.settings_open = true;
Task::none()
}
Message::CloseSettings => {
self.settings_open = false;
Task::none()
}
Message::SetObsUrl(url) => {
if let Some(config) = &self.config_handler {
if let Err(e) = self.settings.set_obs_url(
&config,
url::Url::parse(&url).ok(),
) {
error!(?e, "Can't write to disk obs url")
};
};
Task::none()
}
Message::SetObsConnection(url) => {
self.obs_connection = url;
Task::none() Task::none()
} }
Message::ModifiersPressed(modifiers) => { Message::ModifiersPressed(modifiers) => {

View file

@ -820,8 +820,7 @@ pub(crate) fn slide_view<'a>(
.clip(true) .clip(true)
} else { } else {
Container::new(Space::new(0.0, 0.0)) Container::new(Space::new(0.0, 0.0))
.center_x(width) .center(Length::Fill)
.center_y(size.height)
.clip(true) .clip(true)
} }
} }