Skip to content

Commit

Permalink
Refrain from disrupting the power button (#239)
Browse files Browse the repository at this point in the history
* Refrain from disrupting the power button

* Hiding the home button in gui mode as well
  • Loading branch information
skarbat authored Jun 13, 2017
1 parent c79d61d commit 991673e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 24 deletions.
30 changes: 23 additions & 7 deletions bin/kano-updater
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ from kano_updater.utils import make_low_prio, install_docopt, is_running, \
import kano_updater.priority as Priority


# Keep a global status of wether we are working in GUI or console mode
gui_mode=False


def sigterm_on_download(signo, frame):
status = UpdaterStatus.get_instance()
if status.state == UpdaterStatus.DOWNLOADING_UPDATES:
Expand All @@ -82,6 +86,8 @@ def sigterm_on_download(signo, frame):


def clean_up():
global gui_mode

status = UpdaterStatus.get_instance()
status.notifications_muted = False
status.save()
Expand All @@ -91,11 +97,12 @@ def clean_up():

remove_pid_file()

# Restore the home button only if we are on Desktop mode
run_bg('systemctl --user status kano-desktop && /usr/bin/kano-home-button-visible yes')
if gui_mode:
# Restore the home button only if we are on Desktop mode
run_bg('systemctl --user status kano-desktop && /usr/bin/kano-home-button-visible yes')

# Enable any hardware power button.
enable_power_button()
# Enable any hardware power button.
enable_power_button()


def schedule_install(gui=False, confirm=True, splash_pid=None):
Expand Down Expand Up @@ -162,19 +169,28 @@ def run_install_ind_pkg(package):


def main():

global gui_mode

msg = _('Administrator priviledges are required to perform this operation')
enforce_root(u"{}: {}".format(_('ERROR'), msg))

# Disable any hardware power button.
disable_power_button()

# docopt wasn't installed by default prior Kano OS 1.3.3
# It needs to be installed to make sure the updater runs
install_docopt()
import docopt

args = docopt.docopt(__doc__, version=str(TARGET_VERSION))

gui_mode = args['--gui']

if gui_mode:
# Hide the home button only if we are on Desktop mode
run_bg('systemctl --user status kano-desktop && /usr/bin/kano-home-button-visible no')

# Disable any hardware power button.
disable_power_button()

# We always want to keep the logs from updates
logger.force_log_level('info')

Expand Down
26 changes: 9 additions & 17 deletions kano_updater/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,38 +648,30 @@ def show_kano_dialog(title, description, buttons, blocking=True):

return retval


def enable_power_button():
def set_power_button(enabled):
"""
Enables any power button that might be attached via a Kano hat.
Enables or disables any power button that might be attached via a Kano hat.
This is for when we return to the OS and not reboot / shutdown.
"""
try:
pihat_iface = get_pihat_interface()
if pihat_iface:
pihat_iface.set_power_button_enabled(True)
pihat_iface.set_power_button_enabled(enabled)

pro_hat_iface = get_ck2_pro_hat_interface()
if pro_hat_iface:
pro_hat_iface.set_power_button_enabled(True)
pro_hat_iface.set_power_button_enabled(enabled)
except Exception:
# Kano Peripherals doesn't support this function
pass


def disable_power_button():
""" Disables any power button that might be attached via a Kano hat """
try:
pihat_iface = get_pihat_interface()
if pihat_iface:
pihat_iface.set_power_button_enabled(False)
def enable_power_button():
set_power_button(True)

pro_hat_iface = get_ck2_pro_hat_interface()
if pro_hat_iface:
pro_hat_iface.set_power_button_enabled(False)
except Exception:
# Kano Peripherals doesn't support this function
pass

def disable_power_button():
set_power_button(False)


def verify_kit_is_plugged():
Expand Down

0 comments on commit 991673e

Please sign in to comment.