Use separate tweak menus for clients and servers

Former-commit-id: 92a7ce68f150aa223bc5a78ba02dd7cb7c07317d
Former-commit-id: 838381c35f3fec2a8780772bef8fcac33e7baac1
This commit is contained in:
2023-06-08 14:46:47 -04:00
parent 8474807cd4
commit 93bffe2587
2 changed files with 63 additions and 63 deletions
+3 -5
View File
@@ -829,10 +829,9 @@ if __name__ == "__main__":
read_shortcut() read_shortcut()
elif arguments[0] == 'tweak': elif arguments[0] == 'tweak':
success_flag = True success_flag = True
from stweak import menu_repeat from stweak import global_menu
menu_repeat(False) global_menu(device_type, 'configuration options:')
# PORT START ARGS-SERVER
# server arguments # server arguments
else: else:
if arg_count < 1: if arg_count < 1:
@@ -848,11 +847,10 @@ if __name__ == "__main__":
elif arg_count == 1 and arguments[0] == 'tweak': elif arg_count == 1 and arguments[0] == 'tweak':
success_flag = True success_flag = True
from stweak import global_menu from stweak import global_menu
global_menu(False) global_menu(device_type, 'configuration options:')
elif arg_count > 2 and arguments[1] in ('add', 'del'): elif arg_count > 2 and arguments[1] in ('add', 'del'):
success_flag = True success_flag = True
whitelist_manage(arguments[2]) whitelist_manage(arguments[2])
# PORT END ARGS-SERVER
if arg_count > 0 and success_flag == 0 and arguments[0] != 'sync': if arg_count > 0 and success_flag == 0 and arguments[0] != 'sync':
if device_type == 'client' and arguments[0] not in ('help', '-h', 'version', '-v', 'license'): if device_type == 'client' and arguments[0] not in ('help', '-h', 'version', '-v', 'license'):
+60 -58
View File
@@ -230,66 +230,68 @@ def quick_unlock_config(_default):
return _enabled return _enabled
# continually shows the tweak menu after each change until the user manually exits
def menu_repeat(_post_setup):
while True:
if global_menu(_post_setup):
break
# runs secondary configuration menu # runs secondary configuration menu
def global_menu(_post_setup): def global_menu(_device_type, _top_message):
# curses initialization while True:
noecho() # curses initialization
cbreak() noecho()
stdscr.keypad(True) cbreak()
stdscr.keypad(True)
_options, _choice, _term_message, _return_val = [], 4, False, False _options, _choice, _term_message, _exit_signal = ['change device/synchronization types'], 0, False, False
try: try:
if not _post_setup: if _device_type == 'client':
_options.extend(['change device/synchronization types', 'change gpg key', 're-configure ssh(ync)', _options.extend(['change gpg key', 're-configure ssh(ync)', 'change device name',
'change device name']) '[OPTIONAL, RECOMMENDED] set custom text editor',
_message, _choice = 'all configuration options:', 0 '[OPTIONAL, RECOMMENDED] enable/disable quick-unlock', '[OPTIONAL, NOT IMPLEMENTED] su security mode',
_options.extend(['[OPTIONAL, RECOMMENDED] set custom text editor', '[OPTIONAL, NOT IMPLEMENTED] extensions and updates'])
'[OPTIONAL, RECOMMENDED] enable/disable quick-unlock', else:
'[OPTIONAL, NOT IMPLEMENTED] su security mode', _options.extend(['manage quick-unlock'])
'[OPTIONAL, NOT IMPLEMENTED] extensions and updates', 'exit/done']) _options.extend(['exit/done'])
_message = 'required configuration complete - additional configuration options:' _choice += curses_radio(_options, _top_message)
_choice += curses_radio(_options, _message)
if _choice == 0: if _choice == 0:
_dev_sync_types = install_type() _dev_sync_types = install_type()
# if not running in server or offline mode and a sshync config has not been made # if not running in server or offline mode and a sshync config has not been made
if _dev_sync_types[0] != 'server' and _dev_sync_types[1] != 'true' and not sshyp_data.has_section('SSHYNC'): if _dev_sync_types[0] != 'server' and _dev_sync_types[1] != 'true' and not sshyp_data.has_section('SSHYNC'):
_ip, _username_ssh, _port = ssh_config() _ip, _username_ssh, _port = ssh_config()
# if no device id is set # if no device id is set
if not listdir(f"{home}/.config/sshyp/devices"): if not listdir(f"{home}/.config/sshyp/devices"):
dev_id_config(_ip, _username_ssh, _port) dev_id_config(_ip, _username_ssh, _port)
elif _choice == 1: _device_type = _dev_sync_types[0]
gpg_config() elif _choice == 1:
elif _choice == 2: if _device_type == 'client':
ssh_config() gpg_config()
elif _choice == 3: else:
if not sshyp_data.has_section('SSHYNC'): pass # TODO implement quick-unlock management
ssh_config() elif _choice == 2:
dev_id_config(sshyp_data.get('SSHYNC', 'ip'), sshyp_data.get('SSHYNC', 'user'), if _device_type == 'client':
sshyp_data.get('SSHYNC', 'port')) ssh_config()
elif _choice == 4: else:
editor_config(False) _exit_signal = True
elif _choice == 5: elif _choice == 3:
_enabled = quick_unlock_config(False) if not sshyp_data.has_section('SSHYNC'):
if _enabled == 'true': ssh_config()
_term_message = ("\nquick-unlock has been enabled client-side - in order for this feature to function," dev_id_config(sshyp_data.get('SSHYNC', 'ip'), sshyp_data.get('SSHYNC', 'user'),
"\nyou must first log in to the sshyp server and run:\n\nsshyp whitelist setup (if not" sshyp_data.get('SSHYNC', 'port'))
" already done)\nsshyp whitelist add " elif _choice == 4:
f"'{listdir(f'{home}/.config/sshyp/devices')[0].rstrip()}'\n") editor_config(False)
elif _choice == 8: elif _choice == 5:
_return_val = True _enabled = quick_unlock_config(False)
curses_terminate(_term_message) if _enabled == 'true':
except KeyboardInterrupt: # TODO update for future menu-based quick-unlock management
curses_terminate(False) _term_message = ("\nquick-unlock has been enabled client-side - in order for this feature to function,"
_return_val = True "\nyou must first log in to the sshyp server and run:\n\nsshyp whitelist setup (if not"
return _return_val " already done)\nsshyp whitelist add "
f"'{listdir(f'{home}/.config/sshyp/devices')[0].rstrip()}'\n")
elif _choice == 8:
_exit_signal = True
curses_terminate(_term_message)
except KeyboardInterrupt:
curses_terminate(False)
_exit_signal = True
if _exit_signal:
break
# runs initial configuration wizard # runs initial configuration wizard
@@ -365,7 +367,7 @@ def initial_setup():
f'"{_clipboard_package}" is installed\u001b[0m') f'"{_clipboard_package}" is installed\u001b[0m')
# PORT END CLIPTOOL # PORT END CLIPTOOL
menu_repeat(True) global_menu(_dev_sync_types[0], 'additional configuration options:')
except KeyboardInterrupt: except KeyboardInterrupt:
# cleanly exit curses # cleanly exit curses