From a856716b12f1745b076257dd8ae8cb1f5e542305 Mon Sep 17 00:00:00 2001 From: RemixDev Date: Fri, 21 Aug 2020 20:27:23 +0200 Subject: [PATCH 01/11] Started moving the UI from pywebview to QT --- deemix-pyweb.py | 133 ++++++++++++++++++++++++++++++++++++++++++++++++ server.py | 15 +++--- 2 files changed, 141 insertions(+), 7 deletions(-) create mode 100644 deemix-pyweb.py diff --git a/deemix-pyweb.py b/deemix-pyweb.py new file mode 100644 index 0000000..884a145 --- /dev/null +++ b/deemix-pyweb.py @@ -0,0 +1,133 @@ +#!/usr/bin/env python3 +from PyQt5.QtWidgets import QApplication, QMainWindow, QFileDialog +from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEnginePage +from PyQt5.QtCore import QUrl + +from threading import Thread, Lock +import sys +import os.path as path +from os import makedirs +from time import sleep +from server import run_server +from http.client import HTTPConnection +from deemix.utils.localpaths import getConfigFolder + +server_lock = Lock() + +class MainWindow(QMainWindow): + def __init__(self, title, url, x=None, y=None, w=800, h=600): + super().__init__() + self.resize(w, h) + self.setWindowTitle(title) + self.setMinimumSize(800, 600) + self.webview = QWebEngineView() + self.webview.page().loadFinished.connect(self.finishLoading) + self.setCentralWidget(self.webview) + self.url = url + + if x is not None and y is not None: + self.move(x, y) + else: + center = QApplication.desktop().availableGeometry().center() - self.rect().center() + self.move(center.x(), center.y()) + + def showWindow(self): + self.webview.setUrl(QUrl(self.url)) + self.show() + + def selectDownloadFolder(self): + filename = QFileDialog.getExistingDirectory(self, "Select Download Folder", options=QFileDialog.ShowDirsOnly) + return filename + + def closeEvent(self, event): + x = int(self.x()) + y = int(self.y()) + w = int(self.width()) + h = int(self.height()) + if x < 0: x = 0 + if y < 0: y = 0 + with open(path.join(configFolder, '.UIposition'), 'w') as f: + f.write("|".join([str(x),str(y),str(w),str(h)])) + event.accept() + + def finishLoading(self, ok): + if ok: self.webview.page().runJavaScript("window.dispatchEvent(new Event('pywebviewready'))") + +def url_ok(url, port): + try: + conn = HTTPConnection(url, port) + conn.request('GET', '/') + r = conn.getresponse() + return r.status == 200 + except: + print("Server not started") + return False + +def save_position(): + window = webview.windows[0] + x = int(window.x) + y = int(window.y) + w = int(window.width) + h = int(window.height) + if x < 0: x = 0 + if y < 0: y = 0 + with open(path.join(configFolder, '.UIposition'), 'w') as f: + f.write("|".join([str(x),str(y),str(w),str(h)])) + +def get_position(): + if path.isfile(path.join(configFolder, '.UIposition')): + try: + with open(path.join(configFolder, '.UIposition'), 'r') as f: + (x,y,w,h) = f.read().strip().split("|") + x = int(x) + y = int(y) + w = int(w) + h = int(h) + if x < 0: x = 0 + if y < 0: y = 0 + except: + x = None + y = None + w = 800 + h = 600 + else: + x = None + y = None + w = 800 + h = 600 + return (x,y,w,h) + +if __name__ == '__main__': + url = "127.0.0.1" + port = 6595 + if len(sys.argv) >= 2: + try: + port = int(sys.argv[1]) + except ValueError: + pass + portable = None + server = False + if '--portable' in sys.argv: + portable = path.join(path.dirname(path.realpath(__file__)), 'config') + if '--server' in sys.argv or '-s' in sys.argv: + server = True + + if not server: + configFolder = portable or getConfigFolder() + x,y,w,h = get_position() + app = QApplication([]) + window = MainWindow('deemix', 'http://'+url+':'+str(port), x,y,w,h) + t = Thread(target=run_server, args=(port, url, portable, window)) + else: + t = Thread(target=run_server, args=(port, url, portable)) + t.daemon = True + t.start() + + if not server: + while not url_ok(url, port): + sleep(1) + window.showWindow() + app.exec_() + conn = HTTPConnection(url, port) + conn.request('GET', '/shutdown') + t.join() diff --git a/server.py b/server.py index 0f87022..86de5d2 100644 --- a/server.py +++ b/server.py @@ -25,6 +25,7 @@ from engineio.payload import Payload Payload.max_decode_packets = 500 app = None +gui = None class CustomFlask(Flask): jinja_options = Flask.jinja_options.copy() @@ -288,13 +289,12 @@ def openDownloadsFolder(): @socketio.on('selectDownloadFolder') def selectDownloadFolder(): - try: - import webview - result = webview.windows[0].create_file_dialog(webview.FOLDER_DIALOG, allow_multiple=False) + if gui: + result = gui.selectDownloadFolder() if result: emit('downloadFolderSelected', result) - except: - print("Can't open folder selection, you're not running pywebview") + else: + print("Can't open folder selection, you're not running the gui") @socketio.on('applogin') def applogin(): @@ -338,9 +338,10 @@ def applogin(): except: print("Can't open folder selection, you're not running pywebview") -def run_server(port, host="127.0.0.1", portable=None): - global app +def run_server(port, host="127.0.0.1", portable=None, mainWindow=None): + global app, gui app = deemix(portable) + gui = mainWindow print("Starting server at http://" + host + ":" + str(port)) socketio.run(server, host=host, port=port) From 4a3882629ba9353196b987cf7e49fcdd4f37a33d Mon Sep 17 00:00:00 2001 From: RemixDev Date: Fri, 21 Aug 2020 22:33:30 +0200 Subject: [PATCH 02/11] Fixed thread issues and started working on in app login --- deemix-pyweb.py | 24 +++++++++++-- server.py | 92 ++++++++++++++++++++++++++++--------------------- 2 files changed, 73 insertions(+), 43 deletions(-) diff --git a/deemix-pyweb.py b/deemix-pyweb.py index 884a145..fb0b540 100644 --- a/deemix-pyweb.py +++ b/deemix-pyweb.py @@ -1,9 +1,9 @@ #!/usr/bin/env python3 from PyQt5.QtWidgets import QApplication, QMainWindow, QFileDialog from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEnginePage -from PyQt5.QtCore import QUrl +from PyQt5.QtCore import QUrl, pyqtSignal -from threading import Thread, Lock +from threading import Thread, Lock, Semaphore import sys import os.path as path from os import makedirs @@ -15,6 +15,9 @@ from deemix.utils.localpaths import getConfigFolder server_lock = Lock() class MainWindow(QMainWindow): + selectDownloadFolder_trigger = pyqtSignal() + appLogin_trigger = pyqtSignal() + def __init__(self, title, url, x=None, y=None, w=800, h=600): super().__init__() self.resize(w, h) @@ -24,6 +27,14 @@ class MainWindow(QMainWindow): self.webview.page().loadFinished.connect(self.finishLoading) self.setCentralWidget(self.webview) self.url = url + + self.downloadFolder = None + self.selectDownloadFolder_trigger.connect(self.selectDownloadFolder) + self._selectDownloadFolder_semaphore = Semaphore(0) + + self.arl = None + self.appLogin_trigger.connect(self.appLogin) + self._appLogin_semaphore = Semaphore(0) if x is not None and y is not None: self.move(x, y) @@ -37,7 +48,14 @@ class MainWindow(QMainWindow): def selectDownloadFolder(self): filename = QFileDialog.getExistingDirectory(self, "Select Download Folder", options=QFileDialog.ShowDirsOnly) - return filename + self.downloadFolder = filename + self._selectDownloadFolder_semaphore.release() + + def appLogin(self): + loginWindow = QWebEngineView() + loginWindow.setUrl(QUrl("https://deezer.com/login")) + loginWindow.show() + self._appLogin_semaphore.release() def closeEvent(self, event): x = int(self.x()) diff --git a/server.py b/server.py index 86de5d2..75360e6 100644 --- a/server.py +++ b/server.py @@ -290,7 +290,9 @@ def openDownloadsFolder(): @socketio.on('selectDownloadFolder') def selectDownloadFolder(): if gui: - result = gui.selectDownloadFolder() + gui.selectDownloadFolder_trigger.emit() + gui._selectDownloadFolder_semaphore.acquire() + result = gui.downloadFolder if result: emit('downloadFolderSelected', result) else: @@ -298,45 +300,55 @@ def selectDownloadFolder(): @socketio.on('applogin') def applogin(): - try: - import webview - global loginWindow - if not loginWindow: - @copy_current_request_context - def get_ARL(): - global loginWindow - window = webview.windows[loginWindow] - loginWindow = False - window.loaded -= get_ARL - arl = json.loads(window.get_elements("body")[0]['innerText'])['results'] - window.destroy() - emit('applogin_arl', arl) - @copy_current_request_context - def check_URL(): - global loginWindow - window = webview.windows[loginWindow] - try: - url = window.get_current_url() - except: - url = "https://www.deezer.com/us/login" - if not "/login" in url: - window.loaded -= check_URL - window.loaded += get_ARL - window.load_url('https://www.deezer.com/ajax/gw-light.php?method=user.getArl&input=3&api_version=1.0&api_token=null') - @copy_current_request_context - def on_close(): - global loginWindow - if loginWindow: - loginWindow = False - if not session['dz'].logged_in: - window = webview.create_window('Login into your deezer account', "https://deezer.com/login") - loginWindow = len(webview.windows)-1 - window.loaded += check_URL - window.closed += on_close - else: - emit('logged_in', {'status': 2, 'user': session['dz'].user}) - except: - print("Can't open folder selection, you're not running pywebview") + if gui: + gui.appLogin_trigger.emit() + gui._appLogin_semaphore.acquire() + if gui.arl: + emit('applogin_arl', gui.arl) + gui.arl = None + else: + print("No ARL") + else: + print("Can't open login page, you're not running the gui") + #try: + # import webview + # global loginWindow + # if not loginWindow: + # @copy_current_request_context + # def get_ARL(): + # global loginWindow + # window = webview.windows[loginWindow] + # loginWindow = False + # window.loaded -= get_ARL + # arl = json.loads(window.get_elements("body")[0]['innerText'])['results'] + # window.destroy() + # emit('applogin_arl', arl) + # @copy_current_request_context + # def check_URL(): + # global loginWindow + # window = webview.windows[loginWindow] + # try: + # url = window.get_current_url() + # except: + # url = "https://www.deezer.com/us/login" + # if not "/login" in url: + # window.loaded -= check_URL + # window.loaded += get_ARL + # window.load_url('https://www.deezer.com/ajax/gw-light.php?method=user.getArl&input=3&api_version=1.0&api_token=null') + # @copy_current_request_context + # def on_close(): + # global loginWindow + # if loginWindow: + # loginWindow = False + # if not session['dz'].logged_in: + # window = webview.create_window('Login into your deezer account', "https://deezer.com/login") + # loginWindow = len(webview.windows)-1 + # window.loaded += check_URL + # window.closed += on_close + # else: + # emit('logged_in', {'status': 2, 'user': session['dz'].user}) + #except: + # print("Can't open folder selection, you're not running pywebview") def run_server(port, host="127.0.0.1", portable=None, mainWindow=None): global app, gui From 9a450c567211f31bc139deaa39989fb9faaab7cf Mon Sep 17 00:00:00 2001 From: RemixDev Date: Sat, 22 Aug 2020 00:26:32 +0200 Subject: [PATCH 03/11] Added in app login Still need to fix the error "Release of profile requested but WebEnginePage still not deleted. Expect troubles !" --- deemix-pyweb.py | 56 +++++++++++++++++++++++++++++++++++++++++++------ server.py | 52 +++++++-------------------------------------- 2 files changed, 57 insertions(+), 51 deletions(-) diff --git a/deemix-pyweb.py b/deemix-pyweb.py index fb0b540..7bdfd5b 100644 --- a/deemix-pyweb.py +++ b/deemix-pyweb.py @@ -1,8 +1,10 @@ #!/usr/bin/env python3 -from PyQt5.QtWidgets import QApplication, QMainWindow, QFileDialog -from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEnginePage +from PyQt5.QtWidgets import QApplication, QMainWindow, QFileDialog, QDialog, QVBoxLayout +from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEnginePage, QWebEngineProfile from PyQt5.QtCore import QUrl, pyqtSignal +import json + from threading import Thread, Lock, Semaphore import sys import os.path as path @@ -14,6 +16,48 @@ from deemix.utils.localpaths import getConfigFolder server_lock = Lock() +class LoginWindow(QDialog): + + class CustomPage(QWebEnginePage): + + def acceptNavigationRequest(self, url, type, main): + if url.toString() == "https://www.deezer.com/": + url = QUrl('https://www.deezer.com/ajax/gw-light.php?method=user.getArl&input=3&api_version=1.0&api_token=null') + self.setUrl(url) + return False + return super().acceptNavigationRequest(url, type, main) + + + def __init__(self, parent): + super().__init__(parent) + self.webview = QWebEngineView() + profile = QWebEngineProfile(self.webview) + profile.clearHttpCache() + profile.setPersistentCookiesPolicy(QWebEngineProfile.NoPersistentCookies) + profile.setHttpCacheType(QWebEngineProfile.NoCache) + self.page = self.CustomPage(profile, self.webview) + self.page.loadFinished.connect(self.checkURL) + self.webview.setPage(self.page) + self.webview.setUrl(QUrl("https://deezer.com/login")) + layout = QVBoxLayout() + layout.addWidget(self.webview) + self.setLayout(layout) + self.arl = None + self.exec_() + + def checkURL(self, ok): + url = self.webview.url().toString() + if 'user.getArl' in url: + sleep(1) + self.webview.page().toPlainText(self.saveARL) + + def saveARL(self, body): + if body.startswith("{"): + self.arl = json.loads(body)['results'] + self.accept() + self.page = None + self.webview = None + class MainWindow(QMainWindow): selectDownloadFolder_trigger = pyqtSignal() appLogin_trigger = pyqtSignal() @@ -27,7 +71,7 @@ class MainWindow(QMainWindow): self.webview.page().loadFinished.connect(self.finishLoading) self.setCentralWidget(self.webview) self.url = url - + self.downloadFolder = None self.selectDownloadFolder_trigger.connect(self.selectDownloadFolder) self._selectDownloadFolder_semaphore = Semaphore(0) @@ -52,10 +96,10 @@ class MainWindow(QMainWindow): self._selectDownloadFolder_semaphore.release() def appLogin(self): - loginWindow = QWebEngineView() - loginWindow.setUrl(QUrl("https://deezer.com/login")) - loginWindow.show() + loginWindow = LoginWindow(self) + self.arl = loginWindow.arl self._appLogin_semaphore.release() + loginWindow.deleteLater() def closeEvent(self, event): x = int(self.x()) diff --git a/server.py b/server.py index 75360e6..68e573c 100644 --- a/server.py +++ b/server.py @@ -301,54 +301,16 @@ def selectDownloadFolder(): @socketio.on('applogin') def applogin(): if gui: - gui.appLogin_trigger.emit() - gui._appLogin_semaphore.acquire() - if gui.arl: - emit('applogin_arl', gui.arl) - gui.arl = None + if not session['dz'].logged_in: + gui.appLogin_trigger.emit() + gui._appLogin_semaphore.acquire() + if gui.arl: + emit('applogin_arl', gui.arl) + gui.arl = None else: - print("No ARL") + emit('logged_in', {'status': 2, 'user': session['dz'].user}) else: print("Can't open login page, you're not running the gui") - #try: - # import webview - # global loginWindow - # if not loginWindow: - # @copy_current_request_context - # def get_ARL(): - # global loginWindow - # window = webview.windows[loginWindow] - # loginWindow = False - # window.loaded -= get_ARL - # arl = json.loads(window.get_elements("body")[0]['innerText'])['results'] - # window.destroy() - # emit('applogin_arl', arl) - # @copy_current_request_context - # def check_URL(): - # global loginWindow - # window = webview.windows[loginWindow] - # try: - # url = window.get_current_url() - # except: - # url = "https://www.deezer.com/us/login" - # if not "/login" in url: - # window.loaded -= check_URL - # window.loaded += get_ARL - # window.load_url('https://www.deezer.com/ajax/gw-light.php?method=user.getArl&input=3&api_version=1.0&api_token=null') - # @copy_current_request_context - # def on_close(): - # global loginWindow - # if loginWindow: - # loginWindow = False - # if not session['dz'].logged_in: - # window = webview.create_window('Login into your deezer account', "https://deezer.com/login") - # loginWindow = len(webview.windows)-1 - # window.loaded += check_URL - # window.closed += on_close - # else: - # emit('logged_in', {'status': 2, 'user': session['dz'].user}) - #except: - # print("Can't open folder selection, you're not running pywebview") def run_server(port, host="127.0.0.1", portable=None, mainWindow=None): global app, gui From bd537a458017cba74bcbea630b3ed3099ea66095 Mon Sep 17 00:00:00 2001 From: RemixDev Date: Sat, 22 Aug 2020 11:45:16 +0200 Subject: [PATCH 04/11] Added icon to MainWindow --- deemix-pyweb.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/deemix-pyweb.py b/deemix-pyweb.py index 7bdfd5b..35c595a 100644 --- a/deemix-pyweb.py +++ b/deemix-pyweb.py @@ -2,6 +2,7 @@ from PyQt5.QtWidgets import QApplication, QMainWindow, QFileDialog, QDialog, QVBoxLayout from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEnginePage, QWebEngineProfile from PyQt5.QtCore import QUrl, pyqtSignal +from PyQt5.QtGui import QIcon import json @@ -66,6 +67,7 @@ class MainWindow(QMainWindow): super().__init__() self.resize(w, h) self.setWindowTitle(title) + self.setWindowIcon(QIcon(path.join(appDir, 'icon.ico'))) self.setMinimumSize(800, 600) self.webview = QWebEngineView() self.webview.page().loadFinished.connect(self.finishLoading) @@ -169,8 +171,9 @@ if __name__ == '__main__': pass portable = None server = False + appDir = path.dirname(path.realpath(__file__)) if '--portable' in sys.argv: - portable = path.join(path.dirname(path.realpath(__file__)), 'config') + portable = path.join(appDir, 'config') if '--server' in sys.argv or '-s' in sys.argv: server = True From 959817d20d6d9acb4964d85f412103a1545830c4 Mon Sep 17 00:00:00 2001 From: RemixDev Date: Sat, 22 Aug 2020 11:46:27 +0200 Subject: [PATCH 05/11] Open href links in browser --- deemix-pyweb.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/deemix-pyweb.py b/deemix-pyweb.py index 35c595a..682a48b 100644 --- a/deemix-pyweb.py +++ b/deemix-pyweb.py @@ -5,6 +5,7 @@ from PyQt5.QtCore import QUrl, pyqtSignal from PyQt5.QtGui import QIcon import json +import webbrowser from threading import Thread, Lock, Semaphore import sys @@ -63,6 +64,24 @@ class MainWindow(QMainWindow): selectDownloadFolder_trigger = pyqtSignal() appLogin_trigger = pyqtSignal() + class MainWebpage(QWebEnginePage): + + class ExternalWebpage(QWebEnginePage): + def __init__(self, parent): + super().__init__(parent) + self.urlChanged.connect(self.open_browser) + + def open_browser(self, url): + page = self.sender() + webbrowser.open(url.toString(), 2, True) + page.deleteLater() + + def createWindow(self, _type): + page = None + if _type == QWebEnginePage.WebBrowserTab: + page = self.ExternalWebpage(self) + return page + def __init__(self, title, url, x=None, y=None, w=800, h=600): super().__init__() self.resize(w, h) @@ -70,7 +89,9 @@ class MainWindow(QMainWindow): self.setWindowIcon(QIcon(path.join(appDir, 'icon.ico'))) self.setMinimumSize(800, 600) self.webview = QWebEngineView() - self.webview.page().loadFinished.connect(self.finishLoading) + self.page = self.MainWebpage(self.webview) + self.page.loadFinished.connect(self.finishLoading) + self.webview.setPage(self.page) self.setCentralWidget(self.webview) self.url = url From c35dfa2223c6f042ef04df732e05438b952b39ec Mon Sep 17 00:00:00 2001 From: RemixDev Date: Sat, 22 Aug 2020 11:47:12 +0200 Subject: [PATCH 06/11] Fixed WebEnginePage still not deleted error --- deemix-pyweb.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/deemix-pyweb.py b/deemix-pyweb.py index 682a48b..0be7ad1 100644 --- a/deemix-pyweb.py +++ b/deemix-pyweb.py @@ -21,7 +21,6 @@ server_lock = Lock() class LoginWindow(QDialog): class CustomPage(QWebEnginePage): - def acceptNavigationRequest(self, url, type, main): if url.toString() == "https://www.deezer.com/": url = QUrl('https://www.deezer.com/ajax/gw-light.php?method=user.getArl&input=3&api_version=1.0&api_token=null') @@ -29,7 +28,6 @@ class LoginWindow(QDialog): return False return super().acceptNavigationRequest(url, type, main) - def __init__(self, parent): super().__init__(parent) self.webview = QWebEngineView() @@ -57,8 +55,6 @@ class LoginWindow(QDialog): if body.startswith("{"): self.arl = json.loads(body)['results'] self.accept() - self.page = None - self.webview = None class MainWindow(QMainWindow): selectDownloadFolder_trigger = pyqtSignal() @@ -122,6 +118,8 @@ class MainWindow(QMainWindow): loginWindow = LoginWindow(self) self.arl = loginWindow.arl self._appLogin_semaphore.release() + loginWindow.page.deleteLater() + loginWindow.webview.deleteLater() loginWindow.deleteLater() def closeEvent(self, event): From 08903f6195798d3918025e4233941f90aaa51cf2 Mon Sep 17 00:00:00 2001 From: RemixDev Date: Sat, 22 Aug 2020 12:57:29 +0200 Subject: [PATCH 07/11] Removed web specific actions from context menu --- deemix-pyweb.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/deemix-pyweb.py b/deemix-pyweb.py index 0be7ad1..3668bb9 100644 --- a/deemix-pyweb.py +++ b/deemix-pyweb.py @@ -19,7 +19,6 @@ from deemix.utils.localpaths import getConfigFolder server_lock = Lock() class LoginWindow(QDialog): - class CustomPage(QWebEnginePage): def acceptNavigationRequest(self, url, type, main): if url.toString() == "https://www.deezer.com/": @@ -32,9 +31,7 @@ class LoginWindow(QDialog): super().__init__(parent) self.webview = QWebEngineView() profile = QWebEngineProfile(self.webview) - profile.clearHttpCache() profile.setPersistentCookiesPolicy(QWebEngineProfile.NoPersistentCookies) - profile.setHttpCacheType(QWebEngineProfile.NoCache) self.page = self.CustomPage(profile, self.webview) self.page.loadFinished.connect(self.checkURL) self.webview.setPage(self.page) @@ -61,6 +58,11 @@ class MainWindow(QMainWindow): appLogin_trigger = pyqtSignal() class MainWebpage(QWebEnginePage): + def __init__(self, parent): + super().__init__(parent) + actions = [0,1,2,3,10,11,12,13,14,31,16,19,25,26,28,30,32] + for a in actions: + self.action(a).setVisible(False) class ExternalWebpage(QWebEnginePage): def __init__(self, parent): From 2519db950fa827bce6136f886d1ea6cc9a66fb5c Mon Sep 17 00:00:00 2001 From: RemixDev Date: Sat, 22 Aug 2020 13:42:33 +0200 Subject: [PATCH 08/11] Updated requirements.txt --- requirements.txt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/requirements.txt b/requirements.txt index 6d417dd..f9d207c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,5 @@ deemix>=1.2.7 flask flask-socketio -pywebview>=3.3.2 -cefpython3; platform_system == "Windows" -pywebview[qt]>=3.3.2; platform_system == "Linux" +pyqt5 +pyqtwebengine From de9b4a21f6378d86c1e00fd13641bc12e40cd3ad Mon Sep 17 00:00:00 2001 From: RemixDev Date: Sat, 22 Aug 2020 13:54:07 +0200 Subject: [PATCH 09/11] Removed deemix_gui.py and changed spec file --- deemix_gui.spec => deemix-webui.spec | 10 +-- deemix_gui.py | 101 --------------------------- 2 files changed, 5 insertions(+), 106 deletions(-) rename deemix_gui.spec => deemix-webui.spec (90%) delete mode 100644 deemix_gui.py diff --git a/deemix_gui.spec b/deemix-webui.spec similarity index 90% rename from deemix_gui.spec rename to deemix-webui.spec index d17e52c..29f5ce8 100644 --- a/deemix_gui.spec +++ b/deemix-webui.spec @@ -7,7 +7,7 @@ block_cipher = None sys.modules['FixTk'] = None -a = Analysis(['deemix_gui.py'], +a = Analysis(['deemix-webui.py'], binaries=[], datas=[('webui/public', 'webui/public')], hiddenimports=['engineio.async_drivers.threading', 'pkg_resources.py2_warn'], @@ -27,7 +27,7 @@ if sys.platform.startswith('darwin'): a.zipfiles, a.datas, [], - name='deemix_gui', + name='deemix-webui', debug=False, bootloader_ignore_signals=False, strip=False, @@ -37,7 +37,7 @@ if sys.platform.startswith('darwin'): console=False, icon=f"icon.icns") app = BUNDLE(exe, - name='deemix_gui.app', + name='deemix-webui.app', icon="icon.icns", bundle_identifier=None) else: @@ -45,7 +45,7 @@ else: a.scripts, [], exclude_binaries=True, - name='deemix_gui', + name='deemix-webui', debug=False, bootloader_ignore_signals=False, strip=False, @@ -59,4 +59,4 @@ else: strip=False, upx=True, upx_exclude=[], - name='deemix_gui') + name='deemix-webui') diff --git a/deemix_gui.py b/deemix_gui.py deleted file mode 100644 index ad8475c..0000000 --- a/deemix_gui.py +++ /dev/null @@ -1,101 +0,0 @@ -#!/usr/bin/env python3 -import webview - -from threading import Thread, Lock -import sys -import os.path as path -from os import makedirs -from time import sleep -from server import run_server -from http.client import HTTPConnection -from deemix.utils.localpaths import getConfigFolder - -server_lock = Lock() - -def url_ok(url, port): - try: - conn = HTTPConnection(url, port) - conn.request('GET', '/') - r = conn.getresponse() - return r.status == 200 - except: - print("Server not started") - return False - -def save_position(): - window = webview.windows[0] - x = int(window.x) - y = int(window.y) - w = int(window.width) - h = int(window.height) - if x < 0: x = 0 - if y < 0: y = 0 - with open(path.join(configFolder, '.UIposition'), 'w') as f: - f.write("|".join([str(x),str(y),str(w),str(h)])) - -if __name__ == '__main__': - url = "127.0.0.1" - port = 6595 - if len(sys.argv) >= 2: - try: - port = int(sys.argv[1]) - except ValueError: - pass - portable = None - server = False - if '--portable' in sys.argv: - portable = path.join(path.dirname(path.realpath(__file__)), 'config') - if '--server' in sys.argv or '-s' in sys.argv: - server = True - - t = Thread(target=run_server, args=(port, url, portable)) - t.daemon = True - t.start() - - if not server: - while not url_ok(url, port): - sleep(1) - if portable: - configFolder = portable - else: - configFolder = getConfigFolder() - - if path.isfile(path.join(configFolder, '.UIposition')): - try: - with open(path.join(configFolder, '.UIposition'), 'r') as f: - (x,y,w,h) = f.read().strip().split("|") - x = int(x) - y = int(y) - w = int(w) - h = int(h) - if x < 0: x = 0 - if y < 0: y = 0 - except: - x = None - y = None - w = 800 - h = 600 - else: - x = None - y = None - w = 800 - h = 600 - window = webview.create_window('deemix', 'http://'+url+':'+str(port), - x=x, y=y, width=w, height=h, text_select=True) - window.closing += save_position - if sys.platform == "win32": - from webview.platforms.cef import settings - cacheFolder = path.join(configFolder, 'cefCache') - makedirs(cacheFolder, exist_ok=True) - settings.update({ - 'persist_session_cookies': True, - 'cache_path': cacheFolder - }) - webview.start(gui='cef') - elif sys.platform == "linux": - webview.start(gui='qt') - else: - webview.start() - conn = HTTPConnection(url, port) - conn.request('GET', '/shutdown') - t.join() From 188ec2072b1fb4da697511085ce7e2bafb6efa80 Mon Sep 17 00:00:00 2001 From: RemixDev Date: Sat, 22 Aug 2020 13:58:08 +0200 Subject: [PATCH 10/11] Renamed spec file --- deemix-webui.spec => deemix-pyweb.spec | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename deemix-webui.spec => deemix-pyweb.spec (100%) diff --git a/deemix-webui.spec b/deemix-pyweb.spec similarity index 100% rename from deemix-webui.spec rename to deemix-pyweb.spec From da94900878df3ccb4798aa2873d12070320100bb Mon Sep 17 00:00:00 2001 From: RemixDev Date: Sat, 22 Aug 2020 14:06:59 +0200 Subject: [PATCH 11/11] Updated spec file --- deemix-pyweb.spec | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/deemix-pyweb.spec b/deemix-pyweb.spec index 29f5ce8..4d4d25a 100644 --- a/deemix-pyweb.spec +++ b/deemix-pyweb.spec @@ -7,7 +7,7 @@ block_cipher = None sys.modules['FixTk'] = None -a = Analysis(['deemix-webui.py'], +a = Analysis(['deemix-pyweb.py'], binaries=[], datas=[('webui/public', 'webui/public')], hiddenimports=['engineio.async_drivers.threading', 'pkg_resources.py2_warn'], @@ -27,7 +27,7 @@ if sys.platform.startswith('darwin'): a.zipfiles, a.datas, [], - name='deemix-webui', + name='deemix-pyweb', debug=False, bootloader_ignore_signals=False, strip=False, @@ -37,7 +37,7 @@ if sys.platform.startswith('darwin'): console=False, icon=f"icon.icns") app = BUNDLE(exe, - name='deemix-webui.app', + name='deemix-pyweb.app', icon="icon.icns", bundle_identifier=None) else: @@ -45,7 +45,7 @@ else: a.scripts, [], exclude_binaries=True, - name='deemix-webui', + name='deemix-pyweb', debug=False, bootloader_ignore_signals=False, strip=False, @@ -59,4 +59,4 @@ else: strip=False, upx=True, upx_exclude=[], - name='deemix-webui') + name='deemix-pyweb')