-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
93 lines (77 loc) · 3.69 KB
/
app.py
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
import os
import sys
import requests
import subprocess
import configparser
from PyQt6 import QtWidgets, QtWebEngineWidgets, QtWebEngineCore, QtCore
from PyQt6.QtWidgets import QApplication, QWidget, QVBoxLayout, QSplashScreen, QLabel
from PyQt6.QtWebEngineWidgets import QWebEngineView
from PyQt6.QtWebEngineCore import QWebEnginePage, QWebEngineSettings
from PyQt6.QtCore import QUrl, QTimer
from PyQt6.QtGui import QDesktopServices, QPixmap, QIcon
def isReachable(url):
try:
request = requests.get(url)
if request.status_code == 200:
return True
else:
return False
except requests.exceptions.RequestException as e:
return False
class OpenLinksInDesktopBrowserWebEnginePage(QWebEnginePage):
def acceptNavigationRequest(self, url, navType, isMainFrame):
if (navType == QWebEnginePage.NavigationType.NavigationTypeLinkClicked):
# Use the system's default URL handler.
QDesktopServices.openUrl(url)
return False
return super().acceptNavigationRequest(url, navType, isMainFrame)
class MainWindow(QtWidgets.QMainWindow):
def loadConfig(self):
config = configparser.ConfigParser()
config.read('config.ini')
self.iconPath = config.get('App', 'icon')
self.path = config.get('App', 'path')
self.title = config.get('App', 'title')
self.url = config.get('App', 'url')
def loadServer(self):
if (isReachable(self.url)):
self.timer.stop()
self.browser.setUrl(QUrl(self.url))
self.setCentralWidget(self.browser)
def showSplashscreen(self):
label = QLabel(self)
label.setPixmap(self.icon)
label.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)
self.setCentralWidget(label)
self.show()
def __init__(self, *args, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
self.loadConfig()
self.setWindowTitle(self.title)
self.resize(1280, 800)
self.icon = QPixmap(self.iconPath)
self.setWindowIcon(QIcon(self.icon))
self.browser = QWebEngineView()
self.browser.setPage(OpenLinksInDesktopBrowserWebEnginePage(self))
# Attemps at making local storage work, it might be better to just save the data to a local file instead.
self.browser.settings().setAttribute(QWebEngineSettings.WebAttribute.LocalStorageEnabled, True)
self.browser.settings().setAttribute(QWebEngineSettings.WebAttribute.PdfViewerEnabled, True)
self.browser.settings().setAttribute(QWebEngineSettings.WebAttribute.PluginsEnabled, True)
self.browser.settings().setAttribute(QWebEngineSettings.WebAttribute.AllowRunningInsecureContent, True)
self.browser.settings().setAttribute(QWebEngineSettings.WebAttribute.FullScreenSupportEnabled, True)
self.browser.settings().setAttribute(QWebEngineSettings.WebAttribute.Accelerated2dCanvasEnabled, True)
self.browser.settings().setAttribute(QWebEngineSettings.WebAttribute.LocalContentCanAccessFileUrls, True)
self.browser.settings().setAttribute(QWebEngineSettings.WebAttribute.JavascriptCanAccessClipboard, True)
self.browser.page().quotaRequested.connect(lambda request: request.accept())
self.showSplashscreen()
if (not isReachable(self.url)):
subprocess.Popen(["dotnet", "run", "--project", self.path])
self.timer=QTimer()
self.timer.timeout.connect(self.loadServer)
self.timer.start(100)
if __name__ == '__main__':
workingDirectory = os.path.abspath(os.path.dirname(__file__))
app = QtWidgets.QApplication(sys.argv)
window = MainWindow()
window.show()
app.exec()