diff --git a/src/tweaks/appstate.h b/src/tweaks/appstate.h index cfab203dd..42ef70230 100644 --- a/src/tweaks/appstate.h +++ b/src/tweaks/appstate.h @@ -23,6 +23,7 @@ static List _menu_wps; static List _menu_http; static List _menu_ssh; static List _menu_smbd; +static List _menu_vnc; void menu_network_free_all(void) { @@ -34,6 +35,7 @@ void menu_network_free_all(void) list_free(&_menu_http); list_free(&_menu_ssh); list_free(&_menu_smbd); + list_free(&_menu_vnc); } static List _menu_icons; diff --git a/src/tweaks/formatters.h b/src/tweaks/formatters.h index 327c7a4c9..b7469dbc8 100644 --- a/src/tweaks/formatters.h +++ b/src/tweaks/formatters.h @@ -39,6 +39,17 @@ void formatter_timezone(void *pt, char *out_label) } } +void formatter_vncFps(void *pt, char *out_label) +{ + ListItem *item = (ListItem *)pt; + int value = item->value; + + if (value >= 1 && value <= 30) + sprintf(out_label, "%d", value); + else + strcpy(out_label, "20"); +} + void formatter_appShortcut(void *pt, char *out_label) { ListItem *item = (ListItem *)pt; diff --git a/src/tweaks/network.h b/src/tweaks/network.h index 7c54009d2..27789231b 100644 --- a/src/tweaks/network.h +++ b/src/tweaks/network.h @@ -41,13 +41,26 @@ static struct network_s { bool manual_tz; bool check_updates; bool keep_alive; + bool vncserv; bool loaded; } network_state; +typedef struct network_set { + int vncfps; + int vncrot; + bool loaded; +} network_set; + +static network_set network_settings = { + .vncfps = 20, + .vncrot = 0, +}; + void network_loadState(void) { if (network_state.loaded) return; + network_state.smbd = config_flag_get(".smbdState"); network_state.http = config_flag_get(".httpState"); network_state.ssh = config_flag_get(".sshState"); @@ -62,7 +75,16 @@ void network_loadState(void) network_state.manual_tz = config_flag_get(".manual_tz"); network_state.check_updates = config_flag_get(".checkUpdates"); network_state.keep_alive = config_flag_get(".keepServicesAlive"); + network_state.vncserv = config_flag_get(".vncServer"); network_state.loaded = true; + + // netset + if (network_settings.loaded) + return; + + + config_get(".vncfps", CONFIG_INT, &network_settings.vncfps); + network_settings.loaded = true; } typedef struct { @@ -190,6 +212,12 @@ void network_toggleSmbAvailable(void *item) fclose(file); } +void network_setVNCFPS(void *pt) +{ + network_settings.vncfps = ((ListItem *)pt)->value; + config_setNumber(".vncfps", network_settings.vncfps); +} + void network_setState(bool *state_ptr, const char *flag_name, bool value) { *state_ptr = value; @@ -319,6 +347,37 @@ void network_wpsConnect(void *pt) system("sh " NET_SCRIPT_PATH "/wpsclient.sh"); } +void network_toggleVNC(void *pt) +{ + char command_start[STR_MAX]; + char command_stop[STR_MAX]; + + int new_fps = (int)network_settings.vncfps; + + sprintf(command_start, "/mnt/SDCARD/.tmp_update/bin/vncserver -k /dev/input/event0 -F %d -r 180 &", new_fps); + sprintf(command_stop, "killall -9 vncserver"); + + if (!network_state.vncserv) { + if (!process_isRunning("vncserver")) { + int result = system(command_start); + if (result == 0) { + fprintf(stderr, "VNC enabled\n"); + } else { + fprintf(stderr, "VNC failed to start\n"); + } + } + } else { + if (process_isRunning("vncserver")) { + int result = system(command_stop); + if (result == 0) { + fprintf(stderr, "VNC disabled\n"); + } + } + } + + network_setState(&network_state.vncserv, ".vncServer", ((ListItem *)pt)->value); +} + void network_setTzManualState(void *pt) { bool enabled = ((ListItem *)pt)->value; @@ -544,10 +603,44 @@ void menu_wifi(void *_) header_changed = true; } +void menu_vnc(void *pt) +{ + ListItem *item = (ListItem *)pt; + item->value = (int)network_state.vncserv; + if (!_menu_vnc._created) { + _menu_vnc = list_create(3, LIST_SMALL); + strcpy(_menu_vnc.title, "vnc"); + list_addItem(&_menu_vnc, + (ListItem){ + .label = "IP address: N/A", + .disabled = true, + .action = NULL}); + list_addItem(&_menu_vnc, + (ListItem){ + .label = "Enable", + .item_type = TOGGLE, + .value = (int)network_state.vncserv, + .action = network_toggleVNC}); + list_addItemWithInfoNote(&_menu_vnc, + (ListItem){ + .label = "Framerate", + .item_type = MULTIVALUE, + .value = (int)network_settings.vncfps, + .value_max = 31, + .value_formatter = formatter_vncFps, + .action = network_setVNCFPS}, + "Start a VNC server to view your\n" + "MMP screen remotely\n"); + } + strcpy(_menu_vnc.items[0].label, ip_address_label); + menu_stack[++menu_level] = &_menu_vnc; + header_changed = true; +} + void menu_network(void *_) { - if (!_menu_network._created) { - _menu_network = list_create(8, LIST_SMALL); + if (!_menu_network._created) { + _menu_network = list_create(9, LIST_SMALL); strcpy(_menu_network.title, "Network"); network_loadState(); @@ -626,6 +719,17 @@ void menu_network(void *_) .action = network_setTelnetState}, "Telnet provides unencrypted remote shell\n" "access to your device."); + list_addItemWithInfoNote(&_menu_network, + (ListItem){ + .label = "VNC: Screen share", + .item_type = TOGGLE, + .disabled = !settings.wifi_on, + .alternative_arrow_action = true, + .arrow_action = network_toggleVNC, + .value = (int)network_state.vncserv, + .action = menu_vnc}, + "Connect to your MMP from another device\n" + "to view the screen"); list_addItemWithInfoNote(&_menu_network, (ListItem){ .label = "Disable services in game",