mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-30 18:52:38 +02:00
Successfully wait for VM to start, and then move on in the UI
This commit is contained in:
parent
29a148d211
commit
1f1bb2b353
3 changed files with 29 additions and 19 deletions
|
@ -101,7 +101,7 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||||
|
|
||||||
def vm_started(self):
|
def vm_started(self):
|
||||||
self.waiting_widget.hide()
|
self.waiting_widget.hide()
|
||||||
self.doc_selection_widget.show
|
self.doc_selection_widget.show()
|
||||||
|
|
||||||
def document_selected(self):
|
def document_selected(self):
|
||||||
self.doc_selection_widget.hide()
|
self.doc_selection_widget.hide()
|
||||||
|
|
|
@ -212,13 +212,14 @@ class SettingsWidget(QtWidgets.QWidget):
|
||||||
"ocr", self.ocr_checkbox.checkState() == QtCore.Qt.Checked
|
"ocr", self.ocr_checkbox.checkState() == QtCore.Qt.Checked
|
||||||
)
|
)
|
||||||
self.global_common.settings.set("ocr_language", self.ocr_combobox.currentText())
|
self.global_common.settings.set("ocr_language", self.ocr_combobox.currentText())
|
||||||
if platform.system() != "Windows":
|
if platform.system() == "Darwin" or platform.system() == "Linux":
|
||||||
self.global_common.settings.set(
|
self.global_common.settings.set(
|
||||||
"open", self.open_checkbox.checkState() == QtCore.Qt.Checked
|
"open", self.open_checkbox.checkState() == QtCore.Qt.Checked
|
||||||
)
|
)
|
||||||
self.global_common.settings.set(
|
if platform.system() == "Linux":
|
||||||
"open_app", self.open_combobox.currentText()
|
self.global_common.settings.set(
|
||||||
)
|
"open_app", self.open_combobox.currentText()
|
||||||
|
)
|
||||||
self.global_common.settings.set(
|
self.global_common.settings.set(
|
||||||
"update_container", self.update_checkbox.checkState() == QtCore.Qt.Checked
|
"update_container", self.update_checkbox.checkState() == QtCore.Qt.Checked
|
||||||
)
|
)
|
||||||
|
|
|
@ -218,11 +218,7 @@ class Vm(QtCore.QObject):
|
||||||
]
|
]
|
||||||
args_str = " ".join(pipes.quote(s) for s in args)
|
args_str = " ".join(pipes.quote(s) for s in args)
|
||||||
print("> " + args_str)
|
print("> " + args_str)
|
||||||
self.hyperkit_p = subprocess.Popen(
|
self.hyperkit_p = subprocess.Popen(args)
|
||||||
args,
|
|
||||||
# stdout=sys.stdout,
|
|
||||||
# stderr=subprocess.STDOUT,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Get the sshd PID
|
# Get the sshd PID
|
||||||
with open(self.sshd_pid_path) as f:
|
with open(self.sshd_pid_path) as f:
|
||||||
|
@ -240,11 +236,11 @@ class Vm(QtCore.QObject):
|
||||||
|
|
||||||
def vm_connected(self):
|
def vm_connected(self):
|
||||||
self.state = self.STATE_ON
|
self.state = self.STATE_ON
|
||||||
self.vm_state_change.emit()
|
self.vm_state_change.emit(self.state)
|
||||||
|
|
||||||
def vm_timeout(self):
|
def vm_timeout(self):
|
||||||
self.state = self.STATE_FAIL
|
self.state = self.STATE_FAIL
|
||||||
self.vm_state_change.emit()
|
self.vm_state_change.emit(self.state)
|
||||||
|
|
||||||
def restart(self):
|
def restart(self):
|
||||||
self.stop()
|
self.stop()
|
||||||
|
@ -293,12 +289,25 @@ class WaitForSsh(QtCore.QThread):
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
# Wait for the SSH port to be open
|
# Wait for the SSH port to be open
|
||||||
|
success = False
|
||||||
timeout_seconds = 45
|
timeout_seconds = 45
|
||||||
sock = socket.socket()
|
start_ts = time.time()
|
||||||
sock.settimeout(timeout_seconds)
|
while True:
|
||||||
try:
|
sock = socket.socket()
|
||||||
sock.connect(("127.0.0.1", int(self.ssh_port)))
|
try:
|
||||||
|
sock.connect(("127.0.0.1", int(self.ssh_port)))
|
||||||
|
sock.close()
|
||||||
|
success = True
|
||||||
|
print("ssh port open!")
|
||||||
|
break
|
||||||
|
except Exception:
|
||||||
|
print("ssh port closed ...")
|
||||||
|
pass
|
||||||
|
|
||||||
|
time.sleep(2)
|
||||||
|
if time.time() - start_ts >= timeout_seconds:
|
||||||
|
self.timeout.emit()
|
||||||
|
break
|
||||||
|
|
||||||
|
if success:
|
||||||
self.connected.emit()
|
self.connected.emit()
|
||||||
sock.close()
|
|
||||||
except socket.timeout:
|
|
||||||
self.timeout.emit()
|
|
||||||
|
|
Loading…
Reference in a new issue