Skip to content

Commit da55497

Browse files
committed
Remote Control Server: adding a warning to the info response, if PyRadio is not in Main Mode
1 parent f291753 commit da55497

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

pyradio/radio.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,19 @@ def _text_info(self):
807807
else:
808808
out.append(' Status: Idle')
809809
out.append(' Selection (id={0}): "{1}"'.format(self.selection+1, self.stations[self.selection][0]))
810+
if self.ws.operation_mode != self.ws.NORMAL_MODE:
811+
if self._cnf.headless:
812+
out.append(
813+
'\nPyRadio is NOT in Main Mode!'
814+
"\nPlease attach the program's session to a terminal and take appropriate action"
815+
"\n to close the opened window, effectively putting PyRadio in Main Mode"
816+
)
817+
else:
818+
out.append(
819+
'\nPyRadio is NOT in Main Mode!'
820+
"\nPlease get to the program's terminal and take appropriate action to close the"
821+
"\nopened window, effectively putting PyRadio in Main Mode"
822+
)
810823
return '\n'.join(out)
811824

812825

@@ -846,6 +859,19 @@ def _html_info(self):
846859
out.append('<tr><td>Status:</td><td>Idle</span></td></tr>')
847860
out.append('<tr><td>Selection:</td><td>{}</span></td></tr>'.format(self.stations[self.selection][0]))
848861
out.append('</tbody></table>')
862+
if self.ws.operation_mode != self.ws.NORMAL_MODE:
863+
if self._cnf.headless:
864+
out.append(r'''<p><br><b>PyRadio</b> is <span style="font-weight: bold; color: Red;">NOT</span>
865+
in <span style="font-weight: bold; color: Green;">Main Mode</span>!</p>
866+
<p>Please attach the program's session to a terminal and take appropriate action to close the opened window,
867+
effectively putting <b>PyRadio</b> in <span style="font-weight:bold; color: Green;">Main Mode</span>
868+
</p>''')
869+
else:
870+
out.append(r'''<p><br><b>PyRadio</b> is <span style="font-weight: bold; color: Red;">NOT</span>
871+
in <span style="font-weight: bold; color: Green;">Main Mode</span>!</p>
872+
<p>Please get to the program's terminal and take appropriate action to close the opened window,
873+
effectively putting <b>PyRadio</b> in <span style="font-weight:bold; color: Green;">Main Mode</span>
874+
</p>''')
849875
out.append('</div>')
850876
return '\n'.join(out)
851877

@@ -5269,7 +5295,7 @@ def _move_cursor_one_down(self):
52695295
def _html_check_op_mode(self):
52705296
if self.ws.window_mode == self.ws.NORMAL_MODE:
52715297
return None
5272-
return '<div class="alert alert-danger">Operation not permitted (not in <b>Normal Mode</b>)</div>'
5298+
return '<div class="alert alert-danger">Operation not permitted (not in <b>Main Mode</b>)</div>'
52735299

52745300
def _html_play_next_station(self):
52755301
self._reset_status_bar_right()

pyradio/server.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -933,8 +933,8 @@ class PyRadioServer(object):
933933
'/list': 'Listing stations from playlist',
934934
'/idle': 'Player is idle; operation not applicable...',
935935
'/error': 'Error in parameter',
936-
'/perm': 'Operation not permitted (not in Normal Mode)',
937-
'/perm_html': '<div class="alert alert-danger">Operation not permitted (not in <b>Normal Mode</b>)</div>',
936+
'/perm': 'Operation not permitted (not in Main Mode)',
937+
'/perm_html': '<div class="alert alert-danger">Operation not permitted (not in <b>Main Mode</b>)</div>',
938938
'/log': 'Stations logging toggled',
939939
'/like': 'Station tagged (liked)',
940940
}
@@ -1250,11 +1250,8 @@ def _handle_client_connection(self, address, request):
12501250
# logger.error('received = "{}"'.format(received))
12511251
self._send_raw(received)
12521252
else:
1253-
if self.can_send_command():
1254-
received = self._commands['/text_info']()
1255-
self._send_text(received)
1256-
else:
1257-
self._send_text(self._text['/perm'])
1253+
received = self._commands['/text_info']()
1254+
self._send_text(received)
12581255

12591256
elif self._path in ('/next', '/n'):
12601257
if self._is_html:

0 commit comments

Comments
 (0)