Skip to content

Commit

Permalink
feat:[#323] Skip reboot if unnecessary
Browse files Browse the repository at this point in the history
- default no-prompt logout
- add reboot_condition to recipe
- add set_reboot function that sets message and buttons
  • Loading branch information
jardon committed Sep 30, 2024
1 parent dfe079e commit 892c3b0
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 12 deletions.
3 changes: 2 additions & 1 deletion recipe.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -614,5 +614,6 @@
}
]
}
}
},
"reboot_condition": "false"
}
3 changes: 2 additions & 1 deletion recipe.json
Original file line number Diff line number Diff line change
Expand Up @@ -583,5 +583,6 @@
}
]
}
}
},
"reboot_condition": "false"
}
4 changes: 2 additions & 2 deletions vanilla_first_setup/gtk/done.ui
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<object class="AdwStatusPage" id="status_page">
<property name="icon-name">emblem-default-symbolic</property>
<property name="title" translatable="yes">Finished!</property>
<property name="description" translatable="yes">Restart your device to enjoy your Vanilla OS experience</property>
<property name="description" translatable="yes">You're ready to start experiencing Vanilla OS.</property>
<property name="halign">fill</property>
<property name="valign">fill</property>
<property name="hexpand">true</property>
Expand Down Expand Up @@ -63,7 +63,7 @@
</child>
<child>
<object class="GtkButton" id="btn_close">
<property name="label">Close</property>
<property name="label">Get Started</property>
<property name="halign">center</property>
<property name="visible">false</property>
<style>
Expand Down
29 changes: 22 additions & 7 deletions vanilla_first_setup/views/done.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class VanillaDone(Adw.Bin):
def __init__(
self,
window,
reboot: bool = True,
title: str = "",
description: str = "",
fail_title: str = "",
Expand All @@ -52,22 +51,36 @@ def __init__(

if not title and not description:
self.status_page.set_description(
_("Restart your device to enjoy your {} experience.").format(
_("You're ready to start experiencing {}.").format(
self.__window.recipe["distro_name"]
)
)
else:
self.status_page.set_title(title)
self.status_page.set_description(description)

if reboot:
self.btn_reboot.connect("clicked", self.__on_reboot_clicked)
else:
self.btn_reboot.set_visible(False)
self.btn_close.set_visible(True)
self.btn_reboot.set_visible(False)
self.btn_close.set_visible(True)

self.btn_close.connect("clicked", self.__on_close_clicked)
self.btn_retry.connect("clicked", self.__on_retry_clicked)
self.btn_reboot.connect("clicked", self.__on_reboot_clicked)

def set_reboot(self):
recipe = RecipeLoader()
if recipe.raw.get("reboot_condition"):
condition = subprocess.run(recipe.raw["reboot_condition"].split())
if condition.returncode == 0:
self.status_page.set_description(
("Restart your device to enjoy your {} experience.").format(
self.__window.recipe["distro_name"]
)
)
self.btn_reboot.set_visible(True)
self.btn_close.set_visible(False)
else:
self.btn_reboot.set_visible(False)
self.btn_close.set_visible(True)

def set_result(self, result, terminal=None):
out = terminal.get_text()[0] if terminal else ""
Expand Down Expand Up @@ -95,6 +108,8 @@ def __on_close_clicked(self, *args):
[recipe.raw["tour_app"]],
flags=GLib.SpawnFlags.SEARCH_PATH,
)
else:
subprocess.run(["gnome-session-quit", "--no-prompt"])

self.__window.close()

Expand Down
2 changes: 1 addition & 1 deletion vanilla_first_setup/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ def __init__(self, post_script: str, user: str, new_user: bool = False, **kwargs
# system views
self.__view_done = VanillaDone(
self,
reboot=False,
title=_("Done!"),
description=_("Your device is ready to use."),
fail_title=_("Error!"),
Expand Down Expand Up @@ -167,6 +166,7 @@ def __on_page_changed(self, *args):

# keep the btn_back button locked if this is the last page
if page == self.__view_done:
self.__view_done.set_reboot()
return

# collect all the finals
Expand Down

0 comments on commit 892c3b0

Please sign in to comment.