Merge pull request #87 from matbme/main

Better internet connection error
main
Mirko Brombin 2 years ago committed by GitHub
commit d044c3e409
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -46,8 +46,18 @@
<property name="halign">center</property> <property name="halign">center</property>
<property name="valign">center</property> <property name="valign">center</property>
<style> <style>
<class name="pill" /> <class name="pill"/>
<class name="suggested-action" /> <class name="suggested-action"/>
</style>
</object>
</child>
<child>
<object class="GtkButton" id="btn_retry">
<property name="label">Retry</property>
<property name="halign">center</property>
<property name="visible">false</property>
<style>
<class name="pill"/>
</style> </style>
</object> </object>
</child> </child>
@ -57,8 +67,8 @@
<property name="halign">center</property> <property name="halign">center</property>
<property name="visible">false</property> <property name="visible">false</property>
<style> <style>
<class name="pill" /> <class name="pill"/>
<class name="suggested-action" /> <class name="suggested-action"/>
</style> </style>
</object> </object>
</child> </child>

@ -37,14 +37,14 @@ class Processor:
logger.info("processing the following commands: \n%s" % logger.info("processing the following commands: \n%s" %
'\n'.join(commands)) '\n'.join(commands))
# connection check # connection check
cn = subprocess.run(["wget", "-q", "--spider", "cloudflare.com"], cn = subprocess.run(["wget", "-q", "--spider", "cloudflare.com"],
stdout=subprocess.DEVNULL, stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL) stderr=subprocess.DEVNULL)
if cn.returncode != 0: if cn.returncode != 0:
logger.critical("No internet connection") logger.critical("No internet connection")
return False, "No internet connection." return False, "No internet connection.", True
# nextBoot commands are collected in ~/.local/org.vanillaos.FirstSetup.nextBoot # nextBoot commands are collected in ~/.local/org.vanillaos.FirstSetup.nextBoot
# and executed at the next boot by a desktop entry # and executed at the next boot by a desktop entry
@ -95,7 +95,7 @@ class Processor:
if command.startswith("!noSudo"): if command.startswith("!noSudo"):
command = command.replace("!noSudo", "sudo -u $USER") command = command.replace("!noSudo", "sudo -u $USER")
# outRun band is used to run a command outside of the main # outRun band is used to run a command outside of the main
# shell script. # shell script.
if command.startswith("!outRun"): if command.startswith("!outRun"):
@ -113,7 +113,7 @@ class Processor:
if "VANILLA_FAKE" in os.environ: if "VANILLA_FAKE" in os.environ:
logger.info("VANILLA_FAKE is set, skipping the commands") logger.info("VANILLA_FAKE is set, skipping the commands")
return True, "" return True, ""
cmd = ["pkexec", "sh", f.name] cmd = ["pkexec", "sh", f.name]
if abroot_bin := shutil.which("abroot"): if abroot_bin := shutil.which("abroot"):
cmd = ["pkexec", abroot_bin, "exec", "--assume-yes", "sh", f.name] cmd = ["pkexec", abroot_bin, "exec", "--assume-yes", "sh", f.name]
@ -133,7 +133,7 @@ class Processor:
logger.warning("failed to write to the log file: %s" % e) logger.warning("failed to write to the log file: %s" % e)
logger.warning("the output of the commands is: %s" % logger.warning("the output of the commands is: %s" %
out) out)
if proc.returncode != 0: if proc.returncode != 0:
logger.critical( logger.critical(
"Error while processing commands, see log for details.") "Error while processing commands, see log for details.")

@ -15,6 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
import subprocess import subprocess
from sys import intern
from gi.repository import Gtk, Adw from gi.repository import Gtk, Adw
@ -24,6 +25,7 @@ class VanillaDone(Adw.Bin):
status_page = Gtk.Template.Child() status_page = Gtk.Template.Child()
btn_reboot = Gtk.Template.Child() btn_reboot = Gtk.Template.Child()
btn_retry = Gtk.Template.Child()
btn_close = Gtk.Template.Child() btn_close = Gtk.Template.Child()
log_box = Gtk.Template.Child() log_box = Gtk.Template.Child()
log_output = Gtk.Template.Child() log_output = Gtk.Template.Child()
@ -33,7 +35,7 @@ class VanillaDone(Adw.Bin):
self.__window = window self.__window = window
self.__fail_title = fail_title self.__fail_title = fail_title
self.__fail_description = fail_description self.__fail_description = fail_description
if not title and not description: if not title and not description:
self.status_page.set_description( self.status_page.set_description(
_("Restart your device to enjoy your {} experience.").format( _("Restart your device to enjoy your {} experience.").format(
@ -49,16 +51,29 @@ class VanillaDone(Adw.Bin):
else: else:
self.btn_reboot.set_visible(False) self.btn_reboot.set_visible(False)
self.btn_close.set_visible(True) self.btn_close.set_visible(True)
self.btn_close.connect("clicked", self.__on_close_clicked) self.btn_close.connect("clicked", self.__on_close_clicked)
self.btn_retry.connect("clicked", self.__on_retry_clicked)
def set_result(self, result): def set_result(self, result):
res, msg = result res, msg, *internet_fail = result
# Default to false if internet_fail wasn't passed with result
internet_fail = internet_fail[0] if len(internet_fail) > 0 else False
if res: if res:
return return
self.status_page.set_icon_name("dialog-error-symbolic") if internet_fail:
if not self.__fail_title and not self.__fail_description: self.status_page.set_icon_name("network-offline-symbolic")
else:
self.status_page.set_icon_name("dialog-error-symbolic")
if internet_fail:
self.status_page.set_title(_("No internet connection"))
self.status_page.set_description(_("Please ensure your system is connected to the internet and try again."))
self.log_box.set_visible(False)
elif not self.__fail_title and not self.__fail_description:
self.status_page.set_title(_("Something went wrong")) self.status_page.set_title(_("Something went wrong"))
self.status_page.set_description(_("Please contact the distribution developers.")) self.status_page.set_description(_("Please contact the distribution developers."))
self.log_box.set_visible(True) self.log_box.set_visible(True)
@ -67,11 +82,20 @@ class VanillaDone(Adw.Bin):
self.status_page.set_title(self.__fail_title) self.status_page.set_title(self.__fail_title)
self.status_page.set_description(self.__fail_description) self.status_page.set_description(self.__fail_description)
self.log_box.set_visible(False) self.log_box.set_visible(False)
self.btn_reboot.set_visible(False) self.btn_reboot.set_visible(False)
self.btn_close.set_visible(True) if internet_fail:
self.btn_retry.set_visible(True)
self.btn_close.set_visible(False)
else:
self.btn_retry.set_visible(False)
self.btn_close.set_visible(True)
def __on_reboot_clicked(self, button): def __on_reboot_clicked(self, button):
subprocess.run(['gnome-session-quit', '--reboot']) subprocess.run(['gnome-session-quit', '--reboot'])
def __on_close_clicked(self, button): def __on_close_clicked(self, button):
self.__window.close() self.__window.close()
def __on_retry_clicked(self, button):
self.__window.back()

@ -63,7 +63,7 @@ class VanillaWindow(Adw.ApplicationWindow):
self.__init_mode = 1 self.__init_mode = 1
# system views # system views
self.__view_done = VanillaDone(self, reboot=False, self.__view_done = VanillaDone(self, reboot=False,
title=_("Done!"), description=_("Your device is ready to use."), title=_("Done!"), description=_("Your device is ready to use."),
fail_title=_("Error!"), fail_description=_("Something went wrong.")) fail_title=_("Error!"), fail_description=_("Something went wrong."))
@ -95,7 +95,7 @@ class VanillaWindow(Adw.ApplicationWindow):
self.carousel.append(self.__view_post_script) self.carousel.append(self.__view_post_script)
self.carousel.append(self.__view_done) self.carousel.append(self.__view_done)
@property @property
def builder(self): def builder(self):
return self.__builder return self.__builder
@ -130,11 +130,11 @@ class VanillaWindow(Adw.ApplicationWindow):
if self.__init_mode == 0: if self.__init_mode == 0:
self.__view_done.set_result(result) self.__view_done.set_result(result)
self.next() self.next()
pages_check = [self.__view_done] pages_check = [self.__view_done]
if self.__init_mode == 0: if self.__init_mode == 0:
pages_check.append(self.__view_progress) pages_check.append(self.__view_progress)
cur_index = self.carousel.get_position() cur_index = self.carousel.get_position()
page = self.carousel.get_nth_page(cur_index) page = self.carousel.get_nth_page(cur_index)
with contextlib.suppress(AttributeError): with contextlib.suppress(AttributeError):
@ -181,7 +181,7 @@ class VanillaWindow(Adw.ApplicationWindow):
cur_index = self.carousel.get_position() cur_index = self.carousel.get_position()
page = self.carousel.get_nth_page(cur_index - 1) page = self.carousel.get_nth_page(cur_index - 1)
self.carousel.scroll_to(page, True) self.carousel.scroll_to(page, True)
def toast(self, message, timeout=3): def toast(self, message, timeout=3):
toast = Adw.Toast.new(message) toast = Adw.Toast.new(message)
toast.props.timeout = timeout toast.props.timeout = timeout

Loading…
Cancel
Save