-
Notifications
You must be signed in to change notification settings - Fork 0
/
flathub-ui
123 lines (91 loc) · 4.4 KB
/
flathub-ui
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env python3
from PyQt5.QtCore import QUrl, QProcess
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QApplication, QMainWindow, QVBoxLayout, QWidget, QTextEdit, QPushButton, QDialog, QProgressBar, QMessageBox
from PyQt5.QtWebEngineWidgets import QWebEngineView
import shutil
import sys
import tempfile
import urllib.request
import webbrowser
class CommandOutput(QDialog):
def __init__(self, parent=None):
super().__init__(parent)
self.setWindowTitle('Progreso de instalación del paquete Flatpak')
self.resize(600, 400)
self.layout = QVBoxLayout()
self.text_edit = QTextEdit(self)
self.text_edit.setReadOnly(True)
self.layout.addWidget(self.text_edit)
# Add a progress bar
self.progress_bar = QProgressBar(self)
self.progress_bar.setRange(0, 0) # Indeterminate progress
self.layout.addWidget(self.progress_bar)
self.button_force_cancel = QPushButton("Forzar Cancelación De Instalación", self)
self.button_force_cancel.clicked.connect(self.force_cancel_process)
self.layout.addWidget(self.button_force_cancel)
self.button_close = QPushButton("Cerrar", self)
self.button_close.clicked.connect(self.close)
self.button_close.setEnabled(False) # Disable initially
self.button_close.setVisible(False) # Hide initially
self.layout.addWidget(self.button_close)
self.setLayout(self.layout)
def append_output(self, text):
self.text_edit.append(text)
# Check if the text indicates that the app is already installed
if "rama stable ya se encuentra instalada" in text:
self.process.kill() # Stop the process
QMessageBox.information(self, "Información", "El programa ya se encuentra instalado.")
self.close()
def process_finished(self):
self.progress_bar.setRange(0, 100) # Determinate progress
self.progress_bar.setValue(100)
self.button_force_cancel.setVisible(False) # Hide
self.button_close.setEnabled(True) # Enable
self.button_close.setVisible(True) # Show
def force_cancel_process(self):
if self.process:
self.process.kill()
self.close()
class PythonWebView(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle('Flathub Store')
self.setWindowIcon(QIcon('flathub-ui'))
self.central_widget = QWidget(self)
self.setCentralWidget(self.central_widget)
self.resize(1000, 600)
self.layout = QVBoxLayout()
self.central_widget.setLayout(self.layout)
self.wview = QWebEngineView(self)
self.wview.load(QUrl('https://flathub.org'))
self.wview.page().profile().downloadRequested.connect(self.download_requested)
self.wview.page().profile().setHttpUserAgent('Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:90.0) Gecko/20100101 Firefox/90.0')
self.layout.addWidget(self.wview)
self.show()
self.move(QApplication.desktop().screen().rect().center() - self.rect().center())
def download_requested(self, download):
url = download.url().toString()
if url.endswith('.flatpakref'):
with urllib.request.urlopen(url) as response, tempfile.NamedTemporaryFile(suffix='.flatpakref', delete=False) as fp:
shutil.copyfileobj(response, fp)
fp.close()
self.process = QProcess()
self.process.setProcessChannelMode(QProcess.MergedChannels) # Combine stdout and stderr
self.output_window = CommandOutput(self) # pass `self` to make it modal
self.output_window.process = self.process # pass the process instance to the CommandOutput
self.output_window.show()
self.process.readyRead.connect(self.read_output)
self.process.finished.connect(self.output_window.process_finished)
self.process.start('flatpak', ['install', '-y', '--user', fp.name])
download.cancel()
elif not url.startswith('https://flathub.org'):
webbrowser.open(url, 2)
download.cancel()
def read_output(self):
text = bytes(self.process.readAll()).decode("utf-8")
self.output_window.append_output(text)
if __name__ == "__main__":
app = QApplication(sys.argv)
view = PythonWebView()
sys.exit(app.exec_())