TSK Manager v0.10.0
This commit is contained in:
@@ -0,0 +1,136 @@
|
||||
# tsk/reboot_menu/actions.py
|
||||
import os
|
||||
import shutil
|
||||
import sys # Import the sys module
|
||||
|
||||
from tsk.common.env import is_agnos, RECOMMENDED_OP_USER, RECOMMENDED_OP_BRANCH, RECOMMENDED_OP_DIR, ALTERNATE_OP_USER, \
|
||||
ALTERNATE_OP_BRANCH, ALTERNATE_OP_DIR
|
||||
from tsk.common.key_file_manager import KeyFileManager
|
||||
from tsk.ui.dialog import YesNoDialog
|
||||
|
||||
|
||||
class Rebooter:
|
||||
# Actions based on launch_chffrplus.sh
|
||||
# Reboot is handled in that sh
|
||||
|
||||
CONTINUE_FILE = "/data/continue.sh"
|
||||
OPENPILOT_DIR = "/data/openpilot"
|
||||
|
||||
def __init__(self):
|
||||
self.is_agnos: bool = is_agnos()
|
||||
|
||||
def recommended_action(self):
|
||||
print("Recommended button pressed")
|
||||
key = KeyFileManager().installed_key
|
||||
if key:
|
||||
question = f"Key installed: {key}\n\n"
|
||||
else:
|
||||
question = "!!!! Key not installed.\n" \
|
||||
"!!!! Comma can't drive your car.\n\n"
|
||||
question += f"Reboot and install {RECOMMENDED_OP_USER}/{RECOMMENDED_OP_BRANCH}?"
|
||||
should_reboot = YesNoDialog.ask(question)
|
||||
if not should_reboot:
|
||||
print("Action cancelled")
|
||||
return
|
||||
print("Action confirmed")
|
||||
|
||||
# Remove /data/openpilot
|
||||
if self.is_agnos:
|
||||
shutil.rmtree(self.OPENPILOT_DIR, ignore_errors=True)
|
||||
print(f"Removed {self.OPENPILOT_DIR}")
|
||||
|
||||
# Remove /data/tsk-alternate
|
||||
if self.is_agnos:
|
||||
shutil.rmtree(ALTERNATE_OP_DIR, ignore_errors=True)
|
||||
print(f"Removed {ALTERNATE_OP_DIR}")
|
||||
|
||||
# Move /data/tsk-recommended to /data/openpilot
|
||||
if self.is_agnos:
|
||||
shutil.move(RECOMMENDED_OP_DIR, self.OPENPILOT_DIR)
|
||||
print(f"Moved {RECOMMENDED_OP_DIR} to {self.OPENPILOT_DIR}")
|
||||
|
||||
sys.exit(0)
|
||||
|
||||
def alternate_action(self):
|
||||
print("Alternate button pressed")
|
||||
key = KeyFileManager().installed_key
|
||||
if key:
|
||||
question = f"Key installed: {key}\n\n"
|
||||
else:
|
||||
question = "!!!! Key not installed.\n" \
|
||||
"!!!! Comma can't drive your car.\n\n"
|
||||
question += f"Reboot and install {ALTERNATE_OP_USER}/{ALTERNATE_OP_BRANCH}?"
|
||||
should_reboot = YesNoDialog.ask(question)
|
||||
if not should_reboot:
|
||||
print("Action cancelled")
|
||||
return
|
||||
print("Action confirmed")
|
||||
|
||||
# Remove /data/openpilot
|
||||
if self.is_agnos:
|
||||
shutil.rmtree(self.OPENPILOT_DIR, ignore_errors=True)
|
||||
print(f"Removed {self.OPENPILOT_DIR}")
|
||||
|
||||
# Remove /data/tsk-recommended
|
||||
if self.is_agnos:
|
||||
shutil.rmtree(RECOMMENDED_OP_DIR, ignore_errors=True)
|
||||
print(f"Removed {RECOMMENDED_OP_DIR}")
|
||||
|
||||
# Move /data/tsk-alternate to /data/openpilot
|
||||
if self.is_agnos:
|
||||
shutil.move(ALTERNATE_OP_DIR, self.OPENPILOT_DIR)
|
||||
print(f"Moved {ALTERNATE_OP_DIR} to {self.OPENPILOT_DIR}")
|
||||
|
||||
sys.exit(0)
|
||||
|
||||
def bail_action(self):
|
||||
print("Bail button pressed")
|
||||
key = KeyFileManager().installed_key
|
||||
if key:
|
||||
question = f"Key installed: {key}\n\n"
|
||||
else:
|
||||
question = "!!!! Key not installed.\n" \
|
||||
"!!!! Comma can't drive your car.\n\n"
|
||||
question += "Reboot and install a different fork/branch?"
|
||||
should_reboot = YesNoDialog.ask(question)
|
||||
if not should_reboot:
|
||||
print("Action cancelled")
|
||||
return
|
||||
print("Action confirmed")
|
||||
|
||||
# Remove /data/tsk-recommended since it won't be used
|
||||
if self.is_agnos:
|
||||
shutil.rmtree(RECOMMENDED_OP_DIR, ignore_errors=True)
|
||||
print(f"Removed {RECOMMENDED_OP_DIR}")
|
||||
|
||||
# Remove /data/tsk-alternate since it won't be used
|
||||
if self.is_agnos:
|
||||
shutil.rmtree(ALTERNATE_OP_DIR, ignore_errors=True)
|
||||
print(f"Removed {ALTERNATE_OP_DIR}")
|
||||
|
||||
# /data/openpilot is deleted by the installer
|
||||
|
||||
# Delete /data/continue.sh to trigger an installer without a reset
|
||||
if self.is_agnos:
|
||||
if os.path.exists(self.CONTINUE_FILE):
|
||||
os.remove(self.CONTINUE_FILE)
|
||||
print(f"Removed {self.CONTINUE_FILE}")
|
||||
|
||||
sys.exit(0)
|
||||
|
||||
def retry_action(self):
|
||||
print("Retry button pressed")
|
||||
key = KeyFileManager().installed_key
|
||||
if key:
|
||||
question = f"Key installed: {key}\n\n"
|
||||
else:
|
||||
question = "!!!! Key not installed.\n\n"
|
||||
question += "Reboot without changing anything?"
|
||||
should_reboot = YesNoDialog.ask(question)
|
||||
if not should_reboot:
|
||||
print("Action cancelled")
|
||||
return
|
||||
print("Action confirmed")
|
||||
|
||||
# Do nothing
|
||||
sys.exit(0)
|
||||
@@ -0,0 +1,72 @@
|
||||
# tsk/reboot_menu/ui.py
|
||||
import pyray as rl
|
||||
from openpilot.system.ui.lib.application import gui_app
|
||||
|
||||
from tsk.common.env import RECOMMENDED_OP_USER, RECOMMENDED_OP_BRANCH, ALTERNATE_OP_USER, ALTERNATE_OP_BRANCH
|
||||
from tsk.reboot_menu.actions import Rebooter # Import the class
|
||||
from tsk.ui.button import Button
|
||||
from tsk.ui.header import Header
|
||||
from tsk.ui.layout import Layout, Theme # Import Theme
|
||||
|
||||
|
||||
class RebootMenuUI:
|
||||
"""Manages the Restart Menu and its state."""
|
||||
|
||||
def __init__(self):
|
||||
self.rebooter = Rebooter() # Create an instance here
|
||||
|
||||
self.header = Header()
|
||||
header_height = self.header._calculate_height()
|
||||
key_status_height = Theme.key_status_font_size * 1.5 # Approximate height
|
||||
combined_header_height = header_height + key_status_height
|
||||
|
||||
rect = rl.Rectangle(0, 0, gui_app.width, gui_app.height) # Dummy rectangle for initial calculations
|
||||
# Calculate button height using the same function as in tools.py
|
||||
button_height = Layout.calculate_button_dimensions(rect.height, combined_header_height)
|
||||
|
||||
# Calculate start_y to position the buttons correctly
|
||||
start_x, start_y = Layout.calculate_button_positions(rect, combined_header_height, 3)
|
||||
|
||||
# Button positions
|
||||
button1_x = start_x
|
||||
button2_x = start_x + 600 + 80
|
||||
button3_x = start_x + 2 * (600 + 80)
|
||||
|
||||
button_y = start_y
|
||||
|
||||
self.recommended_button = Button(self.rebooter.recommended_action, [ # Call the method on the instance
|
||||
{"text": "Install", "x_offset": 70, "y_offset": 40},
|
||||
{"text": f"{RECOMMENDED_OP_USER}/", "x_offset": 70, "y_offset": 140},
|
||||
{"text": f"{RECOMMENDED_OP_BRANCH}", "x_offset": 70, "y_offset": 240},
|
||||
], 600, button_height, button1_x, button_y, 90)
|
||||
|
||||
self.alternate_button = Button(self.rebooter.alternate_action, [ # Call the method on the instance
|
||||
{"text": "Install", "x_offset": 70, "y_offset": 40},
|
||||
{"text": f"{ALTERNATE_OP_USER}/", "x_offset": 70, "y_offset": 140},
|
||||
{"text": f"{ALTERNATE_OP_BRANCH}", "x_offset": 70, "y_offset": 240},
|
||||
], 600, button_height, button2_x, button_y, 90)
|
||||
|
||||
self.bail_button = Button(self.rebooter.bail_action, [ # Call the method on the instance
|
||||
{"text": "Install a", "x_offset": 70, "y_offset": 40},
|
||||
{"text": "different", "x_offset": 70, "y_offset": 140},
|
||||
{"text": "fork/branch", "x_offset": 70, "y_offset": 240},
|
||||
], 600, button_height, button3_x, button_y, 90)
|
||||
|
||||
# Add the "Retry" button
|
||||
retry_button_width = 3 * 600 + 2 * 80
|
||||
retry_button_x = (rect.width - retry_button_width) / 2 + rect.x
|
||||
retry_button_y = button_y + button_height + 80
|
||||
|
||||
self.retry_button = Button(self.rebooter.retry_action, [ # Call the method on the instance
|
||||
{"text": "Reboot to try again",
|
||||
"x_offset": (retry_button_width - rl.measure_text_ex(gui_app.font(), "Reboot to try again", 90, 1.0).x) / 2,
|
||||
"y_offset": 60},
|
||||
], retry_button_width, 200, retry_button_x, retry_button_y, 90)
|
||||
|
||||
def render(self, rect: rl.Rectangle):
|
||||
"""Renders the Restart Menu."""
|
||||
|
||||
self.recommended_button.render()
|
||||
self.alternate_button.render()
|
||||
self.bail_button.render()
|
||||
self.retry_button.render()
|
||||
Reference in New Issue
Block a user