feat: add about drawer
Some checks are pending
Validate .desktop files / validate (push) Waiting to run
Some checks are pending
Validate .desktop files / validate (push) Waiting to run
This commit is contained in:
parent
bee543258a
commit
91b1ad874d
6 changed files with 100 additions and 3 deletions
48
src/main.rs
48
src/main.rs
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright 2023 System76 <info@system76.com>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use cosmic::app::{Core, Settings, Task};
|
||||
use cosmic::app::{Core, Settings, Task, context_drawer};
|
||||
use cosmic::command::set_theme;
|
||||
use cosmic::cosmic_config::{self, CosmicConfigEntry};
|
||||
use cosmic::iced::event::{self, Event};
|
||||
|
|
@ -12,7 +12,7 @@ use cosmic::iced::{
|
|||
};
|
||||
use cosmic::iced::window::set_mode;
|
||||
use cosmic::widget::menu::action::MenuAction;
|
||||
use cosmic::widget::{self, Slider, nav_bar, segmented_button};
|
||||
use cosmic::widget::{self, Slider, about::About, nav_bar, segmented_button};
|
||||
use cosmic::{Application, ApplicationExt, Element, action, cosmic_theme, executor, font, theme};
|
||||
use iced_video_player::gst::prelude::*;
|
||||
use iced_video_player::{Video, VideoPlayer, gst, gst_pbutils};
|
||||
|
|
@ -167,6 +167,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub enum Action {
|
||||
About,
|
||||
FileClose,
|
||||
FileOpen,
|
||||
FileClearRecents,
|
||||
|
|
@ -192,6 +193,7 @@ impl MenuAction for Action {
|
|||
|
||||
fn message(&self) -> Message {
|
||||
match self {
|
||||
Self::About => Message::ToggleAbout,
|
||||
Self::FileClose => Message::FileClose,
|
||||
Self::FileOpen => Message::FileOpen,
|
||||
Self::FileClearRecents => Message::FileClearRecents,
|
||||
|
|
@ -289,6 +291,7 @@ pub enum Message {
|
|||
FolderOpenRecent(usize),
|
||||
MultipleLoad(Vec<url::Url>),
|
||||
Fullscreen,
|
||||
LaunchUrl(String),
|
||||
Key(Modifiers, Key),
|
||||
AudioCode(usize),
|
||||
AudioToggle,
|
||||
|
|
@ -314,12 +317,14 @@ pub enum Message {
|
|||
AbRepeat,
|
||||
ShowControls,
|
||||
SystemThemeModeChange(cosmic_theme::ThemeMode),
|
||||
ToggleAbout,
|
||||
WindowClose,
|
||||
}
|
||||
|
||||
/// The [`App`] stores application-specific state.
|
||||
pub struct App {
|
||||
core: Core,
|
||||
about: About,
|
||||
flags: Flags,
|
||||
album_art_opt: Option<tempfile::NamedTempFile>,
|
||||
controls: bool,
|
||||
|
|
@ -883,8 +888,26 @@ impl Application for App {
|
|||
tx
|
||||
};
|
||||
|
||||
let about = About::default()
|
||||
.name(fl!("xdg-name"))
|
||||
.icon(widget::icon::from_name(Self::APP_ID))
|
||||
.version(env!("CARGO_PKG_VERSION"))
|
||||
.author("System76")
|
||||
.comments(fl!("xdg-comment"))
|
||||
.license("GPL-3.0-only")
|
||||
.license_url("https://spdx.org/licenses/GPL-3.0-only")
|
||||
.developers([("Jeremy Soller", "jeremy@system76.com")])
|
||||
.links([
|
||||
(fl!("repository"), "https://github.com/pop-os/cosmic-player"),
|
||||
(
|
||||
fl!("support"),
|
||||
"https://github.com/pop-os/cosmic-player/issues",
|
||||
),
|
||||
]);
|
||||
|
||||
let mut app = App {
|
||||
core,
|
||||
about,
|
||||
flags,
|
||||
album_art_opt: None,
|
||||
controls: true,
|
||||
|
|
@ -1202,6 +1225,12 @@ impl Application for App {
|
|||
);
|
||||
}
|
||||
}
|
||||
Message::LaunchUrl(url) => match open::that_detached(&url) {
|
||||
Ok(()) => {}
|
||||
Err(err) => {
|
||||
log::warn!("failed to open URL {:?}: {}", url, err);
|
||||
}
|
||||
},
|
||||
Message::Key(modifiers, key) => {
|
||||
for (key_bind, action) in self.key_binds.iter() {
|
||||
if key_bind.matches(modifiers, &key) {
|
||||
|
|
@ -1611,6 +1640,9 @@ impl Application for App {
|
|||
Message::SystemThemeModeChange(_theme_mode) => {
|
||||
return self.update_config();
|
||||
}
|
||||
Message::ToggleAbout => {
|
||||
self.core.set_show_context(!self.core.window.show_context);
|
||||
}
|
||||
Message::WindowClose => {
|
||||
self.close();
|
||||
return exit();
|
||||
|
|
@ -1630,6 +1662,18 @@ impl Application for App {
|
|||
)]
|
||||
}
|
||||
|
||||
fn context_drawer(&self) -> Option<context_drawer::ContextDrawer<'_, Message>> {
|
||||
if !self.core.window.show_context {
|
||||
return None;
|
||||
}
|
||||
|
||||
Some(context_drawer::about(
|
||||
&self.about,
|
||||
|url| Message::LaunchUrl(url.to_string()),
|
||||
Message::ToggleAbout,
|
||||
))
|
||||
}
|
||||
|
||||
/// Creates a view after each update.
|
||||
fn view(&self) -> Element<'_, Self::Message> {
|
||||
let theme = theme::active();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue