mirror of
https://github.com/onionshare/onionshare.git
synced 2025-02-14 05:31:25 -05:00
Work in progress commit, moving the timer_callback logic from ShareMode into Mode so ReceiveMode can use it as well
This commit is contained in:
parent
7a47570e18
commit
9bb28c743a
@ -86,6 +86,43 @@ class Mode(QtWidgets.QWidget):
|
|||||||
"""
|
"""
|
||||||
This method is called regularly on a timer.
|
This method is called regularly on a timer.
|
||||||
"""
|
"""
|
||||||
|
self.common.log('Mode', 'timer_callback')
|
||||||
|
# If the auto-shutdown timer has stopped, stop the server
|
||||||
|
print(self.server_status.status) ## HERE IS THE PROBLEM, self.server_status.status isn't getting updated
|
||||||
|
if self.server_status.status == ServerStatus.STATUS_STARTED:
|
||||||
|
print('debug1')
|
||||||
|
if self.app.shutdown_timer and self.common.settings.get('shutdown_timeout'):
|
||||||
|
print('debug2')
|
||||||
|
if self.timeout > 0:
|
||||||
|
print('debug3')
|
||||||
|
now = QtCore.QDateTime.currentDateTime()
|
||||||
|
seconds_remaining = now.secsTo(self.server_status.timeout)
|
||||||
|
|
||||||
|
# Update the server button
|
||||||
|
server_button_text = self.get_stop_server_shutdown_timeout_text()
|
||||||
|
self.server_status.server_button.setText(server_button_text.format(seconds_remaining))
|
||||||
|
|
||||||
|
self.status_bar.clearMessage()
|
||||||
|
if not self.app.shutdown_timer.is_alive():
|
||||||
|
if self.timeout_finished_should_stop_server():
|
||||||
|
self.server_status.stop_server()
|
||||||
|
|
||||||
|
def timer_callback_custom(self):
|
||||||
|
"""
|
||||||
|
Add custom timer code.
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
def get_stop_server_shutdown_timeout_text(self):
|
||||||
|
"""
|
||||||
|
Return the string to put on the stop server button, if there's a shutdown timeout
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
def timeout_finished_should_stop_server(self):
|
||||||
|
"""
|
||||||
|
The shutdown timer expired, should we stop the server? Returns a bool
|
||||||
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def start_server(self):
|
def start_server(self):
|
||||||
@ -214,7 +251,7 @@ class Mode(QtWidgets.QWidget):
|
|||||||
"""
|
"""
|
||||||
self.common.log('Mode', 'stop_server')
|
self.common.log('Mode', 'stop_server')
|
||||||
|
|
||||||
if self.server_status.status != self.server_status.STATUS_STOPPED:
|
if self.server_status.status != ServerStatus.STATUS_STOPPED:
|
||||||
try:
|
try:
|
||||||
self.web.stop(self.app.port)
|
self.web.stop(self.app.port)
|
||||||
except:
|
except:
|
||||||
@ -237,7 +274,7 @@ class Mode(QtWidgets.QWidget):
|
|||||||
"""
|
"""
|
||||||
Handle connection from Tor breaking.
|
Handle connection from Tor breaking.
|
||||||
"""
|
"""
|
||||||
if self.server_status.status != self.server_status.STATUS_STOPPED:
|
if self.server_status.status != ServerStatus.STATUS_STOPPED:
|
||||||
self.server_status.stop_server()
|
self.server_status.stop_server()
|
||||||
self.handle_tor_broke_custom()
|
self.handle_tor_broke_custom()
|
||||||
|
|
||||||
|
@ -341,6 +341,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
|||||||
# If we switched off the shutdown timeout setting, ensure the widget is hidden.
|
# If we switched off the shutdown timeout setting, ensure the widget is hidden.
|
||||||
if not self.common.settings.get('shutdown_timeout'):
|
if not self.common.settings.get('shutdown_timeout'):
|
||||||
self.share_mode.server_status.shutdown_timeout_container.hide()
|
self.share_mode.server_status.shutdown_timeout_container.hide()
|
||||||
|
self.receive_mode.server_status.shutdown_timeout_container.hide()
|
||||||
|
|
||||||
d = SettingsDialog(self.common, self.onion, self.qtapp, self.config, self.local_only)
|
d = SettingsDialog(self.common, self.onion, self.qtapp, self.config, self.local_only)
|
||||||
d.settings_saved.connect(reload_settings)
|
d.settings_saved.connect(reload_settings)
|
||||||
@ -348,6 +349,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
|||||||
|
|
||||||
# When settings close, refresh the server status UI
|
# When settings close, refresh the server status UI
|
||||||
self.share_mode.server_status.update()
|
self.share_mode.server_status.update()
|
||||||
|
self.receive_mode.server_status.update()
|
||||||
|
|
||||||
def check_for_updates(self):
|
def check_for_updates(self):
|
||||||
"""
|
"""
|
||||||
@ -367,6 +369,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
|||||||
Check for messages communicated from the web app, and update the GUI accordingly. Also,
|
Check for messages communicated from the web app, and update the GUI accordingly. Also,
|
||||||
call ShareMode and ReceiveMode's timer_callbacks.
|
call ShareMode and ReceiveMode's timer_callbacks.
|
||||||
"""
|
"""
|
||||||
|
self.common.log('OnionShareGui', 'timer_callback')
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
if not self.local_only:
|
if not self.local_only:
|
||||||
@ -413,10 +416,8 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
|||||||
elif event["path"] != '/favicon.ico':
|
elif event["path"] != '/favicon.ico':
|
||||||
self.status_bar.showMessage('[#{0:d}] {1:s}: {2:s}'.format(web.error404_count, strings._('other_page_loaded', True), event["path"]))
|
self.status_bar.showMessage('[#{0:d}] {1:s}: {2:s}'.format(web.error404_count, strings._('other_page_loaded', True), event["path"]))
|
||||||
|
|
||||||
if self.mode == self.MODE_SHARE:
|
self.share_mode.timer_callback()
|
||||||
self.share_mode.timer_callback()
|
self.receive_mode.timer_callback()
|
||||||
else:
|
|
||||||
self.receive_mode.timer_callback()
|
|
||||||
|
|
||||||
def copy_url(self):
|
def copy_url(self):
|
||||||
"""
|
"""
|
||||||
|
@ -58,6 +58,19 @@ class ReceiveMode(Mode):
|
|||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def get_stop_server_shutdown_timeout_text(self):
|
||||||
|
"""
|
||||||
|
Return the string to put on the stop server button, if there's a shutdown timeout
|
||||||
|
"""
|
||||||
|
return strings._('gui_receive_stop_server_shutdown_timeout', True)
|
||||||
|
|
||||||
|
def timeout_finished_should_stop_server(self):
|
||||||
|
"""
|
||||||
|
The shutdown timer expired, should we stop the server? Returns a bool
|
||||||
|
"""
|
||||||
|
# TODO: wait until the final upload is done before stoppign the server?
|
||||||
|
return True
|
||||||
|
|
||||||
def start_server_custom(self):
|
def start_server_custom(self):
|
||||||
"""
|
"""
|
||||||
Starting the server.
|
Starting the server.
|
||||||
|
@ -211,7 +211,7 @@ class ServerStatus(QtWidgets.QWidget):
|
|||||||
if self.mode == ServerStatus.MODE_SHARE:
|
if self.mode == ServerStatus.MODE_SHARE:
|
||||||
self.server_button.setText(strings._('gui_share_stop_server', True))
|
self.server_button.setText(strings._('gui_share_stop_server', True))
|
||||||
else:
|
else:
|
||||||
self.server_button.setText(strings._('gui_share_stop_server', True))
|
self.server_button.setText(strings._('gui_receive_stop_server', True))
|
||||||
if self.common.settings.get('shutdown_timeout'):
|
if self.common.settings.get('shutdown_timeout'):
|
||||||
self.shutdown_timeout_container.hide()
|
self.shutdown_timeout_container.hide()
|
||||||
if self.mode == ServerStatus.MODE_SHARE:
|
if self.mode == ServerStatus.MODE_SHARE:
|
||||||
|
@ -118,7 +118,7 @@ class ShareMode(Mode):
|
|||||||
# Always start with focus on file selection
|
# Always start with focus on file selection
|
||||||
self.file_selection.setFocus()
|
self.file_selection.setFocus()
|
||||||
|
|
||||||
def timer_callback(self):
|
def timer_callback_custom(self):
|
||||||
"""
|
"""
|
||||||
This method is called regularly on a timer while share mode is active.
|
This method is called regularly on a timer while share mode is active.
|
||||||
"""
|
"""
|
||||||
@ -126,24 +126,26 @@ class ShareMode(Mode):
|
|||||||
if self.new_download:
|
if self.new_download:
|
||||||
self.downloads.downloads_container.vbar.setValue(self.downloads.downloads_container.vbar.maximum())
|
self.downloads.downloads_container.vbar.setValue(self.downloads.downloads_container.vbar.maximum())
|
||||||
self.new_download = False
|
self.new_download = False
|
||||||
|
|
||||||
# If the auto-shutdown timer has stopped, stop the server
|
def get_stop_server_shutdown_timeout_text(self):
|
||||||
if self.server_status.status == self.server_status.STATUS_STARTED:
|
"""
|
||||||
if self.app.shutdown_timer and self.common.settings.get('shutdown_timeout'):
|
Return the string to put on the stop server button, if there's a shutdown timeout
|
||||||
if self.timeout > 0:
|
"""
|
||||||
now = QtCore.QDateTime.currentDateTime()
|
return strings._('gui_share_stop_server_shutdown_timeout', True)
|
||||||
seconds_remaining = now.secsTo(self.server_status.timeout)
|
|
||||||
self.server_status.server_button.setText(strings._('gui_share_stop_server_shutdown_timeout', True).format(seconds_remaining))
|
def timeout_finished_should_stop_server(self):
|
||||||
if not self.app.shutdown_timer.is_alive():
|
"""
|
||||||
# If there were no attempts to download the share, or all downloads are done, we can stop
|
The shutdown timer expired, should we stop the server? Returns a bool
|
||||||
if self.web.download_count == 0 or self.web.done:
|
"""
|
||||||
self.server_status.stop_server()
|
# If there were no attempts to download the share, or all downloads are done, we can stop
|
||||||
self.status_bar.clearMessage()
|
if self.web.download_count == 0 or self.web.done:
|
||||||
self.server_status_label.setText(strings._('close_on_timeout', True))
|
self.server_status.stop_server()
|
||||||
# A download is probably still running - hold off on stopping the share
|
self.server_status_label.setText(strings._('close_on_timeout', True))
|
||||||
else:
|
return True
|
||||||
self.status_bar.clearMessage()
|
# A download is probably still running - hold off on stopping the share
|
||||||
self.server_status_label.setText(strings._('timeout_download_still_running', True))
|
else:
|
||||||
|
self.server_status_label.setText(strings._('timeout_download_still_running', True))
|
||||||
|
return False
|
||||||
|
|
||||||
def start_server_custom(self):
|
def start_server_custom(self):
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user