mirror of
https://github.com/onionshare/onionshare.git
synced 2024-10-01 01:35:40 -04:00
Standardise all startup_timer, scheduled_start attributes as 'autostart_timer'
This commit is contained in:
parent
c411e8d61a
commit
ee3a14a025
@ -138,7 +138,7 @@ def main(cwd=None):
|
||||
if autostart_timer > 0:
|
||||
# Can't set a schedule that is later than the auto-stop timer
|
||||
if app.autostop_timer > 0 and app.autostop_timer < autostart_timer:
|
||||
print(strings._('gui_autostop_timer_cant_be_earlier_than_startup'))
|
||||
print(strings._('gui_autostop_timer_cant_be_earlier_than_autostart_timer'))
|
||||
sys.exit()
|
||||
|
||||
app.start_onion_service(False, True)
|
||||
|
@ -85,7 +85,7 @@ class Settings(object):
|
||||
'auth_password': '',
|
||||
'close_after_first_download': True,
|
||||
'autostop_timer': False,
|
||||
'startup_timer': False,
|
||||
'autostart_timer': False,
|
||||
'use_stealth': False,
|
||||
'use_autoupdate': True,
|
||||
'autoupdate_timestamp': None,
|
||||
|
@ -24,7 +24,7 @@ from onionshare.common import AutoStopTimer
|
||||
|
||||
from ..server_status import ServerStatus
|
||||
from ..threads import OnionThread
|
||||
from ..threads import StartupTimer
|
||||
from ..threads import AutoStartTimer
|
||||
from ..widgets import Alert
|
||||
|
||||
class Mode(QtWidgets.QWidget):
|
||||
@ -115,12 +115,12 @@ class Mode(QtWidgets.QWidget):
|
||||
"""
|
||||
# If this is a scheduled share, display the countdown til the share starts
|
||||
if self.server_status.status == ServerStatus.STATUS_WORKING:
|
||||
if self.server_status.scheduled_start:
|
||||
if self.server_status.autostart_timer_datetime:
|
||||
now = QtCore.QDateTime.currentDateTime()
|
||||
if self.server_status.local_only:
|
||||
seconds_remaining = now.secsTo(self.server_status.startup_timer.dateTime())
|
||||
seconds_remaining = now.secsTo(self.server_status.autostart_timer_widget.dateTime())
|
||||
else:
|
||||
seconds_remaining = now.secsTo(self.server_status.scheduled_start.replace(second=0, microsecond=0))
|
||||
seconds_remaining = now.secsTo(self.server_status.autostart_timer_datetime.replace(second=0, microsecond=0))
|
||||
# Update the server button
|
||||
if seconds_remaining > 0:
|
||||
self.server_status.server_button.setText(strings._('gui_waiting_to_start').format(self.human_friendly_time(seconds_remaining)))
|
||||
@ -183,15 +183,15 @@ class Mode(QtWidgets.QWidget):
|
||||
# Start the onion thread. If this share was scheduled for a future date,
|
||||
# the OnionThread will start and exit 'early' to obtain the port, slug
|
||||
# and onion address, but it will not start the WebThread yet.
|
||||
if self.server_status.scheduled_start:
|
||||
if self.server_status.autostart_timer_datetime:
|
||||
self.start_onion_thread(obtain_onion_early=True)
|
||||
else:
|
||||
self.start_onion_thread()
|
||||
|
||||
# If scheduling a share, delay starting the real share
|
||||
if self.server_status.scheduled_start:
|
||||
self.common.log('Mode', 'start_server', 'Starting startup timer')
|
||||
self.startup_thread = StartupTimer(self)
|
||||
if self.server_status.autostart_timer_datetime:
|
||||
self.common.log('Mode', 'start_server', 'Starting auto-start timer')
|
||||
self.startup_thread = AutoStartTimer(self)
|
||||
# Once the timer has finished, start the real share, with a WebThread
|
||||
self.startup_thread.success.connect(self.start_scheduled_service)
|
||||
self.startup_thread.error.connect(self.start_server_error)
|
||||
|
@ -228,7 +228,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
||||
self.server_status_label.setText(strings._('gui_status_indicator_share_stopped'))
|
||||
elif self.share_mode.server_status.status == ServerStatus.STATUS_WORKING:
|
||||
self.server_status_image_label.setPixmap(QtGui.QPixmap.fromImage(self.server_status_image_working))
|
||||
if self.share_mode.server_status.scheduled_start:
|
||||
if self.share_mode.server_status.autostart_timer_datetime:
|
||||
self.server_status_label.setText(strings._('gui_status_indicator_share_scheduled'))
|
||||
else:
|
||||
self.server_status_label.setText(strings._('gui_status_indicator_share_working'))
|
||||
@ -242,7 +242,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
||||
self.server_status_label.setText(strings._('gui_status_indicator_receive_stopped'))
|
||||
elif self.receive_mode.server_status.status == ServerStatus.STATUS_WORKING:
|
||||
self.server_status_image_label.setPixmap(QtGui.QPixmap.fromImage(self.server_status_image_working))
|
||||
if self.receive_mode.server_status.scheduled_start:
|
||||
if self.receive_mode.server_status.autostart_timer_datetime:
|
||||
self.server_status_label.setText(strings._('gui_status_indicator_receive_scheduled'))
|
||||
else:
|
||||
self.server_status_label.setText(strings._('gui_status_indicator_receive_working'))
|
||||
@ -319,12 +319,12 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
||||
if not self.common.settings.get('autostop_timer'):
|
||||
self.share_mode.server_status.autostop_timer_container.hide()
|
||||
self.receive_mode.server_status.autostop_timer_container.hide()
|
||||
# If we switched off the startup timer setting, ensure the widget is hidden.
|
||||
if not self.common.settings.get('startup_timer'):
|
||||
self.share_mode.server_status.scheduled_start = None
|
||||
self.receive_mode.server_status.scheduled_start = None
|
||||
self.share_mode.server_status.startup_timer_container.hide()
|
||||
self.receive_mode.server_status.startup_timer_container.hide()
|
||||
# If we switched off the auto-start timer setting, ensure the widget is hidden.
|
||||
if not self.common.settings.get('autostart_timer'):
|
||||
self.share_mode.server_status.autostart_timer_datetime = None
|
||||
self.receive_mode.server_status.autostart_timer_datetime = None
|
||||
self.share_mode.server_status.autostart_timer_container.hide()
|
||||
self.receive_mode.server_status.autostart_timer_container.hide()
|
||||
|
||||
d = SettingsDialog(self.common, self.onion, self.qtapp, self.config, self.local_only)
|
||||
d.settings_saved.connect(reload_settings)
|
||||
|
@ -56,35 +56,35 @@ class ServerStatus(QtWidgets.QWidget):
|
||||
self.app = app
|
||||
|
||||
self.web = None
|
||||
self.scheduled_start = None
|
||||
self.autostart_timer_datetime = None
|
||||
self.local_only = local_only
|
||||
|
||||
self.resizeEvent(None)
|
||||
|
||||
# Startup timer layout
|
||||
self.startup_timer_label = QtWidgets.QLabel(strings._('gui_settings_startup_timer'))
|
||||
self.startup_timer = QtWidgets.QDateTimeEdit()
|
||||
self.startup_timer.setDisplayFormat("hh:mm A MMM d, yy")
|
||||
# Auto-start timer layout
|
||||
self.autostart_timer_label = QtWidgets.QLabel(strings._('gui_settings_autostart_timer'))
|
||||
self.autostart_timer_widget = QtWidgets.QDateTimeEdit()
|
||||
self.autostart_timer_widget.setDisplayFormat("hh:mm A MMM d, yy")
|
||||
if self.local_only:
|
||||
# For testing
|
||||
self.startup_timer.setDateTime(QtCore.QDateTime.currentDateTime().addSecs(15))
|
||||
self.startup_timer.setMinimumDateTime(QtCore.QDateTime.currentDateTime())
|
||||
self.autostart_timer_widget.setDateTime(QtCore.QDateTime.currentDateTime().addSecs(15))
|
||||
self.autostart_timer_widget.setMinimumDateTime(QtCore.QDateTime.currentDateTime())
|
||||
else:
|
||||
# Set proposed timer to be 5 minutes into the future
|
||||
self.startup_timer.setDateTime(QtCore.QDateTime.currentDateTime().addSecs(300))
|
||||
self.autostart_timer_widget.setDateTime(QtCore.QDateTime.currentDateTime().addSecs(300))
|
||||
# Onion services can take a little while to start, so reduce the risk of it expiring too soon by setting the minimum to 60s from now
|
||||
self.startup_timer.setMinimumDateTime(QtCore.QDateTime.currentDateTime().addSecs(60))
|
||||
self.startup_timer.setCurrentSection(QtWidgets.QDateTimeEdit.MinuteSection)
|
||||
startup_timer_layout = QtWidgets.QHBoxLayout()
|
||||
startup_timer_layout.addWidget(self.startup_timer_label)
|
||||
startup_timer_layout.addWidget(self.startup_timer)
|
||||
self.autostart_timer_widget.setMinimumDateTime(QtCore.QDateTime.currentDateTime().addSecs(60))
|
||||
self.autostart_timer_widget.setCurrentSection(QtWidgets.QDateTimeEdit.MinuteSection)
|
||||
autostart_timer_layout = QtWidgets.QHBoxLayout()
|
||||
autostart_timer_layout.addWidget(self.autostart_timer_label)
|
||||
autostart_timer_layout.addWidget(self.autostart_timer_widget)
|
||||
|
||||
# Startup timer container, so it can all be hidden and shown as a group
|
||||
startup_timer_container_layout = QtWidgets.QVBoxLayout()
|
||||
startup_timer_container_layout.addLayout(startup_timer_layout)
|
||||
self.startup_timer_container = QtWidgets.QWidget()
|
||||
self.startup_timer_container.setLayout(startup_timer_container_layout)
|
||||
self.startup_timer_container.hide()
|
||||
# Auto-start timer container, so it can all be hidden and shown as a group
|
||||
autostart_timer_container_layout = QtWidgets.QVBoxLayout()
|
||||
autostart_timer_container_layout.addLayout(autostart_timer_layout)
|
||||
self.autostart_timer_container = QtWidgets.QWidget()
|
||||
self.autostart_timer_container.setLayout(autostart_timer_container_layout)
|
||||
self.autostart_timer_container.hide()
|
||||
|
||||
# Auto-stop timer layout
|
||||
self.autostop_timer_label = QtWidgets.QLabel(strings._('gui_settings_autostop_timer'))
|
||||
@ -149,7 +149,7 @@ class ServerStatus(QtWidgets.QWidget):
|
||||
layout = QtWidgets.QVBoxLayout()
|
||||
layout.addWidget(self.server_button)
|
||||
layout.addLayout(url_layout)
|
||||
layout.addWidget(self.startup_timer_container)
|
||||
layout.addWidget(self.autostart_timer_container)
|
||||
layout.addWidget(self.autostop_timer_container)
|
||||
self.setLayout(layout)
|
||||
|
||||
@ -181,13 +181,13 @@ class ServerStatus(QtWidgets.QWidget):
|
||||
except:
|
||||
pass
|
||||
|
||||
def startup_timer_reset(self):
|
||||
def autostart_timer_reset(self):
|
||||
"""
|
||||
Reset the timer in the UI after stopping a share
|
||||
Reset the auto-start timer in the UI after stopping a share
|
||||
"""
|
||||
self.startup_timer.setDateTime(QtCore.QDateTime.currentDateTime().addSecs(300))
|
||||
self.autostart_timer_widget.setDateTime(QtCore.QDateTime.currentDateTime().addSecs(300))
|
||||
if not self.local_only:
|
||||
self.startup_timer.setMinimumDateTime(QtCore.QDateTime.currentDateTime().addSecs(60))
|
||||
self.autostart_timer_widget.setMinimumDateTime(QtCore.QDateTime.currentDateTime().addSecs(60))
|
||||
|
||||
def autostop_timer_reset(self):
|
||||
"""
|
||||
@ -244,8 +244,8 @@ class ServerStatus(QtWidgets.QWidget):
|
||||
self.common.settings.set('slug', self.web.slug)
|
||||
self.common.settings.save()
|
||||
|
||||
if self.common.settings.get('startup_timer'):
|
||||
self.startup_timer_container.hide()
|
||||
if self.common.settings.get('autostart_timer'):
|
||||
self.autostart_timer_container.hide()
|
||||
|
||||
if self.common.settings.get('autostop_timer'):
|
||||
self.autostop_timer_container.hide()
|
||||
@ -269,8 +269,8 @@ class ServerStatus(QtWidgets.QWidget):
|
||||
else:
|
||||
self.server_button.setText(strings._('gui_receive_start_server'))
|
||||
self.server_button.setToolTip('')
|
||||
if self.common.settings.get('startup_timer'):
|
||||
self.startup_timer_container.show()
|
||||
if self.common.settings.get('autostart_timer'):
|
||||
self.autostart_timer_container.show()
|
||||
if self.common.settings.get('autostop_timer'):
|
||||
self.autostop_timer_container.show()
|
||||
elif self.status == self.STATUS_STARTED:
|
||||
@ -280,17 +280,17 @@ class ServerStatus(QtWidgets.QWidget):
|
||||
self.server_button.setText(strings._('gui_share_stop_server'))
|
||||
else:
|
||||
self.server_button.setText(strings._('gui_receive_stop_server'))
|
||||
if self.common.settings.get('startup_timer'):
|
||||
self.startup_timer_container.hide()
|
||||
if self.common.settings.get('autostart_timer'):
|
||||
self.autostart_timer_container.hide()
|
||||
if self.common.settings.get('autostop_timer'):
|
||||
self.autostop_timer_container.hide()
|
||||
self.server_button.setToolTip(strings._('gui_stop_server_autostop_timer_tooltip').format(self.autostop_timer_widget.dateTime().toString("H:mmAP, MMM dd, yy")))
|
||||
elif self.status == self.STATUS_WORKING:
|
||||
self.server_button.setStyleSheet(self.common.css['server_status_button_working'])
|
||||
self.server_button.setEnabled(True)
|
||||
if self.scheduled_start:
|
||||
self.startup_timer_container.hide()
|
||||
self.server_button.setToolTip(strings._('gui_start_server_startup_timer_tooltip').format(self.startup_timer.dateTime().toString("H:mmAP, MMM dd, yy")))
|
||||
if self.autostart_timer_datetime:
|
||||
self.autostart_timer_container.hide()
|
||||
self.server_button.setToolTip(strings._('gui_start_server_autostart_timer_tooltip').format(self.autostart_timer_widget.dateTime().toString("H:mmAP, MMM dd, yy")))
|
||||
else:
|
||||
self.server_button.setText(strings._('gui_please_wait'))
|
||||
if self.common.settings.get('autostop_timer'):
|
||||
@ -299,9 +299,9 @@ class ServerStatus(QtWidgets.QWidget):
|
||||
self.server_button.setStyleSheet(self.common.css['server_status_button_working'])
|
||||
self.server_button.setEnabled(False)
|
||||
self.server_button.setText(strings._('gui_please_wait'))
|
||||
if self.common.settings.get('startup_timer'):
|
||||
self.startup_timer_container.hide()
|
||||
self.server_button.setToolTip(strings._('gui_start_server_startup_timer_tooltip').format(self.startup_timer.dateTime().toString("H:mmAP, MMM dd, yy")))
|
||||
if self.common.settings.get('autostart_timer'):
|
||||
self.autostart_timer_container.hide()
|
||||
self.server_button.setToolTip(strings._('gui_start_server_autostart_timer_tooltip').format(self.autostart_timer_widget.dateTime().toString("H:mmAP, MMM dd, yy")))
|
||||
if self.common.settings.get('autostop_timer'):
|
||||
self.autostop_timer_container.hide()
|
||||
|
||||
@ -311,15 +311,15 @@ class ServerStatus(QtWidgets.QWidget):
|
||||
"""
|
||||
if self.status == self.STATUS_STOPPED:
|
||||
can_start = True
|
||||
if self.common.settings.get('startup_timer'):
|
||||
if self.common.settings.get('autostart_timer'):
|
||||
if self.local_only:
|
||||
self.scheduled_start = self.startup_timer.dateTime().toPyDateTime()
|
||||
self.autostart_timer_datetime = self.autostart_timer_widget.dateTime().toPyDateTime()
|
||||
else:
|
||||
self.scheduled_start = self.startup_timer.dateTime().toPyDateTime().replace(second=0, microsecond=0)
|
||||
self.autostart_timer_datetime = self.autostart_timer_widget.dateTime().toPyDateTime().replace(second=0, microsecond=0)
|
||||
# If the timer has actually passed already before the user hit Start, refuse to start the server.
|
||||
if QtCore.QDateTime.currentDateTime().toPyDateTime() > self.scheduled_start:
|
||||
if QtCore.QDateTime.currentDateTime().toPyDateTime() > self.autostart_timer_datetime:
|
||||
can_start = False
|
||||
Alert(self.common, strings._('gui_server_startup_timer_expired'), QtWidgets.QMessageBox.Warning)
|
||||
Alert(self.common, strings._('gui_server_autostart_timer_expired'), QtWidgets.QMessageBox.Warning)
|
||||
if self.common.settings.get('autostop_timer'):
|
||||
if self.local_only:
|
||||
self.autostop_timer_datetime = self.autostop_timer_widget.dateTime().toPyDateTime()
|
||||
@ -330,9 +330,9 @@ class ServerStatus(QtWidgets.QWidget):
|
||||
if QtCore.QDateTime.currentDateTime().toPyDateTime() > self.autostop_timer_datetime:
|
||||
can_start = False
|
||||
Alert(self.common, strings._('gui_server_autostop_timer_expired'), QtWidgets.QMessageBox.Warning)
|
||||
if self.common.settings.get('startup_timer'):
|
||||
if self.autostop_timer_datetime <= self.scheduled_start:
|
||||
Alert(self.common, strings._('gui_autostop_timer_cant_be_earlier_than_startup'), QtWidgets.QMessageBox.Warning)
|
||||
if self.common.settings.get('autostart_timer'):
|
||||
if self.autostop_timer_datetime <= self.autostart_timer_datetime:
|
||||
Alert(self.common, strings._('gui_autostop_timer_cant_be_earlier_than_autostart_timer'), QtWidgets.QMessageBox.Warning)
|
||||
can_start = False
|
||||
if can_start:
|
||||
self.start_server()
|
||||
@ -364,7 +364,7 @@ class ServerStatus(QtWidgets.QWidget):
|
||||
Stop the server.
|
||||
"""
|
||||
self.status = self.STATUS_WORKING
|
||||
self.startup_timer_reset()
|
||||
self.autostart_timer_reset()
|
||||
self.autostop_timer_reset()
|
||||
self.update()
|
||||
self.server_stopped.emit()
|
||||
@ -375,7 +375,7 @@ class ServerStatus(QtWidgets.QWidget):
|
||||
"""
|
||||
self.common.log('ServerStatus', 'cancel_server', 'Canceling the server mid-startup')
|
||||
self.status = self.STATUS_WORKING
|
||||
self.startup_timer_reset()
|
||||
self.autostart_timer_reset()
|
||||
self.autostop_timer_reset()
|
||||
self.update()
|
||||
self.server_canceled.emit()
|
||||
|
@ -71,22 +71,22 @@ class SettingsDialog(QtWidgets.QDialog):
|
||||
self.public_mode_widget = QtWidgets.QWidget()
|
||||
self.public_mode_widget.setLayout(public_mode_layout)
|
||||
|
||||
# Whether or not to use a startup ('auto-start') timer
|
||||
self.startup_timer_checkbox = QtWidgets.QCheckBox()
|
||||
self.startup_timer_checkbox.setCheckState(QtCore.Qt.Checked)
|
||||
self.startup_timer_checkbox.setText(strings._("gui_settings_startup_timer_checkbox"))
|
||||
startup_timer_label = QtWidgets.QLabel(strings._("gui_settings_whats_this").format("https://github.com/micahflee/onionshare/wiki/Using-the-Startup-Timer"))
|
||||
startup_timer_label.setStyleSheet(self.common.css['settings_whats_this'])
|
||||
startup_timer_label.setTextInteractionFlags(QtCore.Qt.TextBrowserInteraction)
|
||||
startup_timer_label.setOpenExternalLinks(True)
|
||||
startup_timer_label.setMinimumSize(public_mode_label.sizeHint())
|
||||
startup_timer_layout = QtWidgets.QHBoxLayout()
|
||||
startup_timer_layout.addWidget(self.startup_timer_checkbox)
|
||||
startup_timer_layout.addWidget(startup_timer_label)
|
||||
startup_timer_layout.addStretch()
|
||||
startup_timer_layout.setContentsMargins(0,0,0,0)
|
||||
self.startup_timer_widget = QtWidgets.QWidget()
|
||||
self.startup_timer_widget.setLayout(startup_timer_layout)
|
||||
# Whether or not to use an auto-start timer
|
||||
self.autostart_timer_checkbox = QtWidgets.QCheckBox()
|
||||
self.autostart_timer_checkbox.setCheckState(QtCore.Qt.Checked)
|
||||
self.autostart_timer_checkbox.setText(strings._("gui_settings_autostart_timer_checkbox"))
|
||||
autostart_timer_label = QtWidgets.QLabel(strings._("gui_settings_whats_this").format("https://github.com/micahflee/onionshare/wiki/Using-the-Startup-Timer"))
|
||||
autostart_timer_label.setStyleSheet(self.common.css['settings_whats_this'])
|
||||
autostart_timer_label.setTextInteractionFlags(QtCore.Qt.TextBrowserInteraction)
|
||||
autostart_timer_label.setOpenExternalLinks(True)
|
||||
autostart_timer_label.setMinimumSize(public_mode_label.sizeHint())
|
||||
autostart_timer_layout = QtWidgets.QHBoxLayout()
|
||||
autostart_timer_layout.addWidget(self.autostart_timer_checkbox)
|
||||
autostart_timer_layout.addWidget(autostart_timer_label)
|
||||
autostart_timer_layout.addStretch()
|
||||
autostart_timer_layout.setContentsMargins(0,0,0,0)
|
||||
self.autostart_timer_widget = QtWidgets.QWidget()
|
||||
self.autostart_timer_widget.setLayout(autostart_timer_layout)
|
||||
|
||||
# Whether or not to use an auto-stop timer
|
||||
self.autostop_timer_checkbox = QtWidgets.QCheckBox()
|
||||
@ -108,7 +108,7 @@ class SettingsDialog(QtWidgets.QDialog):
|
||||
# General settings layout
|
||||
general_group_layout = QtWidgets.QVBoxLayout()
|
||||
general_group_layout.addWidget(self.public_mode_widget)
|
||||
general_group_layout.addWidget(self.startup_timer_widget)
|
||||
general_group_layout.addWidget(self.autostart_timer_widget)
|
||||
general_group_layout.addWidget(self.autostop_timer_widget)
|
||||
general_group = QtWidgets.QGroupBox(strings._("gui_settings_general_label"))
|
||||
general_group.setLayout(general_group_layout)
|
||||
@ -506,11 +506,11 @@ class SettingsDialog(QtWidgets.QDialog):
|
||||
else:
|
||||
self.close_after_first_download_checkbox.setCheckState(QtCore.Qt.Unchecked)
|
||||
|
||||
startup_timer = self.old_settings.get('startup_timer')
|
||||
if startup_timer:
|
||||
self.startup_timer_checkbox.setCheckState(QtCore.Qt.Checked)
|
||||
autostart_timer = self.old_settings.get('autostart_timer')
|
||||
if autostart_timer:
|
||||
self.autostart_timer_checkbox.setCheckState(QtCore.Qt.Checked)
|
||||
else:
|
||||
self.startup_timer_checkbox.setCheckState(QtCore.Qt.Unchecked)
|
||||
self.autostart_timer_checkbox.setCheckState(QtCore.Qt.Unchecked)
|
||||
|
||||
autostop_timer = self.old_settings.get('autostop_timer')
|
||||
if autostop_timer:
|
||||
@ -956,7 +956,7 @@ class SettingsDialog(QtWidgets.QDialog):
|
||||
settings.load() # To get the last update timestamp
|
||||
|
||||
settings.set('close_after_first_download', self.close_after_first_download_checkbox.isChecked())
|
||||
settings.set('startup_timer', self.startup_timer_checkbox.isChecked())
|
||||
settings.set('autostart_timer', self.autostart_timer_checkbox.isChecked())
|
||||
settings.set('autostop_timer', self.autostop_timer_checkbox.isChecked())
|
||||
|
||||
# Complicated logic here to force v2 onion mode on or off depending on other settings
|
||||
|
@ -90,30 +90,30 @@ class WebThread(QtCore.QThread):
|
||||
self.success.emit()
|
||||
|
||||
|
||||
class StartupTimer(QtCore.QThread):
|
||||
class AutoStartTimer(QtCore.QThread):
|
||||
"""
|
||||
Waits for a prescribed time before allowing a share to start
|
||||
"""
|
||||
success = QtCore.pyqtSignal()
|
||||
error = QtCore.pyqtSignal(str)
|
||||
def __init__(self, mode, canceled=False):
|
||||
super(StartupTimer, self).__init__()
|
||||
super(AutoStartTimer, self).__init__()
|
||||
self.mode = mode
|
||||
self.canceled = canceled
|
||||
self.mode.common.log('StartupTimer', '__init__')
|
||||
self.mode.common.log('AutoStartTimer', '__init__')
|
||||
|
||||
# allow this thread to be terminated
|
||||
self.setTerminationEnabled()
|
||||
|
||||
def run(self):
|
||||
now = QtCore.QDateTime.currentDateTime()
|
||||
scheduled_start = now.secsTo(self.mode.server_status.scheduled_start)
|
||||
autostart_timer_datetime_delta = now.secsTo(self.mode.server_status.autostart_timer_datetime)
|
||||
try:
|
||||
# Sleep until scheduled time
|
||||
while scheduled_start > 0 and self.canceled == False:
|
||||
while autostart_timer_datetime_delta > 0 and self.canceled == False:
|
||||
time.sleep(0.1)
|
||||
now = QtCore.QDateTime.currentDateTime()
|
||||
scheduled_start = now.secsTo(self.mode.server_status.scheduled_start)
|
||||
autostart_timer_datetime_delta = now.secsTo(self.mode.server_status.autostart_timer_datetime)
|
||||
# Timer has now finished
|
||||
if self.canceled == False:
|
||||
self.mode.server_status.server_button.setText(strings._('gui_please_wait'))
|
||||
|
@ -38,7 +38,7 @@
|
||||
"gui_share_stop_server": "Stop sharing",
|
||||
"gui_share_stop_server_autostop_timer": "Stop Sharing ({})",
|
||||
"gui_stop_server_autostop_timer_tooltip": "Auto-stop timer ends at {}",
|
||||
"gui_start_server_startup_timer_tooltip": "Auto-start timer ends at {}",
|
||||
"gui_start_server_autostart_timer_tooltip": "Auto-start timer ends at {}",
|
||||
"gui_receive_start_server": "Start Receive Mode",
|
||||
"gui_receive_stop_server": "Stop Receive Mode",
|
||||
"gui_receive_stop_server_autostop_timer": "Stop Receive Mode ({}s remaining)",
|
||||
@ -102,8 +102,8 @@
|
||||
"gui_settings_button_help": "Help",
|
||||
"gui_settings_autostop_timer_checkbox": "Use auto-stop timer",
|
||||
"gui_settings_autostop_timer": "Stop the share at:",
|
||||
"gui_settings_startup_timer_checkbox": "Use auto-start timer",
|
||||
"gui_settings_startup_timer": "Start the share at:",
|
||||
"gui_settings_autostart_timer_checkbox": "Use auto-start timer",
|
||||
"gui_settings_autostart_timer": "Start the share at:",
|
||||
"settings_error_unknown": "Can't connect to Tor controller because your settings don't make sense.",
|
||||
"settings_error_automatic": "Could not connect to the Tor controller. Is Tor Browser (available from torproject.org) running in the background?",
|
||||
"settings_error_socket_port": "Can't connect to the Tor controller at {}:{}.",
|
||||
@ -131,8 +131,8 @@
|
||||
"gui_tor_connection_lost": "Disconnected from Tor.",
|
||||
"gui_server_started_after_autostop_timer": "The auto-stop timer ran out before the server started. Please make a new share.",
|
||||
"gui_server_autostop_timer_expired": "The auto-stop timer already ran out. Please update it to start sharing.",
|
||||
"gui_server_startup_timer_expired": "The scheduled time has already passed. Please update it to start sharing.",
|
||||
"gui_autostop_timer_cant_be_earlier_than_startup": "The auto-stop time can't be the same or earlier than the start-up time. Please update it to start sharing.",
|
||||
"gui_server_autostart_timer_expired": "The scheduled time has already passed. Please update it to start sharing.",
|
||||
"gui_autostop_timer_cant_be_earlier_than_autostart_timer": "The auto-stop time can't be the same or earlier than the auto-start time. Please update it to start sharing.",
|
||||
"share_via_onionshare": "OnionShare it",
|
||||
"gui_connect_to_tor_for_onion_settings": "Connect to Tor to see onion service settings",
|
||||
"gui_use_legacy_v2_onions_checkbox": "Use legacy addresses",
|
||||
|
@ -308,16 +308,16 @@ class GuiBaseTest(object):
|
||||
# We should have timed out now
|
||||
self.assertEqual(mode.server_status.status, 0)
|
||||
|
||||
# Startup timer tests
|
||||
def set_startup_timer(self, mode, timer):
|
||||
# Auto-start timer tests
|
||||
def set_autostart_timer(self, mode, timer):
|
||||
'''Test that the timer can be set'''
|
||||
schedule = QtCore.QDateTime.currentDateTime().addSecs(timer)
|
||||
mode.server_status.startup_timer.setDateTime(schedule)
|
||||
self.assertTrue(mode.server_status.startup_timer.dateTime(), schedule)
|
||||
mode.server_status.autostart_timer_widget.setDateTime(schedule)
|
||||
self.assertTrue(mode.server_status.autostart_timer_widget.dateTime(), schedule)
|
||||
|
||||
def startup_timer_widget_hidden(self, mode):
|
||||
'''Test that the startup timer widget is hidden when share has started'''
|
||||
self.assertFalse(mode.server_status.startup_timer_container.isVisible())
|
||||
def autostart_timer_widget_hidden(self, mode):
|
||||
'''Test that the auto-start timer widget is hidden when share has started'''
|
||||
self.assertFalse(mode.server_status.autostart_timer_container.isVisible())
|
||||
|
||||
def scheduled_service_started(self, mode, wait):
|
||||
'''Test that the server has timed out after the timer ran out'''
|
||||
@ -331,7 +331,7 @@ class GuiBaseTest(object):
|
||||
self.server_status_indicator_says_scheduled(mode)
|
||||
self.add_delete_buttons_hidden()
|
||||
self.settings_button_is_hidden()
|
||||
self.set_startup_timer(mode, 10)
|
||||
self.set_autostart_timer(mode, 10)
|
||||
QtTest.QTest.mousePress(mode.server_status.server_button, QtCore.Qt.LeftButton)
|
||||
QtTest.QTest.qWait(2000)
|
||||
QtTest.QTest.mouseRelease(mode.server_status.server_button, QtCore.Qt.LeftButton)
|
||||
|
@ -195,12 +195,12 @@ class GuiShareTest(GuiBaseTest):
|
||||
self.server_timed_out(self.gui.share_mode, 10000)
|
||||
self.web_server_is_stopped()
|
||||
|
||||
def run_all_share_mode_startup_timer_tests(self, public_mode):
|
||||
"""Auto-stop timer tests in share mode"""
|
||||
def run_all_share_mode_autostart_timer_tests(self, public_mode):
|
||||
"""Auto-start timer tests in share mode"""
|
||||
self.run_all_share_mode_setup_tests()
|
||||
self.set_startup_timer(self.gui.share_mode, 5)
|
||||
self.set_autostart_timer(self.gui.share_mode, 5)
|
||||
self.server_working_on_start_button_pressed(self.gui.share_mode)
|
||||
self.startup_timer_widget_hidden(self.gui.share_mode)
|
||||
self.autostart_timer_widget_hidden(self.gui.share_mode)
|
||||
self.server_status_indicator_says_scheduled(self.gui.share_mode)
|
||||
self.web_server_is_stopped()
|
||||
self.scheduled_service_started(self.gui.share_mode, 7000)
|
||||
@ -209,7 +209,7 @@ class GuiShareTest(GuiBaseTest):
|
||||
def run_all_share_mode_autostop_autostart_mismatch_tests(self, public_mode):
|
||||
"""Auto-stop timer tests in share mode"""
|
||||
self.run_all_share_mode_setup_tests()
|
||||
self.set_startup_timer(self.gui.share_mode, 15)
|
||||
self.set_autostart_timer(self.gui.share_mode, 15)
|
||||
self.set_timeout(self.gui.share_mode, 5)
|
||||
QtCore.QTimer.singleShot(4000, self.accept_dialog)
|
||||
QtTest.QTest.mouseClick(self.gui.share_mode.server_status.server_button, QtCore.Qt.LeftButton)
|
||||
|
@ -4,12 +4,12 @@ import unittest
|
||||
|
||||
from .GuiShareTest import GuiShareTest
|
||||
|
||||
class LocalShareModeStartupTimerTest(unittest.TestCase, GuiShareTest):
|
||||
class LocalShareModeAutoStartTimerTest(unittest.TestCase, GuiShareTest):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
test_settings = {
|
||||
"public_mode": False,
|
||||
"startup_timer": True,
|
||||
"autostart_timer": True,
|
||||
"autostop_timer": True,
|
||||
}
|
||||
cls.gui = GuiShareTest.set_up(test_settings)
|
||||
|
@ -4,12 +4,12 @@ import unittest
|
||||
|
||||
from .GuiShareTest import GuiShareTest
|
||||
|
||||
class LocalShareModeStartupTimerTest(unittest.TestCase, GuiShareTest):
|
||||
class LocalShareModeAutoStartTimerTest(unittest.TestCase, GuiShareTest):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
test_settings = {
|
||||
"public_mode": False,
|
||||
"startup_timer": True,
|
||||
"autostart_timer": True,
|
||||
}
|
||||
cls.gui = GuiShareTest.set_up(test_settings)
|
||||
|
||||
@ -20,7 +20,7 @@ class LocalShareModeStartupTimerTest(unittest.TestCase, GuiShareTest):
|
||||
@pytest.mark.gui
|
||||
def test_gui(self):
|
||||
self.run_all_common_setup_tests()
|
||||
self.run_all_share_mode_startup_timer_tests(False)
|
||||
self.run_all_share_mode_autostart_timer_tests(False)
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
@ -5,12 +5,12 @@ from PyQt5 import QtCore, QtTest
|
||||
|
||||
from .GuiShareTest import GuiShareTest
|
||||
|
||||
class LocalShareModeStartupTimerTooShortTest(unittest.TestCase, GuiShareTest):
|
||||
class LocalShareModeAutoStartTimerTooShortTest(unittest.TestCase, GuiShareTest):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
test_settings = {
|
||||
"public_mode": False,
|
||||
"startup_timer": True,
|
||||
"autostart_timer": True,
|
||||
}
|
||||
cls.gui = GuiShareTest.set_up(test_settings)
|
||||
|
||||
@ -23,7 +23,7 @@ class LocalShareModeStartupTimerTooShortTest(unittest.TestCase, GuiShareTest):
|
||||
self.run_all_common_setup_tests()
|
||||
self.run_all_share_mode_setup_tests()
|
||||
# Set a low timeout
|
||||
self.set_startup_timer(self.gui.share_mode, 2)
|
||||
self.set_autostart_timer(self.gui.share_mode, 2)
|
||||
QtTest.QTest.qWait(3000)
|
||||
QtCore.QTimer.singleShot(4000, self.accept_dialog)
|
||||
QtTest.QTest.mouseClick(self.gui.share_mode.server_status.server_button, QtCore.Qt.LeftButton)
|
||||
|
@ -8,7 +8,7 @@ class LocalShareModeCancelTest(unittest.TestCase, GuiShareTest):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
test_settings = {
|
||||
"startup_timer": True,
|
||||
"autostart_timer": True,
|
||||
}
|
||||
cls.gui = GuiShareTest.set_up(test_settings)
|
||||
|
||||
|
@ -8,7 +8,7 @@ class ShareModeCancelTest(unittest.TestCase, TorGuiShareTest):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
test_settings = {
|
||||
"startup_timer": True,
|
||||
"autostart_timer": True,
|
||||
}
|
||||
cls.gui = TorGuiShareTest.set_up(test_settings)
|
||||
|
||||
|
@ -52,7 +52,7 @@ class TestSettings:
|
||||
'auth_password': '',
|
||||
'close_after_first_download': True,
|
||||
'autostop_timer': False,
|
||||
'startup_timer': False,
|
||||
'autostart_timer': False,
|
||||
'use_stealth': False,
|
||||
'use_autoupdate': True,
|
||||
'autoupdate_timestamp': None,
|
||||
|
Loading…
Reference in New Issue
Block a user