Skip to content

Commit 1bddd27

Browse files
authored
fix: ctrl q closes application (#180)
* chore: information relating Validity support into Help * chore: update CHANGELOG.md * chore: add keybinding for closing the application * chore: update CHANGELOG
1 parent e0c0dcb commit 1bddd27

4 files changed

Lines changed: 31 additions & 11 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
### Added
11+
12+
- Ctrl + Q quits application
13+
1014
### Changed
1115

1216
- Improved Help theming and added open-fprintd link

src/app/application.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,7 @@ impl cosmic::Application for AppModel {
161161
.on_press(Message::ConfirmDeleteAll),
162162
)
163163
.secondary_action(
164-
widget::button::standard(fl!("cancel"))
165-
.on_press(Message::CancelDeleteAll),
164+
widget::button::standard(fl!("cancel")).on_press(Message::CancelDeleteAll),
166165
)
167166
.into(),
168167
)
@@ -269,6 +268,7 @@ impl cosmic::Application for AppModel {
269268
Message::ClearDevice => self.on_clear_device(),
270269
Message::CancelClear => self.on_cancel_clear(),
271270
Message::ClearComplete(res) => self.on_clear_completion(res),
271+
Message::CloseApplication => self.on_close(),
272272
Message::Register => self.on_register(),
273273
Message::OpenRepositoryUrl => self.on_clicked_link(),
274274
Message::ToggleContextPage(context_page) => self.on_context_page_toggle(context_page),

src/app/message.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ pub enum Message {
4444
ClearDevice,
4545
CancelClear,
4646
ClearComplete(Result<(), AppError>),
47+
CloseApplication,
4748
EnrolledFingers(Vec<String>),
4849
FingerSelected(String),
4950
VerifyFinger,
@@ -57,6 +58,13 @@ pub enum Message {
5758

5859
// Section for handling of Messages
5960
impl AppModel {
61+
/// Closes the application
62+
///
63+
/// **Return** ***Task***::*done*()
64+
pub(crate) fn on_close(&mut self) -> Task<cosmic::Action<Message>> {
65+
Task::done(cosmic::app::Action::Close).map(cosmic::Action::Cosmic)
66+
}
67+
6068
/// Resets clear state
6169
///
6270
/// **Returns** ***Task***()

src/app/subscription.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
use crate::app::{
2-
Message, error::AppError, finger::Finger, fprint::{enroll_fingerprint_process, verify_finger_process}
2+
Message,
3+
error::AppError,
4+
finger::Finger,
5+
fprint::{enroll_fingerprint_process, verify_finger_process},
36
};
47
use ashpd::desktop::settings::{ColorScheme, Settings};
58
use cosmic::iced::{
@@ -106,8 +109,9 @@ pub(crate) fn verify_subscription(data: VerifyData) -> Subscription<Message> {
106109
&data.device_path,
107110
&data.finger.as_finger_id().unwrap_or_default(),
108111
&data.username,
109-
&mut output)
110-
.await
112+
&mut output,
113+
)
114+
.await
111115
{
112116
Ok(_) => {}
113117
Err(e) => {
@@ -163,7 +167,7 @@ pub fn portal_theme_subscription(app_theme: crate::config::AppTheme) -> Subscrip
163167
}
164168
}
165169

166-
/// **Returns** a subscription to key events 0-9, r, v, c, Ctrl + d, Tab, Shift + Tab, F1, and Ctrl + ,
170+
/// **Returns** a subscription to key events 0-9, r, v, c, Ctrl + d/,/q and F1
167171
pub fn key_subscription() -> Subscription<Message> {
168172
cosmic::iced::event::listen_raw(|event, _status, _window| {
169173
let Event::Keyboard(keyboard::Event::KeyPressed { key, modifiers, .. }) = event else {
@@ -175,13 +179,17 @@ pub fn key_subscription() -> Subscription<Message> {
175179
use cosmic::iced::keyboard::key::Named;
176180

177181
match &key {
178-
Key::Named(Named::F1) if !modifiers.control() && !modifiers.logo() && !modifiers.alt() => {
182+
Key::Named(Named::F1)
183+
if !modifiers.control() && !modifiers.logo() && !modifiers.alt() =>
184+
{
179185
Some(Message::ToggleContextPage(ContextPage::About))
180186
}
181-
Key::Character(c) if modifiers.control() && c == "," => {
182-
Some(Message::ToggleContextPage(ContextPage::Settings))
183-
}
184-
Key::Character(c) if modifiers.control() && c == "d" => Some(Message::Delete),
187+
Key::Character(c) if modifiers.control() => match c.as_str() {
188+
"," => Some(Message::ToggleContextPage(ContextPage::Settings)),
189+
"q" => Some(Message::CloseApplication),
190+
"d" => Some(Message::Delete),
191+
_ => None,
192+
},
185193
Key::Character(c) if !modifiers.control() && !modifiers.logo() && !modifiers.alt() => {
186194
match c.as_str() {
187195
"r" => Some(Message::Register),

0 commit comments

Comments
 (0)