Optimize some content
This commit is contained in:
parent
183c16e435
commit
8949d7b9bf
78
Galactic.py
78
Galactic.py
|
@ -39,9 +39,9 @@ from selenium.common.exceptions import NoSuchWindowException
|
|||
from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEngineSettings, QWebEngineProfile
|
||||
from PyQt5.QtWebEngineCore import QWebEngineUrlRequestInterceptor
|
||||
from PyQt5.QtNetwork import QNetworkProxyFactory
|
||||
from PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox, QSystemTrayIcon, QMenu, QAction, QDesktopWidget
|
||||
from PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox, QSystemTrayIcon, QMenu, QAction, QDesktopWidget, QShortcut
|
||||
from PyQt5.QtCore import Qt, QCoreApplication, QTimer, QUrl
|
||||
from PyQt5.QtGui import QIcon
|
||||
from PyQt5.QtGui import QIcon, QKeySequence
|
||||
from typing import List
|
||||
from fastapi import FastAPI, Response, WebSocket, UploadFile, File, HTTPException
|
||||
from pydantic import BaseModel
|
||||
|
@ -50,7 +50,8 @@ from starlette.websockets import WebSocketDisconnect
|
|||
from winotify import Notification, audio
|
||||
from func_timeout import func_set_timeout, FunctionTimedOut
|
||||
from pathlib import Path
|
||||
from urllib.parse import urlparse, urlencode, parse_qs, urljoin
|
||||
from urllib.parse import urlparse
|
||||
|
||||
|
||||
def _fd(f):
|
||||
return f.fileno() if hasattr(f, 'fileno') else f
|
||||
|
@ -474,51 +475,6 @@ class ColorUtils:
|
|||
return r, g, b
|
||||
|
||||
|
||||
class UrlHelper:
|
||||
def __init__(self, url: str):
|
||||
self._url = str(url)
|
||||
self._parsed_url = urlparse(self._url)
|
||||
|
||||
def __str__(self):
|
||||
return self._url
|
||||
|
||||
@classmethod
|
||||
def encode_query_string(cls, qs_object):
|
||||
if not isinstance(qs_object, dict):
|
||||
raise TypeError('Wrong parameter type.')
|
||||
return urlencode(qs_object, doseq=True)
|
||||
|
||||
@classmethod
|
||||
def decode_query_string(cls, qs_string):
|
||||
if not isinstance(qs_string, str):
|
||||
raise TypeError('Wrong parameter type.')
|
||||
return parse_qs(qs_string, keep_blank_values=True)
|
||||
|
||||
@classmethod
|
||||
def join(cls, base, relative):
|
||||
return urljoin(base, relative)
|
||||
|
||||
@property
|
||||
def scheme(self):
|
||||
return self._parsed_url.scheme
|
||||
|
||||
@property
|
||||
def netloc(self):
|
||||
return self._parsed_url.netloc
|
||||
|
||||
@property
|
||||
def path(self):
|
||||
return self._parsed_url.path
|
||||
|
||||
@property
|
||||
def query_string(self):
|
||||
return self._parsed_url.query
|
||||
|
||||
@property
|
||||
def fragment(self):
|
||||
return self._parsed_url.fragment
|
||||
|
||||
|
||||
class FetchResult:
|
||||
def __init__(self, data):
|
||||
self.status = 0
|
||||
|
@ -725,7 +681,6 @@ class Browser(InspectRequestsMixin, DriverCommonMixin, Chrome):
|
|||
self.set_page_load_timeout(25)
|
||||
# Open the default page.
|
||||
home and self.open(home)
|
||||
self.UrlHelper = self.url_helper = UrlHelper
|
||||
|
||||
@property
|
||||
def title(self) -> str:
|
||||
|
@ -1155,6 +1110,10 @@ class BrowserPluginRunningParam(dict):
|
|||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
@classmethod
|
||||
def no_method(cls, *args, **kwargs):
|
||||
pass
|
||||
|
||||
def __setitem__(self, key, value):
|
||||
pass
|
||||
|
||||
|
@ -1171,7 +1130,7 @@ class BrowserPluginRunningParam(dict):
|
|||
try:
|
||||
return super().__getitem__(item)
|
||||
except KeyError:
|
||||
return None
|
||||
return self.no_method
|
||||
|
||||
|
||||
class BrowserPluginParent:
|
||||
|
@ -1194,18 +1153,20 @@ class BrowserPluginParent:
|
|||
self.message_except(e)
|
||||
|
||||
def message(self, message=None):
|
||||
notification_send(app_id=self.app_id, title=self.name, message='%s' % (message,))
|
||||
self.instant_message and self.instant_message(json.dumps({
|
||||
'time': int(time.time()), 'type': 'message', 'data': {'user_id': str(self.user_id), 'content': str(message), 'title': str(self.app_id)}
|
||||
}))
|
||||
if len(str(message)) <= 4096:
|
||||
notification_send(app_id=self.app_id, title=self.name, message='%s' % (message,))
|
||||
self.instant_message and self.instant_message(json.dumps({
|
||||
'time': int(time.time()), 'type': 'message', 'data': {'user_id': str(self.user_id), 'content': str(message), 'title': str(self.app_id)}
|
||||
}))
|
||||
|
||||
def message_except(self, exception_info):
|
||||
notification_send(app_id=self.app_id, title='%s ' % (self.name,), message='%s' % (exception_info,))
|
||||
|
||||
def logging(self, logging=None):
|
||||
self.instant_message and self.instant_message(json.dumps({
|
||||
'time': int(time.time()), 'type': 'logging', 'data': {'user_id': str(self.user_id), 'content': str(logging)}
|
||||
}))
|
||||
if len(str(logging)) <= 1024:
|
||||
self.instant_message and self.instant_message(json.dumps({
|
||||
'time': int(time.time()), 'type': 'logging', 'data': {'user_id': str(self.user_id), 'content': str(logging)}
|
||||
}))
|
||||
|
||||
def run(self, app_id, user_id, driver, requirements, instant_message) -> threading.Thread:
|
||||
self.app_id, self.user_id, self.instant_message = app_id, user_id, instant_message
|
||||
|
@ -1951,6 +1912,7 @@ class MainWindow(QMainWindow):
|
|||
self.tray_menu.addAction(action)
|
||||
self.tray_icon.setContextMenu(self.tray_menu)
|
||||
self.tray_icon.show()
|
||||
QShortcut(QKeySequence('F5'), self).activated.connect(self.on_debug_reload_external_plugins)
|
||||
self.init()
|
||||
|
||||
def closeEvent(self, event):
|
||||
|
@ -2277,7 +2239,7 @@ class MainRunner:
|
|||
appdata = os.getenv('APPDATA')
|
||||
self.app_data = os.path.join(appdata, 'Galactic') if appdata else os.path.join(os.path.dirname(__file__), 'data')
|
||||
self.app_name = 'Galactic'
|
||||
self.app_version = '1.0.0.0'
|
||||
self.app_version = '1.0.0.1'
|
||||
self.web_server_host = '127.0.0.1'
|
||||
self.web_server_port = 8095
|
||||
self.web_server = None
|
||||
|
|
Loading…
Reference in New Issue