~fnux/pisk

c720b527b58e70067670ee68d8cdf76d037caecc — Timothée Floure 2 years ago 0d327b1
Catch errors from user-requested udisks2 actions
1 files changed, 19 insertions(+), 4 deletions(-)

M disks.pl
M disks.pl => disks.pl +19 -4
@@ 310,6 310,17 @@ sub define_curses_bindings {

### Main logic

sub handle_udisks2_action {
	my ($cui, $action, $device) = @_;

	my $action_result = eval { $action->(); };
	if ( not $action_result ) {
		# FIXME: Handle error stored in $@
	}

	return;
}

sub handle_listbox_event {
	my ($cui, $udisks2, $listbox, $listbox_values, $listbox_labels) = @_;



@@ 399,15 410,19 @@ sub handle_listbox_event {
	# Handle actions
	given ($action) {
		when (/^mount$/) {
			mount_filesystem($device);
			handle_udisks2_action($cui, sub { mount_filesystem($device) });
			refresh_listbox_content($udisks2, $listbox_values, $listbox_labels);
		}
		when (/^unmount$/) {
			unmount_filesystem($device);
			handle_udisks2_action($cui, sub { unmount_filesystem($device) });
			refresh_listbox_content($udisks2, $listbox_values, $listbox_labels);
		}
		when (/^swapon$/) { active_swapspace($device); }
		when (/^swapoff$/) { disable_swapspace($device); }
		when (/^swapon$/) {
			handle_udisks2_action($cui, sub { active_swapspace($device) });
		}
		when (/^swapoff$/) {
			handle_udisks2_action($cui, sub { disable_swapspace($device) });
		}
	}

	# Refresh focus and selection