Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ubuntu 24.04 #7

Merged
merged 13 commits into from
Aug 4, 2024
28 changes: 16 additions & 12 deletions src/grub-reboot-picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
from gi.repository import Gtk, AppIndicator3


SHOW_GRUB_MENU_SUB_MENUS = True
DEVELOPMENT_MODE = False
SHOW_GRUB_MENU_SUB_MENUS = False
DEVELOPMENT_MODE = True
mendhak marked this conversation as resolved.
Show resolved Hide resolved
GRUB_CONFIG_PATH = "/boot/grub/grub.cfg"
if DEVELOPMENT_MODE:
GRUB_CONFIG_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), "grub.cfg")

icon_name = "un-reboot"

Expand All @@ -35,7 +38,7 @@ def get_grub_entries():
grub_entries.clear()
grub_entries['menuitems'] = []

for i, line in enumerate(open('/boot/grub/grub.cfg')):
for i, line in enumerate(open(GRUB_CONFIG_PATH)):
for match in re.finditer(pattern, line):
grub_entry = {}
grub_entry['name'] = match.group(1)
Expand Down Expand Up @@ -89,7 +92,7 @@ def get_grub_entries_with_submenus():
current_submenu = None
submenu_entry_match = None

for i, line in enumerate(open('/boot/grub/grub.cfg')):
for i, line in enumerate(open(GRUB_CONFIG_PATH)):
menu_entry_match = re.match(menu_pattern, line)
if menu_entry_match:
grub_entry = {}
Expand Down Expand Up @@ -130,14 +133,15 @@ def build_menu():
menuitem = Gtk.MenuItem(label=grub_entry['name'])
if len(grub_entry.get('submenuitems', [])) == 0:
menuitem.connect('activate', do_grub_reboot, grub_entry)
submenu = Gtk.Menu()
for grub_entry_submenuitem in grub_entry.get('submenuitems', []):
# print(grub_entry_submenuitem)
submenu_item = Gtk.MenuItem(label=grub_entry_submenuitem['name'])
submenu_item.connect('activate', do_grub_reboot, grub_entry_submenuitem,
grub_entry)
submenu.append(submenu_item)
menuitem.set_submenu(submenu)
else:
submenu = Gtk.Menu()
for grub_entry_submenuitem in grub_entry.get('submenuitems', []):
# print(grub_entry_submenuitem)
submenu_item = Gtk.MenuItem(label=grub_entry_submenuitem['name'])
submenu_item.connect('activate', do_grub_reboot, grub_entry_submenuitem,
grub_entry)
submenu.append(submenu_item)
menuitem.set_submenu(submenu)

menu.append(menuitem)

Expand Down
Loading