From 674a8ee7255d8cabf162e976e9afedab4072f272 Mon Sep 17 00:00:00 2001 From: sergiotarxz Date: Sat, 13 Jul 2024 03:38:35 +0200 Subject: [PATCH] Committing missing file. --- lib/JapaChar/Accessibility.pm | 52 +++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 lib/JapaChar/Accessibility.pm diff --git a/lib/JapaChar/Accessibility.pm b/lib/JapaChar/Accessibility.pm new file mode 100644 index 0000000..0fd2b00 --- /dev/null +++ b/lib/JapaChar/Accessibility.pm @@ -0,0 +1,52 @@ +package JapaChar::Accessibility; + +use v5.38.2; + +use strict; +use warnings; + +use Moo; + +require JapaChar::Schema; + +my $option_name = 'accessibility-mode'; +my $dyslexia = 'dyslexia'; +my $remove_assisted_mode = 'remove-assisted-mode'; + +has app => (is => 'ro'); + +sub _current_mode($self) { + my ($result) = JapaChar::Schema->Schema->resultset('Option')->search({ name => $option_name }); + my $return = ''; + if (defined $result) { + $return = $result->value; + } + return $return; +} + +sub is_dyslexia($self) { + return $self->_current_mode eq $dyslexia; +} + +sub show_assisted_mode_selection($self) { + my $dialog = Adw::AlertDialog->new( 'Select assisted mode', + 'If you feel you are not progressing as well as you could try one of these, do not take one of them working for you as a diagnosis.' ); + $dialog->add_response( $dyslexia, 'Dyslexia' ); + $dialog->add_response( $remove_assisted_mode, 'Remove accessibility' ); + $dialog->signal_connect( + 'response', + sub( $obj, $response ) { + $self->_on_assisted_mode_selection_response( $response ); + } + ); + $self->app->present_dialog($dialog); + return $dialog; +} + +sub _on_assisted_mode_selection_response( $self, $response ) { + if (!defined $response) { + die 'Accessibility mode invalid'; + } + my ($result) = JapaChar::Schema->Schema->resultset('Option')->update_or_create({ name => $option_name, value => $response }); +} +1;