Compare commits
2 commits
7e0a019893
...
b0a33ad0f6
| Author | SHA1 | Date | |
|---|---|---|---|
| b0a33ad0f6 | |||
| 8699a08948 |
1 changed files with 119 additions and 110 deletions
229
src/main.rs
229
src/main.rs
|
|
@ -32,7 +32,7 @@ use cosmic::widget::{
|
|||
};
|
||||
use cosmic::widget::{container, text};
|
||||
use cosmic::widget::{icon, slider};
|
||||
use cosmic::{Application, ApplicationExt, Element, executor};
|
||||
use cosmic::{Application, ApplicationExt, Apply, Element, executor};
|
||||
use cosmic::{cosmic_config, theme};
|
||||
use crisp::types::Value;
|
||||
use lisp::parse_lisp;
|
||||
|
|
@ -94,13 +94,32 @@ fn main() -> Result<()> {
|
|||
|
||||
let args = Cli::parse();
|
||||
|
||||
let (config_handler, config) = match cosmic_config::Config::new(
|
||||
App::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 settings;
|
||||
if args.ui {
|
||||
debug!("main view");
|
||||
settings = Settings::default()
|
||||
.debug(false)
|
||||
.is_daemon(true)
|
||||
.transparent(true);
|
||||
settings = Settings::default().debug(false).is_daemon(true);
|
||||
} else {
|
||||
debug!("window view");
|
||||
settings = Settings::default()
|
||||
|
|
@ -109,7 +128,7 @@ fn main() -> Result<()> {
|
|||
.is_daemon(true);
|
||||
}
|
||||
|
||||
cosmic::app::run::<App>(settings, args)
|
||||
cosmic::app::run::<App>(settings, (args, config_handler, config))
|
||||
.map_err(|e| miette!("Invalid things... {}", e))
|
||||
}
|
||||
|
||||
|
|
@ -235,7 +254,11 @@ const HEADER_SPACE: u16 = 6;
|
|||
|
||||
impl cosmic::Application for App {
|
||||
type Executor = executor::Default;
|
||||
type Flags = Cli;
|
||||
type Flags = (
|
||||
Cli,
|
||||
Option<cosmic_config::Config>,
|
||||
core::settings::Settings,
|
||||
);
|
||||
type Message = Message;
|
||||
const APP_ID: &'static str = "lumina";
|
||||
fn core(&self) -> &Core {
|
||||
|
|
@ -257,41 +280,13 @@ impl cosmic::Application for App {
|
|||
|
||||
let mut windows = vec![];
|
||||
|
||||
if input.ui {
|
||||
if input.0.ui {
|
||||
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 (config_handler, settings) = (input.1, input.2);
|
||||
|
||||
let items = if let Some(file) = input.file {
|
||||
let items = if let Some(file) = input.0.file {
|
||||
match read_to_string(file) {
|
||||
Ok(lisp) => {
|
||||
let mut service_items = vec![];
|
||||
|
|
@ -366,7 +361,7 @@ impl cosmic::Application for App {
|
|||
menu_keys.insert(
|
||||
KeyBind {
|
||||
modifiers: vec![Modifier::Ctrl],
|
||||
key: Key::Character(".".into()),
|
||||
key: Key::Character(",".into()),
|
||||
},
|
||||
MenuAction::OpenSettings,
|
||||
);
|
||||
|
|
@ -380,7 +375,7 @@ impl cosmic::Application for App {
|
|||
file: PathBuf::default(),
|
||||
windows,
|
||||
presentation_open: false,
|
||||
cli_mode: !input.ui,
|
||||
cli_mode: !input.0.ui,
|
||||
library: None,
|
||||
library_open: true,
|
||||
editor_mode: None,
|
||||
|
|
@ -409,7 +404,7 @@ impl cosmic::Application for App {
|
|||
|
||||
let mut batch = vec![];
|
||||
|
||||
if input.ui {
|
||||
if input.0.ui {
|
||||
debug!("main view");
|
||||
batch.push(app.update_title());
|
||||
} else {
|
||||
|
|
@ -723,82 +718,74 @@ impl cosmic::Application for App {
|
|||
.map(|item| {
|
||||
let title = text::title4(item.title().clone());
|
||||
let subtitle = text::body(item.to_string());
|
||||
Element::from(Container::new(
|
||||
Element::from(
|
||||
row![
|
||||
column![title, subtitle]
|
||||
.spacing(space_xxs),
|
||||
horizontal_space(),
|
||||
tooltip(
|
||||
button::icon(
|
||||
icon::from_name("add")
|
||||
.symbolic(true)
|
||||
)
|
||||
.icon_size(space_l)
|
||||
.on_press(
|
||||
Message::AppendServiceItemKind(
|
||||
item.clone()
|
||||
)
|
||||
),
|
||||
icon::from_name("add")
|
||||
.symbolic(true).apply(button::icon)
|
||||
.icon_size(space_l)
|
||||
.on_press(
|
||||
Message::AppendServiceItemKind(
|
||||
item.clone()
|
||||
)
|
||||
),
|
||||
"Add to service",
|
||||
TPosition::FollowCursor
|
||||
),
|
||||
tooltip(
|
||||
button::icon(
|
||||
icon::from_name("edit")
|
||||
.symbolic(true)
|
||||
)
|
||||
.icon_size(space_l)
|
||||
.on_press(Message::OpenEditorKind(
|
||||
item.clone()
|
||||
)),
|
||||
icon::from_name("edit")
|
||||
.symbolic(true).apply(button::icon)
|
||||
.icon_size(space_l)
|
||||
.on_press(Message::OpenEditorKind(
|
||||
item.clone()
|
||||
)),
|
||||
"Edit Item",
|
||||
TPosition::FollowCursor
|
||||
),
|
||||
]
|
||||
.align_y(Vertical::Center),
|
||||
))
|
||||
.align_y(Vertical::Center)
|
||||
.apply(container),
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
let modal = Container::new(
|
||||
column![
|
||||
search_input("Amazing Grace", &self.search_query)
|
||||
.id(self.search_id.clone())
|
||||
.select_on_focus(true)
|
||||
.on_input(Message::Search)
|
||||
.on_submit(Message::Search),
|
||||
column(items).spacing(space_xxs)
|
||||
]
|
||||
.spacing(space_s),
|
||||
)
|
||||
let modal = column![
|
||||
search_input("Amazing Grace", &self.search_query)
|
||||
.id(self.search_id.clone())
|
||||
.select_on_focus(true)
|
||||
.on_input(Message::Search)
|
||||
.on_submit(Message::Search),
|
||||
column(items).spacing(space_xxs)
|
||||
]
|
||||
.spacing(space_s)
|
||||
.apply(container)
|
||||
.padding(space_xl)
|
||||
.style(nav_bar_style);
|
||||
let modal = Container::new(modal)
|
||||
let modal = mouse_area(modal)
|
||||
.on_press(Message::None)
|
||||
.apply(container)
|
||||
.padding([space_xxl, space_xxxl * 2])
|
||||
.center_x(Length::Fill)
|
||||
.align_top(Length::Fill);
|
||||
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),
|
||||
Space::new(Length::Fill, Length::Fill)
|
||||
.apply(container)
|
||||
.style(|_| {
|
||||
container::background(
|
||||
cosmic::iced::Background::Color(
|
||||
Color::BLACK,
|
||||
)
|
||||
})
|
||||
)
|
||||
.on_press(Message::CloseSearch),
|
||||
.scale_alpha(0.3),
|
||||
)
|
||||
})
|
||||
.apply(mouse_area)
|
||||
.on_press(Message::CloseSearch),
|
||||
modal
|
||||
);
|
||||
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)
|
||||
|
|
@ -811,30 +798,50 @@ impl cosmic::Application for App {
|
|||
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])
|
||||
let settings_column = column![
|
||||
icon::from_name("dialog-close")
|
||||
.symbolic(true)
|
||||
.prefer_svg(true)
|
||||
.apply(button::icon)
|
||||
.class(theme::Button::Icon)
|
||||
.on_press(Message::CloseSettings)
|
||||
.apply(container)
|
||||
.padding(space_s)
|
||||
.align_right(Length::Fill)
|
||||
.align_top(60),
|
||||
horizontal_space().height(space_xxl),
|
||||
settings::section()
|
||||
.title("Obs Settings")
|
||||
.add(obs_socket)
|
||||
.add(apply_button)
|
||||
.apply(container)
|
||||
.center_x(Length::Fill)
|
||||
.align_top(Length::Fill)
|
||||
.padding([0, space_xxxl * 2])
|
||||
]
|
||||
.height(Length::Fill);
|
||||
let settings_container = settings_column
|
||||
.apply(container)
|
||||
.style(nav_bar_style)
|
||||
.center_x(Length::Fill)
|
||||
.align_top(Length::Fill);
|
||||
let modal = Container::new(settings_container)
|
||||
let modal = mouse_area(settings_container)
|
||||
.on_press(Message::None)
|
||||
.apply(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),
|
||||
Space::new(Length::Fill, Length::Fill)
|
||||
.apply(container)
|
||||
.style(|_| {
|
||||
container::background(
|
||||
cosmic::iced::Background::Color(
|
||||
Color::BLACK,
|
||||
)
|
||||
})
|
||||
)
|
||||
.on_press(Message::CloseSettings),
|
||||
.scale_alpha(0.3),
|
||||
)
|
||||
})
|
||||
.apply(mouse_area)
|
||||
.on_press(Message::CloseSettings),
|
||||
modal
|
||||
);
|
||||
Some(mouse_stack.into())
|
||||
|
|
@ -1228,6 +1235,7 @@ impl cosmic::Application for App {
|
|||
Task::none()
|
||||
}
|
||||
Message::SearchFocus => {
|
||||
self.settings_open = false;
|
||||
self.searching = true;
|
||||
cosmic::widget::text_input::focus(
|
||||
self.search_id.clone(),
|
||||
|
|
@ -1489,6 +1497,7 @@ impl cosmic::Application for App {
|
|||
})
|
||||
}
|
||||
Message::OpenSettings => {
|
||||
self.searching = false;
|
||||
self.settings_open = true;
|
||||
Task::none()
|
||||
}
|
||||
|
|
@ -1796,7 +1805,7 @@ where
|
|||
(Key::Character(k), Modifiers::CTRL) if k == *"o" => {
|
||||
self.update(Message::Open)
|
||||
}
|
||||
(Key::Character(k), Modifiers::CTRL) if k == *"." => {
|
||||
(Key::Character(k), Modifiers::CTRL) if k == *"," => {
|
||||
self.update(Message::OpenSettings)
|
||||
}
|
||||
(Key::Character(k), Modifiers::CTRL)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue