Skip to content

Commit 95c6294

Browse files
committed
Add update banner.
1 parent 49280a8 commit 95c6294

File tree

6 files changed

+126
-2
lines changed

6 files changed

+126
-2
lines changed
Lines changed: 2 additions & 0 deletions
Loading

assets/resources.xml.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@
44
<file compressed="true" preprocess="xml-stripblanks" alias="gtk/help-overlay.ui">gtk/help-overlay.ui</file>
55
<file compressed="true" preprocess="xml-stripblanks" alias="metainfo.xml">@[email protected]</file>
66
</gresource>
7+
<gresource prefix="@APP_PATH@/icons/scalable/actions/">
8+
<file preprocess="xml-stripblanks" alias="right-small-symbolic.svg">icons/hicolor/scalable/actions/right-small-symbolic.svg</file>
9+
</gresource>
710
</gresources>

gnome/src/app.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@ pub fn start(app: &adw::Application, files: &[gio::File]) {
2828
}
2929
}
3030

31+
let donate_action = SimpleAction::new("donate", None);
32+
donate_action.connect_activate(clone!(
33+
#[weak]
34+
window,
35+
move |_, _| {
36+
gtk::UriLauncher::new("https://ko-fi.com/luleyleo").launch(
37+
Some(&window),
38+
gio::Cancellable::NONE,
39+
|_| {},
40+
);
41+
}
42+
));
43+
app.add_action(&donate_action);
44+
3145
let about_action = SimpleAction::new("about", None);
3246
about_action.connect_activate(clone!(
3347
#[weak]
@@ -44,6 +58,41 @@ pub fn start(app: &adw::Application, files: &[gio::File]) {
4458
));
4559
app.add_action(&about_action);
4660

61+
let news_action = SimpleAction::new("news", None);
62+
news_action.connect_activate(clone!(
63+
#[weak]
64+
window,
65+
move |_, _| {
66+
let app = window.application().unwrap();
67+
let app_path = app.resource_base_path().unwrap();
68+
let dialog = adw::AboutDialog::from_appdata(
69+
&format!("{app_path}/metainfo.xml"),
70+
Some(env!("APP_VERSION")),
71+
);
72+
dialog.present(Some(&window));
73+
74+
let navigation_view = dialog
75+
.first_child() // adw::BreakpointBin
76+
.unwrap()
77+
.first_child() // adw::FloatingSheet
78+
.unwrap()
79+
.first_child()
80+
.unwrap()
81+
.next_sibling() // adw::Gizmo
82+
.unwrap()
83+
.first_child() // adw::BreakpointBin
84+
.unwrap()
85+
.first_child() // adw::ToastOverlay
86+
.unwrap()
87+
.first_child() // adw::NaviationView
88+
.unwrap()
89+
.downcast::<adw::NavigationView>()
90+
.unwrap();
91+
navigation_view.push_by_tag("whatsnew");
92+
}
93+
));
94+
app.add_action(&news_action);
95+
4796
let quit_action = SimpleAction::new("quit", None);
4897
quit_action.connect_activate(clone!(
4998
#[weak]

gnome/src/config.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ mod imp {
4242
#[property(name = "search-pdf", get, set, type = bool, member = pdf)]
4343
#[property(name = "search-office", get, set, type = bool, member = office)]
4444
search: RefCell<SearchConfig>,
45+
46+
#[property(get, set)]
47+
last_version: RefCell<String>,
4548
}
4649

4750
#[glib::object_subclass]
@@ -95,13 +98,15 @@ mod imp {
9598
self.window.replace(config.window);
9699
self.flags.replace(config.flags);
97100
self.search.replace(config.search);
101+
self.last_version.replace(config.last_version);
98102
}
99103

100104
pub fn save(&self) {
101105
let config = FullConfig {
102106
window: *self.window.borrow(),
103107
flags: *self.flags.borrow(),
104108
search: *self.search.borrow(),
109+
last_version: self.last_version.borrow().clone(),
105110
};
106111
let config_txt = toml::to_string(&config).expect("Failed to serialize config");
107112
let config_path = Self::config_path();
@@ -111,11 +116,23 @@ mod imp {
111116
}
112117
}
113118

114-
#[derive(Default, Clone, serde::Serialize, serde::Deserialize)]
119+
#[derive(Clone, serde::Serialize, serde::Deserialize)]
115120
struct FullConfig {
116121
window: WindowConfig,
117122
flags: SearchFlags,
118123
search: SearchConfig,
124+
last_version: String,
125+
}
126+
127+
impl Default for FullConfig {
128+
fn default() -> Self {
129+
Self {
130+
window: Default::default(),
131+
flags: Default::default(),
132+
search: Default::default(),
133+
last_version: env!("APP_VERSION").to_string(),
134+
}
135+
}
119136
}
120137

121138
#[derive(Clone, Copy, serde::Serialize, serde::Deserialize)]

gnome/src/ui/search_window/imp.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::{
55
ui::{preview::Preview, ErrorWindow, ResultHeaderView, ResultView},
66
APP_ID,
77
};
8-
use adw::subclass::prelude::*;
8+
use adw::{prelude::PreferencesGroupExt, subclass::prelude::*};
99
use clapgrep_core::{SearchEngine, SearchFlags, SearchMessage, SearchParameters};
1010
use gettextrs::gettext;
1111
use glib::subclass::InitializingObject;
@@ -73,6 +73,8 @@ pub struct SearchWindow {
7373
#[property(get)]
7474
pub search_errors_notification: RefCell<String>,
7575

76+
#[template_child]
77+
pub update_banner: TemplateChild<adw::PreferencesGroup>,
7678
#[template_child]
7779
pub results_stack: TemplateChild<gtk::Stack>,
7880
#[template_child]
@@ -183,6 +185,11 @@ impl SearchWindow {
183185
}
184186
}
185187
}
188+
189+
#[template_callback]
190+
fn on_hide_update_banner(&self) {
191+
self.update_banner.set_visible(false);
192+
}
186193
}
187194

188195
impl SearchWindow {
@@ -295,6 +302,14 @@ impl SearchWindow {
295302
*self.search_progress_notification.borrow_mut() = message;
296303
self.obj().notify("search_progress_notification");
297304
}
305+
306+
fn show_update_banner(&self, version: &str) {
307+
self.update_banner.set_title(&gettext_f(
308+
"Updated to {version} 🎉",
309+
&[("version", version)],
310+
));
311+
self.update_banner.set_visible(true);
312+
}
298313
}
299314

300315
#[glib::derived_properties]
@@ -367,6 +382,11 @@ impl ObjectImpl for SearchWindow {
367382
.sync_create()
368383
.build();
369384

385+
if self.config.last_version() != env!("APP_VERSION") {
386+
self.show_update_banner(env!("APP_VERSION"));
387+
self.config.set_last_version(env!("APP_VERSION"));
388+
}
389+
370390
obj.results().connect_items_changed(clone!(
371391
#[weak]
372392
obj,

gnome/src/ui/search_window/search_window.blp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,34 @@ template $ClapgrepSearchWindow: Adw.ApplicationWindow {
8888
}
8989
}
9090

91+
Adw.PreferencesGroup update_banner {
92+
visible: false;
93+
94+
[header-suffix]
95+
Button {
96+
clicked => $on_hide_update_banner() swapped;
97+
98+
child: Adw.ButtonContent {
99+
icon-name: "window-close-symbolic";
100+
};
101+
102+
styles [
103+
"flat",
104+
]
105+
}
106+
107+
Adw.ButtonRow {
108+
title: _("See what's new");
109+
end-icon-name: "right-small-symbolic";
110+
action-name: "app.news";
111+
}
112+
113+
Adw.ButtonRow {
114+
title: _("Donate 💝");
115+
action-name: "app.donate";
116+
}
117+
}
118+
91119
Adw.PreferencesGroup {
92120
title: _("Search Options");
93121

@@ -248,6 +276,11 @@ template $ClapgrepSearchWindow: Adw.ApplicationWindow {
248276

249277
menu menu_app {
250278
section {
279+
item {
280+
label: "Donate 💝";
281+
action: "app.donate";
282+
}
283+
251284
item {
252285
label: _("Keyboard Shortcuts");
253286
action: "win.show-help-overlay";

0 commit comments

Comments
 (0)