Verified Commit 5e4ef4f6 authored by Rasmus Thomsen's avatar Rasmus Thomsen
Browse files

fix(tree-wide): make sure clone! calls aren't too long

parent 7fcc4f06
Pipeline #313690 failed with stages
in 32 minutes and 15 seconds
......@@ -37,10 +37,10 @@ while IFS= read -r line; do
# It would be `2` since 3 is the minimum we want to trigger but
# we have to account for the fact that there is an opening line
# and a closing line
if [ $clonelines -gt 5 ]; then
if [ $clonelines -gt 9 ]; then
# Easier than adding '>&2' to every single call
(
printf "clone! in line %s to %s is too long (%s lines)!\\n" \
printf "clone! in $1:%s to %s is too long (%s lines)!\\n" \
"$clonestartline" $linenum $((clonelines - 2))
printf -- '```rust\n'
sed -n "$clonestartline,${linenum}p" "$1"
......
......@@ -151,6 +151,35 @@ impl SyncListBox {
imp::SyncListBox::from_instance(self)
}
fn handle_db_receiver_received(&self, res: Result<()>) -> glib::Continue {
let self_ = self.imp();
if let Err(e) = res {
self_
.google_fit_selected_image
.set_icon_name(Some("network-error-symbolic"));
self_.google_fit_selected_image.set_visible(true);
self_.google_fit_spinner.set_spinning(false);
self_
.google_fit_stack
.set_visible_child(&self_.google_fit_selected_image.get());
self.open_sync_error(&e.to_string());
} else {
let obj = self.clone();
spawn!(async move {
let self_ = obj.imp();
self_.google_fit_selected_image.set_visible(true);
self_.google_fit_spinner.set_spinning(false);
self_
.google_fit_stack
.set_visible_child(&self_.google_fit_selected_image.get());
});
}
self_.google_fit_start_sync_row.set_activatable(false);
glib::Continue(false)
}
fn handle_row_activated(self, row: &gtk::ListBoxRow) {
let self_ = self.imp();
if row == &self_.google_fit_start_sync_row.get() {
......@@ -166,28 +195,12 @@ impl SyncListBox {
glib::MainContext::channel::<Result<()>>(glib::PRIORITY_DEFAULT);
let db_sender = new_db_receiver();
receiver.attach(None, clone!(@weak self as obj => @default-panic, move |res| {
let self_ = obj.imp();
if let Err(e) = res {
self_.google_fit_selected_image.set_icon_name(Some("network-error-symbolic"));
self_.google_fit_selected_image.set_visible(true);
self_.google_fit_spinner.set_spinning(false);
self_.google_fit_stack.set_visible_child(&self_.google_fit_selected_image.get());
obj.open_sync_error(&e.to_string());
} else {
let obj = obj.clone();
spawn!(async move {
let self_ = obj.imp();
self_.google_fit_selected_image.set_visible(true);
self_.google_fit_spinner.set_spinning(false);
self_.google_fit_stack.set_visible_child(&self_.google_fit_selected_image.get());
});
}
self_.google_fit_start_sync_row.set_activatable(false);
glib::Continue(false)
}));
receiver.attach(
None,
clone!(@weak self as obj => @default-panic, move |res| {
obj.handle_db_receiver_received(res)
}),
);
std::thread::spawn(move || {
let mut sync_provider = GoogleFitSyncProvider::new(db_sender);
......
......@@ -341,6 +341,17 @@ impl Window {
);
}
fn handle_sync_data_error_received(&self, err_opt: Option<anyhow::Error>) -> glib::Continue {
if let Some(e) = err_opt {
self.show_error(&i18n_f(
"Couldn't sync Google Fit data due to error: {}",
&[&e.to_string()],
));
}
glib::Continue(false)
}
/// Display an error in a non-intrusive way.
fn show_error(&self, err_msg: &str) {
let self_ = self.imp();
......@@ -360,14 +371,7 @@ impl Window {
receiver.attach(
None,
clone!(@weak self as obj => @default-panic, move |v: Option<anyhow::Error>| {
if let Some(e) = v {
obj.show_error(&i18n_f(
"Couldn't sync Google Fit data due to error: {}",
&[&e.to_string()],
));
}
glib::Continue(false)
obj.handle_sync_data_error_received(v)
}),
);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment