Skip to content

Commit c2932d4

Browse files
committed
simplify this
1 parent 3734192 commit c2932d4

File tree

1 file changed

+16
-33
lines changed

1 file changed

+16
-33
lines changed

src/application.rs

+16-33
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ glib::wrapper! {
7979
@implements gio::ActionGroup, gio::ActionMap;
8080
}
8181

82+
fn load_string(path: &str) -> String {
83+
let Ok(data) = gio::resources_lookup_data(path, gio::ResourceLookupFlags::empty()) else {
84+
return format!("{path} not found");
85+
};
86+
String::from_utf8(data.to_vec()).unwrap_or_else(|e| format!("{path} is invalid utf8 {e}"))
87+
}
88+
8289
impl ShutterApplication {
8390
pub fn new(application_id: &str, flags: &gio::ApplicationFlags) -> Self {
8491
glib::Object::builder()
@@ -109,42 +116,18 @@ impl ShutterApplication {
109116
.issue_url("https://github.com/shutter-project/shutter/issues")
110117
.license_type(gtk::License::Gpl30)
111118
.artists(
112-
String::from_utf8(
113-
gio::resources_lookup_data(
114-
"/org/shutter-project/Shutter/credits/art",
115-
gio::ResourceLookupFlags::empty(),
116-
)
117-
.expect("no artist data")
118-
.to_vec(),
119-
)
120-
.expect("can't convert artists to utf8")
121-
.lines()
122-
.collect::<Vec<_>>(),
119+
load_string("/org/shutter-project/Shutter/credits/art")
120+
.lines()
121+
.collect::<Vec<_>>(),
123122
)
124123
.developers(
125-
String::from_utf8(
126-
gio::resources_lookup_data(
127-
"/org/shutter-project/Shutter/credits/dev",
128-
gio::ResourceLookupFlags::empty(),
129-
)
130-
.expect("no dev data")
131-
.to_vec(),
132-
)
133-
.expect("can't convert devs to utf8")
134-
.lines()
135-
.collect::<Vec<_>>(),
136-
)
137-
.copyright(
138-
String::from_utf8(
139-
gio::resources_lookup_data(
140-
"/org/shutter-project/Shutter/credits/copyright",
141-
gio::ResourceLookupFlags::empty(),
142-
)
143-
.expect("no copyright data")
144-
.to_vec(),
145-
)
146-
.expect("can't convert copyright to utf8"),
124+
load_string("/org/shutter-project/Shutter/credits/dev")
125+
.lines()
126+
.collect::<Vec<_>>(),
147127
)
128+
.copyright(load_string(
129+
"/org/shutter-project/Shutter/credits/copyright",
130+
))
148131
.build();
149132

150133
about.present(Some(&window));

0 commit comments

Comments
 (0)