Clean up shared theme imports in portal consent dialog
This commit is contained in:
1 parent
46a6d08a83
commit
da1428dd00
1 file changed
+16
-15
+16
-15
@@ -4,8 +4,10 @@ use cosmic::{
|
|||||||
iced::{Alignment, Length},
|
iced::{Alignment, Length},
|
||||||
widget::{button, column, container, image, row, scrollable, text_input},
|
widget::{button, column, container, image, row, scrollable, text_input},
|
||||||
};
|
};
|
||||||
|
use ferese_theme::{Palette, accent_button, controls, material::ModalMaterial, text};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[derive(Clone, Serialize, Deserialize)]
|
#[derive(Clone, Serialize, Deserialize)]
|
||||||
pub(crate) struct Prompt {
|
pub(crate) struct Prompt {
|
||||||
@@ -31,8 +33,8 @@ enum Message {
|
|||||||
Attached(
|
Attached(
|
||||||
Result<
|
Result<
|
||||||
(
|
(
|
||||||
Option<std::sync::Arc<crate::parent::Parent>>,
|
Option<Arc<crate::parent::Parent>>,
|
||||||
Result<ferese_theme::material::ModalMaterial, String>,
|
Result<ModalMaterial, String>,
|
||||||
),
|
),
|
||||||
String,
|
String,
|
||||||
>,
|
>,
|
||||||
@@ -45,9 +47,9 @@ enum Message {
|
|||||||
struct Consent {
|
struct Consent {
|
||||||
core: Core,
|
core: Core,
|
||||||
prompt: Prompt,
|
prompt: Prompt,
|
||||||
material: Option<ferese_theme::material::ModalMaterial>,
|
material: Option<ModalMaterial>,
|
||||||
parent: Option<std::sync::Arc<crate::parent::Parent>>,
|
parent: Option<Arc<crate::parent::Parent>>,
|
||||||
palette: ferese_theme::Palette,
|
palette: Palette,
|
||||||
font: cosmic::font::Font,
|
font: cosmic::font::Font,
|
||||||
background: cosmic::iced::Color,
|
background: cosmic::iced::Color,
|
||||||
}
|
}
|
||||||
@@ -57,9 +59,11 @@ pub(crate) fn run() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
std::io::stdin()
|
std::io::stdin()
|
||||||
.take(256 * 1024 + 1)
|
.take(256 * 1024 + 1)
|
||||||
.read_to_string(&mut input)?;
|
.read_to_string(&mut input)?;
|
||||||
|
|
||||||
if input.len() > 256 * 1024 {
|
if input.len() > 256 * 1024 {
|
||||||
return Err("Consent request is too large".into());
|
return Err("Consent request is too large".into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let prompt: Prompt = serde_json::from_str(&input)?;
|
let prompt: Prompt = serde_json::from_str(&input)?;
|
||||||
let (theme, font, background, _) = crate::picker::appearance();
|
let (theme, font, background, _) = crate::picker::appearance();
|
||||||
let height = if prompt.image.is_some() || !prompt.shortcuts.is_empty() {
|
let height = if prompt.image.is_some() || !prompt.shortcuts.is_empty() {
|
||||||
@@ -78,6 +82,7 @@ pub(crate) fn run() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
.is_daemon(false),
|
.is_daemon(false),
|
||||||
(prompt, font, background),
|
(prompt, font, background),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,7 +113,7 @@ impl cosmic::Application for Consent {
|
|||||||
let document = ferese_config::config_path()
|
let document = ferese_config::config_path()
|
||||||
.and_then(|path| std::fs::read_to_string(path).ok())
|
.and_then(|path| std::fs::read_to_string(path).ok())
|
||||||
.and_then(|source| ferese_config::Document::parse(&source).ok());
|
.and_then(|source| ferese_config::Document::parse(&source).ok());
|
||||||
ferese_theme::Palette::from_document(document.as_ref())
|
Palette::from_document(document.as_ref())
|
||||||
},
|
},
|
||||||
font,
|
font,
|
||||||
background,
|
background,
|
||||||
@@ -134,12 +139,8 @@ impl cosmic::Application for Consent {
|
|||||||
Message::Opened(id) => {
|
Message::Opened(id) => {
|
||||||
let parent = self.prompt.parent.clone();
|
let parent = self.prompt.parent.clone();
|
||||||
return cosmic::iced::window::run(id, move |window| {
|
return cosmic::iced::window::run(id, move |window| {
|
||||||
let parent =
|
let parent = crate::parent::Parent::attach(window, &parent)?.map(Arc::new);
|
||||||
crate::parent::Parent::attach(window, &parent)?.map(std::sync::Arc::new);
|
Ok((parent, ModalMaterial::attach(window)))
|
||||||
Ok((
|
|
||||||
parent,
|
|
||||||
ferese_theme::material::ModalMaterial::attach(window),
|
|
||||||
))
|
|
||||||
})
|
})
|
||||||
.map(|result| cosmic::Action::App(Message::Attached(result)));
|
.map(|result| cosmic::Action::App(Message::Attached(result)));
|
||||||
}
|
}
|
||||||
@@ -179,7 +180,7 @@ impl cosmic::Application for Consent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn view(&self) -> Element<'_, Message> {
|
fn view(&self) -> Element<'_, Message> {
|
||||||
let text = |value: String| ferese_theme::text(value, self.font);
|
let text = |value: String| text(value, self.font);
|
||||||
let mut details = column![text(self.prompt.description.clone())].spacing(12);
|
let mut details = column![text(self.prompt.description.clone())].spacing(12);
|
||||||
for (index, shortcut) in self.prompt.shortcuts.iter().enumerate() {
|
for (index, shortcut) in self.prompt.shortcuts.iter().enumerate() {
|
||||||
details = details.push(
|
details = details.push(
|
||||||
@@ -187,7 +188,7 @@ impl cosmic::Application for Consent {
|
|||||||
text(shortcut.description.clone()),
|
text(shortcut.description.clone()),
|
||||||
text_input("Ctrl+Alt+k (leave empty to disable)", &shortcut.trigger)
|
text_input("Ctrl+Alt+k (leave empty to disable)", &shortcut.trigger)
|
||||||
.font(self.font)
|
.font(self.font)
|
||||||
.style(ferese_theme::controls::settings_input(self.palette))
|
.style(controls::settings_input(self.palette))
|
||||||
.on_input(move |value| Message::Shortcut(index, value))
|
.on_input(move |value| Message::Shortcut(index, value))
|
||||||
]
|
]
|
||||||
.spacing(6),
|
.spacing(6),
|
||||||
@@ -212,7 +213,7 @@ impl cosmic::Application for Consent {
|
|||||||
.class(cosmic::theme::Button::Text)
|
.class(cosmic::theme::Button::Text)
|
||||||
.on_press(Message::Cancel),
|
.on_press(Message::Cancel),
|
||||||
button::custom(text(self.prompt.accept.clone()))
|
button::custom(text(self.prompt.accept.clone()))
|
||||||
.class(ferese_theme::accent_button())
|
.class(accent_button())
|
||||||
.on_press(Message::Accept)
|
.on_press(Message::Accept)
|
||||||
]
|
]
|
||||||
.spacing(12)
|
.spacing(12)
|
||||||
|
|||||||
Reference in new issue
Block a user