├── .github ├── ISSUE_TEMPLATE └── PULL_REQUEST_TEMPLATE ├── .gitignore ├── .travis.yml ├── CONTRIBUTING.md ├── JAK ├── Application.py ├── DevTools.py ├── IPC.py ├── KeyBindings.py ├── RequestInterceptor.py ├── Settings.py ├── Utils.py ├── WebEngine.py ├── Widgets.py └── __init__.py ├── LICENSE ├── MANIFEST.in ├── README.md ├── bin ├── JAK └── jak-cli ├── contributing.md ├── docs ├── Application.html ├── DevTools.html ├── IPC.html ├── KeyBindings.html ├── RequestInterceptor.html ├── Settings.html ├── Utils.html ├── WebEngine.html ├── Widgets.html ├── __init__.html └── pycco.css ├── requirements.txt ├── setup.cfg └── setup.py /.github/ISSUE_TEMPLATE: -------------------------------------------------------------------------------- 1 | ## FEATURE REQUEST: Dear santa for this Christmas i will like? 2 | 3 | #### Detailed Description 4 | 5 | 6 | 7 | #### Context 8 | 9 | 10 | 11 | 12 | ## Possible Implementation 13 | 14 | 15 | 16 | ======================================================= 17 | 18 | 19 | ## BUGS 20 | 21 | 22 | 23 | #### Context 24 | 25 | 26 | 27 | #### Expected Behavior 28 | 29 | 30 | 31 | #### Actual Behavior 32 | 33 | 34 | 35 | #### Possible Fix 36 | 37 | 38 | 39 | #### Steps to Reproduce 40 | 41 | 42 | 1. 43 | 2. 44 | 3. 45 | 4. 46 | 47 | 48 | #### Context 49 | 50 | 51 | 52 | #### Your Environment 53 | 54 | 55 | 56 | Pygi version: 57 | python version: 58 | Linux distro: 59 | Link to your project: 60 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE: -------------------------------------------------------------------------------- 1 | ## Reference to a related issue in your repository. 2 | 3 | 4 | ## Description of the changes proposed in the pull request 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | 5 | # C extensions 6 | *.so 7 | 8 | # Distribution / packaging 9 | .Python 10 | env/ 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | *.egg-info/ 23 | .installed.cfg 24 | *.egg 25 | 26 | # PyInstaller 27 | # Usually these files are written by a python script from a template 28 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 29 | *.manifest 30 | *.spec 31 | 32 | # Installer logs 33 | pip-log.txt 34 | pip-delete-this-directory.txt 35 | 36 | # Unit test / coverage reports 37 | htmlcov/ 38 | .tox/ 39 | .coverage 40 | .coverage.* 41 | .cache 42 | nosetests.xml 43 | coverage.xml 44 | *,cover 45 | 46 | # Translations 47 | *.mo 48 | *.pot 49 | 50 | # Django stuff: 51 | *.log 52 | 53 | # Sphinx documentation 54 | docs/_build/ 55 | 56 | # PyBuilder 57 | target/ 58 | 59 | # JAKTesting 60 | jak 61 | index.html 62 | dist/ 63 | test.py 64 | .idea/ 65 | MANIFEST -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: required 2 | language: python 3 | python: 4 | - '3.6' 5 | - "3.7" 6 | - "3.8" 7 | - "3.9" 8 | notifications: 9 | webhooks: 10 | urls: 11 | - https://webhooks.gitter.im/e/9da87f9fb77e9c13620d 12 | on_success: change 13 | on_failure: always 14 | on_start: never 15 | cache: 16 | - pip 17 | install: 18 | - pip install -r requirements.txt 19 | deploy: 20 | provider: pypi 21 | user: codesardine 22 | password: 23 | secure: etAjJfwFBg8/gzzV9ZkiBXQyDnDzG5QevKy/4SmGeXphl/USCIpBuXH0kxvVkE+DFv6OdiW2eiJk/xFP5LZpA6P9AgJtWmgqoKIkF/0oh/fRHzqwIXgYJJMQpq4ZrwmEEYYNuU5oQaz8wOu/g9EaJ2bo3ACXjsl0PsPyZv7+QBzoV6y3lfnuOYgfcxu3H0OYCfLz2cHER3747n5Fm/9OZZ2LpAgJks9a6AeYujrDNt+7GNIp8LT5W2VIdBCwz3RVazQwHpCHREgoGfVzRWz3Rj/hXUcQygY+ogEUjKMHHJfePuoX+MYP6MMYtvOtUH/P96ltO5kv8Bx8SDzet1HYV2fLNnIiuV5cTA4ChhLD1bdcS3qoom+gwJikY/zgc6gNz0qqzBwnTYJa/0ZcNf+Tw6NrO3Kkd0jE5dfx/di2xrTSyL7lbXxGSKo1ELlbgm+nPdegGp0aTje1Qe2SWFWqcqyB5eYc0B1/4V1m4iORaEsbUEEDLTm+N5PBXOxJ5lXgrvHmgz+N5CzbKYMHoAreuqFo3/vUDf7dVuSAHdnCfZ1N2x2YDZxrSn9gxpStTaE/XvtxM+1VNX55X8+cR/BmkS37avDKM1rASwTpCVwXnZCrRYMwFEBmTMQXjhg/uGX81RZ55Q8chiLTKELSFTRbDOIk87GEdm4019eR1fJJZB8= 24 | distributions: sdist bdist_wheel 25 | on: 26 | tags: true 27 | python: 3.8 28 | script: nosetests 29 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | I would love for you to contribute to JAK and help making it better! Here are some guidelines I would like you to follow: 2 | 3 | ### Developing 4 | 5 | * Join [Gitter chat](https://gitter.im/JustAnotherDesktopEnviroment/Lobby), it will make communication easier. 6 | 7 | * When contributing to this repository, please first discuss the change you wish to make via issue. 8 | 9 | * Try and follow pep8 when you can. 10 | 11 | * Make sure you test your changes. 12 | 13 | * Don't break existing functionality I try to maintain the Master Branch in a working order. 14 | 15 | ## Pull Request Process 16 | 17 | * Ensure you create separate pull requests on another branch for each issue or feature, that will accelerate the merging process without interfering with other issues, once I have tested the code I will merge back.

18 | 19 | ## Adding a wrapper 20 | clone the repository 21 | ``` 22 | git checkout --orphan wrapper/my-wrapper-name-online 23 | git rm -rf . 24 | ``` 25 | Commit your wrapper 26 | ``` 27 | git push -u origin wrapper/my-wrapper-name-online 28 | ``` 29 | All done send pull request 30 | 31 | ### Our Pledge 32 | 33 | In the interest of fostering an open and welcoming environment, we as 34 | contributors and maintainers pledge to making participation in our project and 35 | our community a harassment-free experience for everyone, regardless of age, body 36 | size, disability, ethnicity, gender identity and expression, level of experience, 37 | nationality, personal appearance, race, religion, or sexual identity and 38 | orientation. 39 | 40 | ### Our Standards 41 | 42 | Examples of behavior that contributes to creating a positive environment 43 | include: 44 | 45 | * Using welcoming and inclusive language 46 | * Being respectful of differing viewpoints and experiences 47 | * Gracefully accepting constructive criticism 48 | * Focusing on what is best for the community 49 | * Showing empathy towards other community members 50 | 51 | Examples of unacceptable behavior by participants include: 52 | 53 | * The use of sexualized language or imagery and unwelcome sexual attention or 54 | advances 55 | * Trolling, insulting/derogatory comments, and personal or political attacks 56 | * Public or private harassment 57 | * Publishing others' private information, such as a physical or electronic 58 | address, without explicit permission 59 | * Other conduct which could reasonably be considered inappropriate in a 60 | professional setting 61 | 62 | ### Our Responsibilities 63 | 64 | Project maintainers are responsible for clarifying the standards of acceptable 65 | behavior and are expected to take appropriate and fair corrective action in 66 | response to any instances of unacceptable behavior. 67 | 68 | Project maintainers have the right and responsibility to remove, edit, or 69 | reject comments, commits, code, wiki edits, issues, and other contributions 70 | that are not aligned to this Code of Conduct, or to ban temporarily or 71 | permanently any contributor for other behaviors that they deem inappropriate, 72 | threatening, offensive, or harmful. 73 | 74 | ### Scope 75 | 76 | This Code of Conduct applies both within project spaces and in public spaces 77 | when an individual is representing the project or its community. Examples of 78 | representing a project or community include using an official project e-mail 79 | address, posting via an official social media account, or acting as an appointed 80 | representative at an online or offline event. Representation of a project may be 81 | further defined and clarified by project maintainers. 82 | 83 | ### Enforcement 84 | 85 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 86 | reported by contacting the project team at [INSERT EMAIL ADDRESS]. All 87 | complaints will be reviewed and investigated and will result in a response that 88 | is deemed necessary and appropriate to the circumstances. The project team is 89 | obligated to maintain confidentiality with regard to the reporter of an incident. 90 | Further details of specific enforcement policies may be posted separately. 91 | 92 | Project maintainers who do not follow or enforce the Code of Conduct in good 93 | faith may face temporary or permanent repercussions as determined by other 94 | members of the project's leadership. 95 | 96 | ### Attribution 97 | 98 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 99 | available at [http://contributor-covenant.org/version/1/4][version] 100 | 101 | [homepage]: http://contributor-covenant.org 102 | [version]: http://contributor-covenant.org/version/1/4/ 103 | -------------------------------------------------------------------------------- /JAK/Application.py: -------------------------------------------------------------------------------- 1 | #### Jade Application Kit 2 | # * https://codesardine.github.io/Jade-Application-Kit 3 | # * Vitor Lopes Copyright (c) 2016 - 2020 4 | # * https://vitorlopes.me 5 | 6 | import sys 7 | import subprocess 8 | from JAK.Utils import Instance, bindings, getScreenGeometry 9 | from JAK import Settings 10 | from JAK.Widgets import JWindow 11 | from JAK.WebEngine import JWebView 12 | if bindings() == "PyQt5": 13 | print("PyQt5 Bindings") 14 | from PyQt5.QtCore import Qt, QCoreApplication 15 | from PyQt5.QtWidgets import QApplication 16 | else: 17 | print("JAK_PREFERRED_BINDING environment variable not set, falling back to PySide2 Bindings.") 18 | from PySide2.QtCore import Qt, QCoreApplication 19 | from PySide2.QtWidgets import QApplication 20 | 21 | 22 | class JWebApp(QApplication): 23 | #### Imports: from JAK.Application import JWebApp 24 | def __init__(self, config=Settings.config(), **app_config): 25 | super(JWebApp, self).__init__(sys.argv) 26 | self.config = config 27 | self.setAAttribute(Qt.AA_UseHighDpiPixmaps) 28 | self.setAAttribute(Qt.AA_EnableHighDpiScaling) 29 | self.applicationStateChanged.connect(self._applicationStateChanged_cb) 30 | 31 | for key, value in app_config.items(): 32 | if isinstance(value, dict): 33 | for subkey, subvalue in app_config[key].items(): 34 | config[key][subkey] = subvalue 35 | else: 36 | config[key] = value 37 | 38 | if config["setAAttribute"]: 39 | for attr in config["setAAttribute"]: 40 | self.setAAttribute(attr) 41 | 42 | if config["remote-debug"] or "--remote-debug" in sys.argv: 43 | sys.argv.append("--remote-debugging-port=9000") 44 | 45 | if config["debug"] or "--dev" in sys.argv: 46 | print("Debugging On") 47 | if not config["debug"]: 48 | config["debug"] = True 49 | else: 50 | print("Production Mode On, use (--dev) for debugging") 51 | 52 | # Enable/Disable GPU acceleration 53 | if not config["disableGPU"]: 54 | # Virtual machine detection using SystemD 55 | detect_virtual_machine = subprocess.Popen( 56 | ["systemd-detect-virt"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT 57 | ) 58 | detect_nvidia_pci = subprocess.Popen( 59 | "lspci | grep -i --color 'vga\|3d\|2d'", stdout=subprocess.PIPE, stderr=subprocess.STDOUT, 60 | shell=True 61 | ) 62 | virtual = detect_virtual_machine.communicate()[-1] 63 | nvidia_pci = detect_nvidia_pci.communicate()[0].decode("utf-8").lower() 64 | 65 | if config["disableGPU"]: 66 | self.disable_opengl() 67 | print("Disabling GPU, Software Rendering explicitly activated") 68 | else: 69 | if virtual: 70 | # Detect virtual machine 71 | print(f"Virtual machine detected:{virtual}") 72 | self.disable_opengl() 73 | 74 | elif nvidia_pci: 75 | # Detect NVIDIA cards 76 | if "nvidia" in nvidia_pci: 77 | print("NVIDIA falling back to Software Rendering") 78 | self.disable_opengl() 79 | else: 80 | print(f"Virtual Machine:{virtual}") 81 | 82 | if not self.config['webview']['online'] and self.config['webview']['IPC']: 83 | if bindings() == "PyQt5": 84 | from PyQt5.QtWebEngineCore import QWebEngineUrlScheme 85 | else: 86 | from PySide2.QtWebEngineCore import QWebEngineUrlScheme 87 | QWebEngineUrlScheme.registerScheme(QWebEngineUrlScheme("ipc".encode())) 88 | 89 | def _applicationStateChanged_cb(self, event): 90 | view = Instance.retrieve("view") 91 | page = view.page() 92 | # TODO freeze view when inactive to save ram 93 | if event == Qt.ApplicationInactive: 94 | print("inactive") 95 | elif event == Qt.ApplicationActive: 96 | print("active") 97 | 98 | def disable_opengl(self): 99 | # Disable GPU acceleration 100 | # https://codereview.qt-project.org/c/qt/qtwebengine-chromium/+/206307 101 | self.setAAttribute(Qt.AA_UseSoftwareOpenGL) 102 | 103 | def setAAttribute(self, attr): 104 | QCoreApplication.setAttribute(attr, True) 105 | 106 | def run(self): 107 | Instance.record("view", JWebView(self.config)) 108 | win = Instance.auto("win", JWindow(self.config)) 109 | 110 | if self.config['window']["transparent"]: 111 | from JAK.Utils import JavaScript 112 | JavaScript.css( 113 | "body, html {background-color:transparent !important;background-image:none !important;}", "JAK" 114 | ) 115 | 116 | if self.config['webview']["addCSS"]: 117 | from JAK.Utils import JavaScript 118 | JavaScript.css(self.config['webview']["addCSS"], "user") 119 | print("Custom CSS detected") 120 | 121 | if self.config['webview']["runJavaScript"]: 122 | from JAK.Utils import JavaScript 123 | JavaScript.send(self.config['webview']["runJavaScript"]) 124 | print("Custom JavaScript detected") 125 | 126 | if self.config['window']["fullScreen"]: 127 | screen = getScreenGeometry() 128 | win.resize(int(screen.width()), int(screen.height())) 129 | else: 130 | width, height = int(win.default_size("width")), int(win.default_size("height")) 131 | win.resize(width, height) 132 | 133 | win.setFocusPolicy(Qt.WheelFocus) 134 | win.show() 135 | win.setFocus() 136 | win.window_original_position = win.frameGeometry() 137 | self.exec_() 138 | -------------------------------------------------------------------------------- /JAK/DevTools.py: -------------------------------------------------------------------------------- 1 | #### Jade Application Kit 2 | # * https://codesardine.github.io/Jade-Application-Kit 3 | # * Vitor Lopes Copyright (c) 2016 - 2020 4 | # * https://vitorlopes.me 5 | 6 | from JAK.Utils import bindings 7 | if bindings() == "PyQt5": 8 | from PyQt5.QtWebEngineWidgets import QWebEngineView 9 | from PyQt5.QtWidgets import QDockWidget 10 | else: 11 | from PySide2.QtWebEngineWidgets import QWebEngineView 12 | from PySide2.QtWidgets import QDockWidget 13 | 14 | 15 | class WebView(QWebEngineView): 16 | 17 | def __init__(self, parent=None): 18 | QWebEngineView.__init__(self, parent) 19 | 20 | def set_inspected_view(self, view=None): 21 | self.page().setInspectedPage(view.page() if view else None) 22 | 23 | 24 | class InspectorDock(QDockWidget): 25 | 26 | def __init__(self, parent=None): 27 | super().__init__(parent=parent) 28 | title = "Inspector" 29 | self.setWindowTitle(title) 30 | -------------------------------------------------------------------------------- /JAK/IPC.py: -------------------------------------------------------------------------------- 1 | from JAK.Utils import Instance 2 | 3 | 4 | class Bind: 5 | """ 6 | * Usage: from JAK import IPC 7 | * Create your own class and point to this one: IPC.Bind = MyOverrride 8 | """ 9 | @staticmethod 10 | def listen(data): 11 | """ 12 | * Do something with the data. 13 | * :param data: 14 | * :return: url output 15 | """ 16 | raise NotImplementedError() 17 | 18 | 19 | class Communication: 20 | """ 21 | Call python methods from JavaScript. 22 | """ 23 | @staticmethod 24 | def send(url) -> None: 25 | if ":" in url: 26 | url = url.split(':')[1] 27 | if url.endswith("()"): 28 | eval(f"Bind.{url}") 29 | else: 30 | Bind.listen(url) 31 | -------------------------------------------------------------------------------- /JAK/KeyBindings.py: -------------------------------------------------------------------------------- 1 | #### Jade Application Kit 2 | # * https://codesardine.github.io/Jade-Application-Kit 3 | # * Vitor Lopes Copyright (c) 2016 - 2020 4 | # * https://vitorlopes.me 5 | 6 | from JAK.Utils import Instance, bindings 7 | if bindings() == "PyQt5": 8 | from PyQt5.QtCore import Qt 9 | else: 10 | from PySide2.QtCore import Qt 11 | 12 | 13 | class KeyPress: 14 | """ #### Imports: from JAK.Keybindings import KeyPress """ 15 | 16 | def __init__(self, event, config): 17 | # * self.win = QMainWindow Instance 18 | # * self.view = QTWebEngine Instance 19 | if event.type() == event.KeyPress: 20 | if event.key() == Qt.Key_F11: 21 | if config['webview']["online"] is True or config['window']["showHelpMenu"] is True: 22 | self.full_screen() 23 | elif event.key() == Qt.Key_F10: 24 | if config['webview']["online"] is True or config['window']["showHelpMenu"] is True: 25 | self.win = Instance.retrieve("win") 26 | self.win.corner_window() 27 | 28 | elif event.modifiers() == Qt.ControlModifier: 29 | 30 | if event.key() == Qt.Key_Minus: 31 | self._zoom_out() 32 | 33 | elif event.key() == Qt.Key_Equal: 34 | self._zoom_in() 35 | 36 | def _current_zoom(self): 37 | self.view = Instance.retrieve("view") 38 | return self.view.zoomFactor() 39 | 40 | def _zoom_in(self): 41 | new_zoom = self._current_zoom() * 1.5 42 | self.view.setZoomFactor(new_zoom) 43 | self._save_zoom() 44 | 45 | def _zoom_out(self): 46 | new_zoom = self._current_zoom() / 1.5 47 | self.view.setZoomFactor(new_zoom) 48 | self._save_zoom() 49 | 50 | # TODO only zoom to a certain lvl then reset 51 | def _reset_zoom(self): 52 | self.view.setZoomFactor(1) 53 | 54 | def _save_zoom(self): 55 | percent = int(self._current_zoom() * 100) 56 | print(f"Zoom:{percent}%") 57 | # TODO save zoom 58 | 59 | def full_screen(self): 60 | # TODO animate window resize 61 | self.win = Instance.retrieve("win") 62 | if self.win.isFullScreen(): 63 | self.win.showNormal() 64 | self.win.hide_show_bar() 65 | else: 66 | self.win.showFullScreen() 67 | self.win.hide_show_bar() 68 | 69 | -------------------------------------------------------------------------------- /JAK/RequestInterceptor.py: -------------------------------------------------------------------------------- 1 | #### Jade Application Kit 2 | # * https://codesardine.github.io/Jade-Application-Kit 3 | # * Vitor Lopes Copyright (c) 2016 - 2020 4 | # * https://vitorlopes.me 5 | 6 | from JAK.Utils import check_url_rules, bindings 7 | if bindings() == "PyQt5": 8 | from PyQt5.QtWebEngineCore import QWebEngineUrlRequestInterceptor, QWebEngineUrlRequestInfo 9 | else: 10 | from PySide2.QtWebEngineCore import QWebEngineUrlRequestInterceptor, QWebEngineUrlRequestInfo 11 | 12 | 13 | class Interceptor(QWebEngineUrlRequestInterceptor): 14 | #### Imports: from JAK.RequestInterceptor import Interceptor 15 | 16 | def __init__(self, config): 17 | self.config = config 18 | """ 19 | 20 | * :param debug:bool: 21 | * :param block_rules:dict: URL's to block 22 | """ 23 | super(Interceptor, self).__init__() 24 | 25 | def interceptRequest(self, info) -> None: 26 | """ 27 | * All method calls to the profile on the main thread will block until execution of this function is finished. 28 | * :param info: QWebEngineUrlRequestInfo 29 | """ 30 | 31 | if self.config['webview']["urlRules"] is not None: 32 | # If we have any URL's in the block dictionary 33 | url = info.requestUrl().toString() 34 | try: 35 | if check_url_rules("Block", url, self.config['webview']["urlRules"]["block"]): 36 | # block url's 37 | info.block(True) 38 | print(f"Blocked:{url}") 39 | except KeyError: 40 | pass 41 | 42 | if self.config["debug"]: 43 | url = info.requestUrl().toString() 44 | resource = info.resourceType() 45 | if resource == QWebEngineUrlRequestInfo.ResourceType.ResourceTypeMainFrame: 46 | print(f"Intercepted link:{url}") 47 | 48 | elif resource != QWebEngineUrlRequestInfo.ResourceType.ResourceTypeMainFrame: 49 | print(f"Intercepted resource:{url}") 50 | -------------------------------------------------------------------------------- /JAK/Settings.py: -------------------------------------------------------------------------------- 1 | #### Jade Application Kit 2 | # * https://codesardine.github.io/Jade-Application-Kit 3 | # * Vitor Lopes Copyright (c) 2016 - 2020 4 | # * https://vitorlopes.me 5 | from JAK.Utils import bindings 6 | if bindings() == "PyQt5": 7 | from PyQt5.QtCore import Qt 8 | from PyQt5.QtWebEngineWidgets import QWebEngineSettings 9 | else: 10 | from PySide2.QtCore import Qt 11 | from PySide2.QtWebEngineWidgets import QWebEngineSettings 12 | 13 | 14 | def config(): 15 | return { 16 | "debug": False, 17 | "remote-debug": False, 18 | "setAAttribute": (), 19 | "disableGPU": False, 20 | "window": { 21 | "title": "Jade Application Kit", 22 | "icon": None, 23 | "backgroundImage": None, 24 | "setFlags": Qt.Window, 25 | "setAttribute": (), 26 | "state": None, 27 | "fullScreen": False, 28 | "transparent": False, 29 | "toolbar": None, 30 | "menus": None, 31 | "SystemTrayIcon": False, 32 | "showHelpMenu": False, 33 | }, 34 | "webview": { 35 | "webContents": "https://codesardine.github.io/Jade-Application-Kit", 36 | "online": False, 37 | "urlRules": None, 38 | "cookiesPath": None, 39 | "userAgent": None, 40 | "addCSS": None, 41 | "runJavaScript": None, 42 | "IPC": True, 43 | "MediaAudioVideoCapture": False, 44 | "MediaVideoCapture": False, 45 | "MediaAudioCapture": False, 46 | "Geolocation": False, 47 | "MouseLock": False, 48 | "DesktopVideoCapture": False, 49 | "DesktopAudioVideoCapture": False, 50 | "injectJavaScript": { 51 | "JavaScript": None, 52 | "name": "Application Script" 53 | }, 54 | "webChannel": { 55 | "active": False, 56 | "sharedOBJ": None 57 | }, 58 | "enabledSettings": ( 59 | QWebEngineSettings.JavascriptCanPaste, 60 | QWebEngineSettings.FullScreenSupportEnabled, 61 | QWebEngineSettings.AllowWindowActivationFromJavaScript, 62 | QWebEngineSettings.LocalContentCanAccessRemoteUrls, 63 | QWebEngineSettings.JavascriptCanAccessClipboard, 64 | QWebEngineSettings.SpatialNavigationEnabled, 65 | QWebEngineSettings.TouchIconsEnabled 66 | ), 67 | "disabledSettings": ( 68 | QWebEngineSettings.PlaybackRequiresUserGesture 69 | ) 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /JAK/Utils.py: -------------------------------------------------------------------------------- 1 | #### Jade Application Kit 2 | # * https://codesardine.github.io/Jade-Application-Kit 3 | # * Vitor Lopes Copyright (c) 2016 - 2020 4 | # * https://vitorlopes.me 5 | 6 | import os 7 | import re 8 | import subprocess 9 | from pathlib import Path 10 | from PyQt5.QtWidgets import QApplication 11 | 12 | register = {} 13 | 14 | 15 | def create_desktop_entry(url, title, description, icon): 16 | entry_name = title.replace(" ", "-") 17 | filename = f"{entry_name}.desktop" 18 | user_entry_path = f"{str(Path.home())}/.local/share/applications" 19 | # system_entry_path = f"/usr/share/applications/{file}" 20 | 21 | template = f""" 22 | # Created with JAK url:https://github.com/codesardine/Jade-Application-Kit 23 | [Desktop Entry] 24 | Type=Application 25 | Version=1.0 26 | Name={title} 27 | Comment={description} 28 | Path=/usr/bin 29 | Exec=jak-cli --url {url} --title {title} --icon {icon} --online true 30 | Icon={icon} 31 | Terminal=false 32 | Categories=Network; 33 | """.strip() 34 | 35 | with open(f"{user_entry_path}/{filename}", 'w+') as file: 36 | file.write(template) 37 | print(f"Desktop entry created in:{user_entry_path}/{filename}") 38 | 39 | update_database = "update-desktop-database" 40 | if os.path.isfile(f"/usr/bin/{update_database}"): 41 | proc = subprocess.run(f"{update_database} {user_entry_path}", shell=True, check=True) 42 | if proc.returncode == 0: 43 | print("Database updated.") 44 | else: 45 | print("desktop-file-utils:Not installed\nDatabase not updated.") 46 | 47 | 48 | def getScreenGeometry(): 49 | return QApplication.instance().desktop().screenGeometry() 50 | 51 | 52 | def bindings(): 53 | environment_var = "JAK_PREFERRED_BINDING" 54 | try: 55 | preferred_bindings = os.environ[environment_var] 56 | return preferred_bindings 57 | except KeyError: 58 | user_config_path = f"{str(Path.home())}/.config/jak.conf" 59 | if os.path.isfile(user_config_path): 60 | config_file = user_config_path 61 | else: 62 | system_config_path = "/etc/jak.conf" 63 | config_file = system_config_path 64 | try: 65 | import configparser 66 | config = configparser.ConfigParser() 67 | config.read(config_file) 68 | preferred_bindings = config["bindings"][environment_var] 69 | return preferred_bindings 70 | except Exception as error: 71 | print(error) 72 | 73 | 74 | def get_current_path(): 75 | return str(Path('.').absolute()) 76 | 77 | 78 | def check_url_rules(request_type: str, url_request: str, url_rules: tuple) -> bool: 79 | """ 80 | * Search logic for url rules, we can use regex or simple match the beginning of the domain. 81 | * :param request_type: WebWindowType 82 | * :return: function, checks against a list of urls 83 | """ 84 | SCHEME = "https://" 85 | 86 | if request_type == "Block": 87 | url_rules=url_rules 88 | 89 | elif request_type == "WebBrowserTab": 90 | try: 91 | url_rules = url_rules["WebBrowserTab"] 92 | except KeyError: 93 | url_rules = "" 94 | 95 | elif request_type == "WebBrowserWindow": 96 | try: 97 | url_rules = url_rules["WebBrowserWindow"] 98 | except KeyError: 99 | url_rules = "" 100 | 101 | for rule in url_rules: 102 | pattern = re.compile(f"{SCHEME}{rule}") 103 | if url_request.startswith(f"{SCHEME}{rule}"): 104 | print(f"{SCHEME}{rule}:Method:startswith") 105 | return True 106 | elif re.search(pattern, url_request): 107 | print(f"{SCHEME}{rule}:Method:regex") 108 | return True 109 | return False 110 | 111 | 112 | class Instance: 113 | """ 114 | #### :Imports: from JAK.Utils import Instance 115 | Add object instances in a dictionary, it can be used to point 116 | to references we don,t want to be garbage collected, for usage later 117 | """ 118 | 119 | @staticmethod 120 | def get_instances() -> dict: 121 | """ 122 | * :Usage: Instance.get_instances() 123 | """ 124 | return register 125 | 126 | @staticmethod 127 | def record(name: str, _type: object) -> None: 128 | """ 129 | * :Usage: Instance.record("name", object) 130 | * Should only be used once per instance 131 | """ 132 | register[name] = _type 133 | print(f"Registering ['{name}'] Instance") 134 | 135 | @staticmethod 136 | def retrieve(name: str) -> object or str: 137 | """ 138 | * :Usage: Instance.retrieve("name") 139 | """ 140 | try: 141 | return register[name] 142 | except KeyError: 143 | print(f"Instance: ['{name}'] Not Present, to add it use -> Instance.record(['{name}', object])") 144 | return "" 145 | 146 | @staticmethod 147 | def auto(name: str, _type: object) -> object: 148 | """ 149 | * :Usage: Instance.auto("name", object) 150 | * Automatically detects if an instance is active with that name and retrieves it. 151 | If not present, creates it creates a new one and retrieves it. 152 | * Should only be used once per instance 153 | """ 154 | try: 155 | return register[name] 156 | except KeyError: 157 | register[name] = _type 158 | finally: 159 | print(f"Registering and Retrieving ['{name}'] Instance") 160 | return register[name] 161 | 162 | 163 | class JavaScript: 164 | """ 165 | * Run javascript in the webview after load is complete Injects will be logged in the inspector 166 | * :Imports: from Jak.Utils import JavaScript 167 | * :Usage: JavaScript.log(msg) 168 | """ 169 | @staticmethod 170 | def log(message: str) -> None: 171 | """ 172 | * Outputs console.log() messages in the inspector 173 | * :param message: Log message 174 | """ 175 | JavaScript.send(f"console.log('JAK log:{message}');") 176 | 177 | @staticmethod 178 | def css(styles: str, _type) -> None: 179 | """ 180 | * Insert custom styles 181 | * :param styles: CSS -> a { color: red; } 182 | """ 183 | javascript = f""" 184 | var style = document.createElement('style'); 185 | style.type = 'text/css'; 186 | style.classList.add('{_type}-custom-style'); 187 | style.innerHTML = `{JavaScript._is_file_or_string(styles)}`; 188 | document.getElementsByTagName('head')[0].appendChild(style); 189 | """ 190 | view = Instance.retrieve("view") 191 | view.page().loadFinished.connect( 192 | lambda: view.page().runJavaScript(javascript) 193 | ) 194 | 195 | @staticmethod 196 | def alert(message: str) -> None: 197 | """ 198 | * Triggers an alert message 199 | * :param message: your popcorn is ready enjoy 200 | """ 201 | JavaScript.send(f"alert('{message}');") 202 | JavaScript.log(f"JAK Alert:[{message}]") 203 | 204 | @staticmethod 205 | def send(script: str) -> None: 206 | """ 207 | * Send custom JavaScript 208 | """ 209 | try: 210 | view = Instance.retrieve("view") 211 | view.page().runJavaScript(f"{JavaScript._is_file_or_string(script)}") 212 | except Exception as err: 213 | print(err) 214 | 215 | @staticmethod 216 | def inject(page, options: dict) -> None: 217 | if bindings() == "PyQt5": 218 | from PyQt5.QtWebEngineWidgets import QWebEngineScript 219 | else: 220 | from PySide2.QtWebEngineWidgets import QWebEngineScript 221 | 222 | script = QWebEngineScript() 223 | script.setName(options["name"]) 224 | script.setWorldId(QWebEngineScript.MainWorld) 225 | script.setInjectionPoint(QWebEngineScript.DocumentCreation) 226 | script.setRunsOnSubFrames(True) 227 | script.setSourceCode(options["JavaScript"]) 228 | print(f"Injecting JavaScript {options['name']}") 229 | page.profile().scripts().insert(script) 230 | 231 | @staticmethod 232 | def _is_file_or_string(script) -> str: 233 | """ 234 | * Detect if is file or string, convert to string 235 | * :param script: file or string 236 | """ 237 | if os.path.exists(script) and os.path.isfile(script): 238 | try: 239 | with open(script, "r") as file: 240 | string = file.read() 241 | return string 242 | except Exception as err: 243 | print(err) 244 | elif isinstance(script, str): 245 | return script 246 | -------------------------------------------------------------------------------- /JAK/WebEngine.py: -------------------------------------------------------------------------------- 1 | #### Jade Application Kit 2 | # * https://codesardine.github.io/Jade-Application-Kit 3 | # * Vitor Lopes Copyright (c) 2016 - 2020 4 | # * https://vitorlopes.me 5 | import os 6 | from functools import lru_cache as cache 7 | from JAK.Utils import check_url_rules, get_current_path, bindings 8 | from JAK.Widgets import Dialog 9 | from JAK.RequestInterceptor import Interceptor 10 | if bindings() == "PyQt5": 11 | from PyQt5.QtCore import QUrl, Qt 12 | from PyQt5.QtWebEngineCore import QWebEngineUrlSchemeHandler 13 | from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEngineProfile, QWebEnginePage, QWebEngineSettings 14 | else: 15 | from PySide2.QtCore import QUrl, Qt 16 | from PySide2.QtWebEngineCore import QWebEngineUrlSchemeHandler 17 | from PySide2.QtWebEngineWidgets import QWebEngineView, QWebEngineProfile, QWebEnginePage, QWebEngineSettings 18 | 19 | 20 | @cache(maxsize=5) 21 | def validate_url(self, url: str) -> None: 22 | """ 23 | * Check if is a URL or HTML and if is valid 24 | * :param self: QWebEnginePage 25 | * :param web_contents: URL or HTML 26 | """ 27 | if "!doctype" in url.lower(): 28 | # Inject HTML 29 | base_url = get_current_path() 30 | self.setHtml(url, QUrl(f"file://{base_url}/")) 31 | print("Loading local HTML") 32 | else: 33 | if url.endswith(".html"): 34 | # HTML file 35 | if not url.startswith("/"): 36 | url = f"/{url}" 37 | url = f"file://{url}" 38 | 39 | elif "://" not in url: 40 | # HTML URL 41 | url = f"https://{url}" 42 | 43 | url = QUrl(url) 44 | if url.isValid(): 45 | self.load(url) 46 | print(f"Loading URL:{url.toString()}") 47 | 48 | 49 | class IpcSchemeHandler(QWebEngineUrlSchemeHandler): 50 | def __init__(self): 51 | super().__init__() 52 | 53 | def requestStarted(self, request): 54 | url = request.requestUrl().toString() 55 | if url.startswith("ipc:"): 56 | # * Link's that starts with [ ipc:somefunction() ] trigger's the two way communication system between 57 | # HTML and Python, only if online is set to false 58 | from JAK.IPC import Communication 59 | Communication.send(url) 60 | return 61 | 62 | 63 | class JWebPage(QWebEnginePage): 64 | """ #### Imports: from JAK.WebEngine import JWebPage """ 65 | def __init__(self, profile, webview, config): 66 | self.config = config 67 | super(JWebPage, self).__init__(profile, webview) 68 | self.featurePermissionRequested.connect(self._on_feature_permission_requested) 69 | 70 | def _open_in_browser(self) -> None: 71 | """ Open url in a external browser """ 72 | print("Open above^ tab in Browser") 73 | from webbrowser import open_new_tab 74 | open_new_tab(self.url) 75 | 76 | def _dialog_open_in_browser(self) -> None: 77 | """ Opens a dialog to confirm if user wants to open url in external browser """ 78 | msg = "Open In Your Browser" 79 | Dialog.question(self.parent(), self.title(), msg, self._open_in_browser) 80 | 81 | @cache(maxsize=10) 82 | def acceptNavigationRequest(self, url, _type, is_main_frame) -> bool: 83 | """ 84 | * Decide if we navigate to a URL 85 | * :param url: QtCore.QUrl 86 | * :param _type: QWebEnginePage.NavigationType 87 | * :param is_main_frame:bool 88 | """ 89 | self.url = url.toString() 90 | self.page = JWebPage(self.profile(), self.view(), self.config) 91 | # Redirect new tabs to same window 92 | self.page.urlChanged.connect(self._on_url_changed) 93 | 94 | if self.config['webview']["online"]: 95 | if _type == QWebEnginePage.WebWindowType.WebBrowserTab: 96 | if self.config['webview']["urlRules"]: 97 | # Check for URL rules on new tabs 98 | if self.url.startswith(self.config['webview']["urlRules"]["WebBrowserTab"]): 99 | self.open_window(self.url) 100 | return False 101 | elif check_url_rules("WebBrowserTab", self.url, self.config['webview']["urlRules"]): 102 | print(f"Redirecting WebBrowserTab^ to same window") 103 | return True 104 | else: 105 | print(f"Deny WebBrowserTab:{self.url}") 106 | # check against WebBrowserWindow list to avoid duplicate dialogs 107 | if not check_url_rules("WebBrowserWindow", self.url, self.config['webview']["urlRules"]): 108 | self._dialog_open_in_browser() 109 | return False 110 | else: 111 | return True 112 | 113 | elif _type == QWebEnginePage.WebBrowserBackgroundTab: 114 | print(f"WebBrowserBackgroundTab request:{self.url}") 115 | return True 116 | 117 | elif _type == QWebEnginePage.WebBrowserWindow: 118 | if self.config['webview']["urlRules"] and self.config['webview']["online"]: 119 | # Check URL rules on new windows 120 | if check_url_rules("WebBrowserWindow", self.url, self.config['webview']["urlRules"]): 121 | print(f"Deny WebBrowserWindow:{self.url}") 122 | self._dialog_open_in_browser() 123 | return False 124 | else: 125 | print(f"Allow WebBrowserWindow:{self.url}") 126 | return True 127 | else: 128 | return True 129 | 130 | elif _type == QWebEnginePage.WebDialog: 131 | return True 132 | return True 133 | 134 | def _on_feature_permission_requested(self, security_origin, feature): 135 | 136 | def grant_permission(): 137 | self.setFeaturePermission(security_origin, feature, self.PermissionGrantedByUser) 138 | 139 | def deny_permission(): 140 | self.setFeaturePermission(security_origin, feature, self.PermissionDeniedByUser) 141 | 142 | if feature == self.Notifications: 143 | grant_permission() 144 | elif feature == self.MediaAudioVideoCapture and self.config['webview']["MediaAudioVideoCapture"]: 145 | grant_permission() 146 | elif feature == self.MediaVideoCapture and self.config['webview']["MediaVideoCapture"]: 147 | grant_permission() 148 | elif feature == self.MediaAudioCapture and self.config['webview']["MediaAudioCapture"]: 149 | grant_permission() 150 | elif feature == self.Geolocation and self.config['webview']["Geolocation"]: 151 | grant_permission() 152 | elif feature == self.MouseLock and self.config['webview']["MouseLock"]: 153 | grant_permission() 154 | elif feature == self.DesktopVideoCapture and self.config['webview']["DesktopVideoCapture"]: 155 | grant_permission() 156 | elif feature == self.DesktopAudioVideoCapture and self.config['webview']["DesktopAudioVideoCapture"]: 157 | grant_permission() 158 | else: 159 | deny_permission() 160 | 161 | def open_window(self, url): 162 | """ Open a New Window""" 163 | # FIXME cookies path needs to be declared for this to work 164 | self.popup = JWebView(self.config) 165 | self.popup.page().windowCloseRequested.connect(self.popup.close) 166 | self.popup.show() 167 | print(f"Opening New Window^") 168 | 169 | @cache(maxsize=2) 170 | def createWindow(self, _type: object) -> QWebEnginePage: 171 | """ 172 | * Redirect new window's or tab's to same window 173 | * :param _type: QWebEnginePage.WebWindowType 174 | """ 175 | return self.page 176 | 177 | def _on_url_changed(self, url: str) -> None: 178 | url = url.toString() 179 | if url == "about:blank": 180 | return False 181 | else: 182 | validate_url(self, url) 183 | 184 | 185 | class JWebView(QWebEngineView): 186 | """ #### Imports: from JAK.WebEngine import JWebView """ 187 | def __init__(self, config): 188 | self.config = config 189 | super(JWebView, self).__init__() 190 | self.setAttribute(Qt.WA_DeleteOnClose, True) 191 | self.profile = QWebEngineProfile.defaultProfile() 192 | self.webpage = JWebPage(self.profile, self, config) 193 | self.setPage(self.webpage) 194 | if config['webview']["injectJavaScript"]["JavaScript"]: 195 | self._inject_script(config['webview']["injectJavaScript"]) 196 | self.interceptor = Interceptor(config) 197 | 198 | if config['webview']["userAgent"]: 199 | # Set user agent 200 | self.profile.setHttpUserAgent(config['webview']["userAgent"]) 201 | 202 | if config["debug"]: 203 | self.settings().setAttribute(QWebEngineSettings.XSSAuditingEnabled, True) 204 | else: 205 | self.setContextMenuPolicy(Qt.PreventContextMenu) 206 | 207 | if config['window']["transparent"]: 208 | # Activates background transparency 209 | self.setAttribute(Qt.WA_TranslucentBackground) 210 | self.page().setBackgroundColor(Qt.transparent) 211 | print("Transparency detected") 212 | 213 | # * Set Engine options 214 | self.settings().setAttribute(self.config['webview']['disabledSettings'], False) 215 | for setting in self.config['webview']['enabledSettings']: 216 | self.settings().setAttribute(setting, True) 217 | 218 | if config['webview']["online"]: 219 | self.settings().setAttribute(QWebEngineSettings.DnsPrefetchEnabled, True) 220 | print("Engine online IPC and Bridge Disabled") 221 | self.page().profile().downloadRequested.connect(self._download_requested) 222 | 223 | # Set persistent cookies 224 | self.profile.setPersistentCookiesPolicy(QWebEngineProfile.ForcePersistentCookies) 225 | 226 | # set cookies on user folder 227 | if config['webview']["cookiesPath"]: 228 | # allow specific path per application. 229 | _cookies_path = f"{os.getenv('HOME')}/.jak/{config['webview']['cookiesPath']}" 230 | else: 231 | # use separate cookies database per application 232 | title = config['window']["title"].lower().replace(" ", "-") 233 | _cookies_path = f"{os.getenv('HOME')}/.jak/{title}" 234 | 235 | self.profile.setPersistentStoragePath(_cookies_path) 236 | print(f"Cookies PATH:{_cookies_path}") 237 | else: 238 | self.settings().setAttribute(QWebEngineSettings.ShowScrollBars, False) 239 | application_script = "const JAK = {};" 240 | 241 | if config['webview']["IPC"]: 242 | print("IPC Active:") 243 | self._ipc_scheme_handler = IpcSchemeHandler() 244 | self.profile.installUrlSchemeHandler('ipc'.encode(), self._ipc_scheme_handler) 245 | application_script += """JAK.IPC = function(backendFunction) { 246 | window.location.href = "ipc:" + backendFunction; 247 | };""" 248 | 249 | if config['webview']["webChannel"]["active"]: 250 | if bindings() == "PyQt5": 251 | from PyQt5.QtCore import QFile, QIODevice 252 | from PyQt5.QtWebChannel import QWebChannel 253 | else: 254 | from PySide2.QtCore import QFile, QIODevice 255 | from PySide2.QtWebChannel import QWebChannel 256 | 257 | webchannel_js = QFile(':/qtwebchannel/qwebchannel.js') 258 | webchannel_js.open(QIODevice.ReadOnly) 259 | webchannel_js = bytes(webchannel_js.readAll()).decode('utf-8') 260 | webchannel_js += """new QWebChannel(qt.webChannelTransport, function (channel) { 261 | JAK.Bridge = channel.objects.Bridge; 262 | });""" 263 | 264 | application_script += webchannel_js 265 | self._inject_script({"JavaScript": application_script, "name": "JAK"}) 266 | channel = QWebChannel(self.page()) 267 | if config['webview']["webChannel"]["sharedOBJ"]: 268 | bridge_obj = config['webview']["webChannel"]["sharedOBJ"] 269 | else: 270 | raise NotImplementedError("QWebChannel shared QObject") 271 | 272 | channel.registerObject("Bridge", bridge_obj) 273 | self.page().setWebChannel(channel) 274 | print("WebChannel Active:") 275 | else: 276 | self._inject_script({"JavaScript": application_script, "name": "JAK"}) 277 | 278 | self.profile.setRequestInterceptor(self.interceptor) 279 | print(self.profile.httpUserAgent()) 280 | validate_url(self, config['webview']["webContents"]) 281 | 282 | def _inject_script(self, script: dict): 283 | from JAK.Utils import JavaScript 284 | JavaScript.inject(self.page(), script) 285 | 286 | def dropEvent(self, *args): 287 | # disable drop event 288 | pass 289 | 290 | def _download_requested(self, download_item) -> None: 291 | """ 292 | * If a download is requested call a save file dialog 293 | * :param download_item: file to be downloaded 294 | """ 295 | if bindings() == "PyQt5": 296 | from PyQt5.QtWidgets import QFileDialog 297 | else: 298 | from PySide2.QtWidgets import QFileDialog 299 | dialog = QFileDialog(self) 300 | path = dialog.getSaveFileName(dialog, "Save File", download_item.path()) 301 | 302 | if path[0]: 303 | download_item.setPath(path[0]) 304 | print(f"downloading file to:( {download_item.path()} )") 305 | download_item.accept() 306 | self.download_item = download_item 307 | download_item.finished.connect(self._download_finished) 308 | else: 309 | print("Download canceled") 310 | 311 | def _download_finished(self) -> None: 312 | """ 313 | Goes to previous page and pops an alert informing the user that the download is finish and were to find it 314 | """ 315 | file_path = self.download_item.path() 316 | msg = f"File Downloaded to: {file_path}" 317 | Dialog.information(self, "Download Complete", msg) 318 | -------------------------------------------------------------------------------- /JAK/Widgets.py: -------------------------------------------------------------------------------- 1 | #### Jade Application Kit 2 | # * https://codesardine.github.io/Jade-Application-Kit 3 | # * Vitor Lopes Copyright (c) 2016 - 2020 4 | # * https://vitorlopes.me 5 | 6 | import os 7 | from JAK.Utils import Instance, bindings, getScreenGeometry 8 | from JAK.KeyBindings import KeyPress 9 | if bindings() == "PyQt5": 10 | from PyQt5.QtCore import Qt, QSize, QUrl 11 | from PyQt5.QtGui import QIcon, QPixmap, QImage 12 | from PyQt5.QtWidgets import QMainWindow, QWidget, QMessageBox, QSystemTrayIcon,\ 13 | QAction, QToolBar, QMenu, QMenuBar, QFileDialog, QLabel 14 | else: 15 | from PySide2.QtCore import Qt, QSize, QUrl 16 | from PySide2.QtGui import QIcon, QPixmap, QImage 17 | from PySide2.QtWidgets import QMainWindow, QWidget, QMessageBox, QSystemTrayIcon,\ 18 | QAction, QToolBar, QMenu, QMenuBar, QFileDialog, QLabel 19 | 20 | 21 | class SystemTrayIcon(QSystemTrayIcon): 22 | def __init__(self, icon, app, config): 23 | self.config = config 24 | self.icon = icon 25 | super(SystemTrayIcon, self).__init__(icon, parent=app) 26 | self.setContextMenu(self.tray_menu()) 27 | self.show() 28 | 29 | def tray_menu(self): 30 | """ 31 | Create menu for the tray icon 32 | """ 33 | self.menu = QMenu() 34 | for item in self.config['window']["SystemTrayIcon"]: 35 | try: 36 | self.action = QAction(f"{item['title']}", self) 37 | self.action.triggered.connect(item['action']) 38 | if item['icon']: 39 | self.action.setIcon(QIcon(QPixmap(item['icon']))) 40 | self.menu.addAction(self.action) 41 | except KeyError: 42 | pass 43 | return self.menu 44 | 45 | 46 | class JWindow(QMainWindow): 47 | """ #### Imports: from JAK.Widgets import JWindow """ 48 | def __init__(self, config): 49 | super().__init__() 50 | self.config = config 51 | if config["window"]["backgroundImage"]: 52 | # Transparency must be set to True 53 | self.label = QLabel(self) 54 | self.setObjectName("JAKWindow") 55 | self.setBackgroundImage(config["window"]["backgroundImage"]) 56 | self.video_corner = False 57 | self.center = getScreenGeometry().center() 58 | self.setWindowTitle(config['window']["title"]) 59 | self.setWindowFlags(config['window']["setFlags"]) 60 | self.setWAttribute(Qt.WA_DeleteOnClose) 61 | for attr in config['window']["setAttribute"]: 62 | self.setWAttribute(attr) 63 | 64 | if config['window']["state"]: 65 | self.setWindowState(config['window']["state"]) 66 | 67 | if config['window']["icon"] and os.path.isfile(config['window']["icon"]): 68 | self.icon = QIcon(config['window']["icon"]) 69 | else: 70 | print(f"icon not found: {config['window']['icon']}") 71 | print("loading default icon:") 72 | self.icon = QIcon.fromTheme("applications-internet") 73 | 74 | view = Instance.retrieve("view") 75 | if view: 76 | self.view = view 77 | self.setCentralWidget(self.view) 78 | self.view.iconChanged.connect(self._icon_changed) 79 | if config['webview']["online"]: 80 | self.view.page().titleChanged.connect(self.status_message) 81 | 82 | if config['window']["transparent"]: 83 | # Set Background Transparency 84 | self.setWAttribute(Qt.WA_TranslucentBackground) 85 | self.setAutoFillBackground(True) 86 | 87 | if config['webview']["online"]: 88 | # Do not display toolbar or system tray offline 89 | if config['window']["toolbar"]: 90 | self.toolbar = JToolbar(self, config['window']["toolbar"], self.icon, config['window']["title"]) 91 | self.addToolBar(self.toolbar) 92 | self.setMenuBar(Menu(self, config['window']["menus"])) 93 | else: 94 | if config['window']["showHelpMenu"]: 95 | self.setMenuBar(Menu(self, config['window']["menus"])) 96 | self.view.page().titleChanged.connect(self.status_message) 97 | 98 | if config['window']["SystemTrayIcon"]: 99 | self.system_tray = SystemTrayIcon(self.icon, self, config) 100 | 101 | if config["debug"]: 102 | self.showInspector() 103 | self._set_icons() 104 | 105 | def setBackgroundImage(self, image): 106 | screen = getScreenGeometry() 107 | pixmap = QPixmap(QImage(image)).scaled(screen.width(), screen.height(), Qt.KeepAspectRatioByExpanding) 108 | self.label.setPixmap(pixmap) 109 | self.label.setGeometry(0, 0, screen.width(), self.label.sizeHint().height()) 110 | 111 | def showInspector(self): 112 | from JAK.DevTools import WebView, InspectorDock 113 | self.inspector_dock = InspectorDock(self) 114 | self.inspector_view = WebView(parent=self) 115 | self.inspector_view.set_inspected_view(self.view) 116 | self.inspector_dock.setWidget(self.inspector_view) 117 | self.addDockWidget(Qt.TopDockWidgetArea, self.inspector_dock) 118 | 119 | def hideInspector(self): 120 | self.inspector_dock.hide() 121 | 122 | def setWAttribute(self, attr): 123 | self.setAttribute(attr, True) 124 | 125 | def keyPressEvent(self, event): 126 | KeyPress(event, self.config) 127 | 128 | def _set_icons(self): 129 | self.setWindowIcon(self.icon) 130 | if self.config['window']["SystemTrayIcon"]: 131 | self.system_tray.setIcon(self.icon) 132 | 133 | def _icon_changed(self): 134 | if not self.view.icon().isNull(): 135 | self.icon = self.view.icon() 136 | self._set_icons() 137 | 138 | def status_message(self): 139 | # Show status message 140 | self.statusbar = self.statusBar() 141 | self.statusbar.showMessage(self.view.page().title(), 10000) 142 | 143 | def hide_show_bar(self): 144 | if self.isFullScreen() or self.video_corner: 145 | self.statusbar.hide() 146 | if self.config['window']["toolbar"]: 147 | self.toolbar.hide() 148 | else: 149 | self.statusbar.show() 150 | if self.config['window']["toolbar"]: 151 | self.toolbar.show() 152 | 153 | def default_size(self, size: str): 154 | # Set to 70% screen size 155 | screen = getScreenGeometry() 156 | if size == "width": 157 | return screen.width() * 2 / 3 158 | elif size == "height": 159 | return screen.height() * 2 / 3 160 | 161 | def set_window_to_defaults(self): 162 | self.window_original_position.moveCenter(self.center) 163 | self.move(self.window_original_position.topLeft()) 164 | self.resize(self.default_size("width"), self.default_size("height")) 165 | self.hide_show_bar() 166 | self.setWindowFlags(Qt.Window) 167 | self.show() 168 | 169 | def set_window_to_corner(self): 170 | self.move(self.window_original_position.bottomRight()) 171 | # Set to 30% screen size 172 | screen = getScreenGeometry() 173 | self.resize(screen.width() * 0.7 / 2, screen.height() * 0.7 / 2) 174 | self.hide_show_bar() 175 | self.setWindowFlags(Qt.SplashScreen | Qt.WindowStaysOnTopHint) 176 | self.show() 177 | 178 | def corner_window(self): 179 | if self.video_corner: 180 | self.video_corner = False 181 | self.set_window_to_defaults() 182 | else: 183 | self.video_corner = True 184 | if self.isFullScreen(): 185 | self.showNormal() 186 | self.set_window_to_corner() 187 | 188 | 189 | class JToolbar(QToolBar): 190 | """ #### Imports: from JAK.Widgets import JToolbar """ 191 | def __init__(self, parent, toolbar, icon, title): 192 | """ 193 | * :param parent: Parent window 194 | * :param toolbar:dict 195 | * :param icon:str 196 | * :param title:str 197 | """ 198 | super(JToolbar, self).__init__(parent) 199 | self.icon = icon 200 | self.setMovable(False) 201 | self.setContextMenuPolicy(Qt.PreventContextMenu) 202 | self.setIconSize(QSize(32, 32)) 203 | self.about_title = "About" 204 | 205 | if toolbar: 206 | # If a dict is passed generate buttons from dict 207 | for btn in toolbar: 208 | try: 209 | if btn["icon"]: 210 | item = QAction(QIcon(btn["icon"]), btn["name"], self) 211 | except KeyError: 212 | item = QAction(btn["name"], self) 213 | 214 | item.triggered.connect(self._on_click(btn["url"])) 215 | self.addAction(item) 216 | 217 | def _on_click(self, url: str, title=""): 218 | view = Instance.retrieve("view") 219 | if url.startswith("https"): 220 | return lambda: view.setUrl(QUrl(url)) 221 | else: 222 | msg = url 223 | return lambda: Dialog.information(self, title, msg) 224 | 225 | 226 | class Menu(QMenuBar): 227 | 228 | def __init__(self, parent, menus): 229 | 230 | super(Menu, self).__init__(parent) 231 | if menus: 232 | for menu in menus: 233 | if type(menu) is dict: 234 | title = self.addMenu(menu["title"]) 235 | for entry in menu["entries"]: 236 | submenu = QAction(entry[0], self) 237 | title.addAction(submenu) 238 | print(entry[1]) 239 | submenu.triggered.connect(self._on_click(entry[1])) 240 | 241 | help_menu = {"title": "Keyboard Shortcuts", "text": """ 242 | 243 | F11           Toggle Full Screen 244 |
245 | F10           Toggle Corner Window 246 |
247 | CTRL +     Zoom In 248 |
249 | CTRL -     Zoom Out 250 | 251 | """},\ 252 | {"title": "About JAK", "text": """ 253 | 254 | 255 | This online application is copyright and ownership of their respective authors. 256 |

257 | This wrapper offers the ability to run web applications, as a self contained native desktop application. 258 | Enjoy. 259 |
260 |
261 |
262 | 263 | Powered by: 264 | 265 | Jade Application Kit
266 | 267 | Native Hybrid Apps on Linux. 268 |
269 | 270 | Using QT WebEngine 271 | 272 |
273 |
274 | 275 |
276 | This application comes with no warranty. License: GPL 277 |
278 | Author:Vitor Lopes 279 |
280 |
281 | 282 | """} 283 | 284 | _help = self.addMenu("Help") 285 | for entry in help_menu: 286 | submenu = QAction(entry["title"], self) 287 | submenu.triggered.connect(self._on_click(entry["text"], entry["title"])) 288 | _help.addAction(submenu) 289 | 290 | def _on_click(self, url: str, title=""): 291 | if url.startswith("https"): 292 | view = Instance.retrieve("view") 293 | return lambda: view.setUrl(QUrl(url)) 294 | 295 | elif url.endswith("()"): 296 | from JAK import IPC 297 | return lambda: IPC.Communication.send(url) 298 | else: 299 | msg = url 300 | return lambda: Dialog.information(self, title, msg) 301 | 302 | 303 | class Dialog: 304 | @staticmethod 305 | def question(parent, title, msg, on_confirm=""): 306 | reply = QMessageBox.question(parent, title, msg, QMessageBox.Yes | QMessageBox.No, QMessageBox.No) 307 | if reply == QMessageBox.Yes: 308 | on_confirm() 309 | 310 | @staticmethod 311 | def information(parent, title, msg): 312 | QMessageBox.information(parent, title, msg) 313 | 314 | 315 | class FileChooserDialog(QWidget): 316 | 317 | def __init__(self, parent=None, file_type="", title="Choose a File"): 318 | super().__init__(parent) 319 | self.file_type = file_type 320 | self.title = title 321 | self.show() 322 | 323 | def choose_file(self): 324 | dialog = QFileDialog() 325 | options = dialog.Options() 326 | file_name = dialog.getOpenFileName( 327 | self, self.title, os.environ['HOME'], 328 | f"{self.file_type.upper()} Files ({self.file_type})", 329 | options=options) 330 | if file_name[0]: 331 | return file_name[0] 332 | 333 | self.hide() 334 | self.destroy() 335 | -------------------------------------------------------------------------------- /JAK/__init__.py: -------------------------------------------------------------------------------- 1 | __version__ = "v3.5.6" 2 | print(f"JAK {__version__}") 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include LICENSE README.rst 2 | recursive-include docs * 3 | recursive-include j * 4 | recursive-include bin * 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Just Another Desktop Environment Application Kit ( JAK ) 2 | 3 | Build web wrappers or hybrid web/desktop applications on Linux, using Python/JavaScript/HTML5/CSS3 powered by [QTWebengine](https://wiki.qt.io/QtWebEngine). Using web technologies we can create beautiful User Interfaces using a diverse amount of available library's and frameworks. 4 | 5 | [![Codacy Badge](https://api.codacy.com/project/badge/Grade/c79991176d484d50960a36007749b6a6)](https://www.codacy.com/app/codesardine/Jade-Application-Kit?utm_source=github.com&utm_medium=referral&utm_content=codesardine/Jade-Application-Kit&utm_campaign=Badge_Grade) 6 | [![Build Status](https://travis-ci.org/codesardine/Jade-Application-Kit.svg?branch=master)](https://travis-ci.org/codesardine/Jade-Application-Kit) 7 | [![PyPI version](https://badge.fury.io/py/Jade-Application-Kit.svg)](https://badge.fury.io/py/Jade-Application-Kit) 8 | [![Gitter chat](https://badges.gitter.im/gitterHQ/gitter.png)](https://gitter.im/JustAnotherDesktopEnviroment/Lobby) 9 | ![release](https://img.shields.io/github/release/codesardine/jade-application-kit.svg) 10 | ![License](https://img.shields.io/github/license/codesardine/jade-application-kit.svg) 11 | 12 | [![Packaging status](https://repology.org/badge/vertical-allrepos/python:jade-application-kit.svg)](https://repology.org/metapackage/python:jade-application-kit) 13 | 14 | ## Getting Started 15 | 16 | * Prerequisites 17 | * Python >= 3.8 18 | * PySide2 >= 5.14 or PyQt5 >= 5.13 19 | * desktop-file-utils, for application.desktop creation: optional 20 | 21 | ```bash 22 | git clone https://github.com/codesardine/Jade-Application-Kit.git 23 | 24 | cd Jade-Application-Kit 25 | ``` 26 | 27 | Install using pip 28 | ```bash 29 | pip3 install -r requirements.txt 30 | ``` 31 | or 32 | ```bash 33 | pip3 install Jade-Application-Kit 34 | ``` 35 | 36 | Install manually 37 | ```bash 38 | ~/.virtualenv/python3 setup.py install 39 | ``` 40 | or 41 | ```bash 42 | sudo python3 setup.py install 43 | ``` 44 | 45 | Install in Manjaro 46 | ```bash 47 | sudo pacman -S python-jade-application-kit 48 | ``` 49 | 50 | ## Environment variables 51 | JAK defaults to using PySide2 to use PyQt5 set this environment variable, this is read before the config file. 52 | ``` 53 | export JAK_PREFERRED_BINDING=PyQt5 54 | ``` 55 | 56 | ## Config file 57 | Setting bindings via config file, system wide is fetched last. 58 | * User file location = /username/.config/jak.conf 59 | * System wide location = /etc/jak.conf 60 | 61 | Config file contents. 62 | ``` 63 | [bindings] 64 | JAK_PREFERRED_BINDING = PyQt5 65 | ``` 66 | 67 | ## Contributing 68 | Please read [CONTRIBUTING.md](https://github.com/codesardine/Jade-Application-Kit/blob/master/CONTRIBUTING.md) for details on code of conduct, and the process for submitting pull requests. 69 | 70 | ## Using from the command line 71 | With the command line utility you can create a self-contained web wrapper's in a question of seconds. 72 | ``` 73 | jak-cli --url https://my-web-app-url --title Mytitle 74 | ``` 75 | Creating Desktop files in the user directory ( ~/.local/share/applications ). 76 | ``` 77 | jak-cli --url https://slack.com --title Slack --cde --desc "Collaboration software for connected teams." 78 | ``` 79 | More options. 80 | ``` 81 | jak-cli --help 82 | ``` 83 | 84 | ## Using Python 85 | ``` 86 | #!/usr/bin/env python 87 | from JAK.Application import JWebApp 88 | 89 | url = "https://my-web-app-url" 90 | 91 | webapp = JWebApp(title="Mytitle", online=True, web_contents=url) 92 | 93 | webapp.run() 94 | ``` 95 | ### URL Rules: 96 | * We can match domains by starting letters or using Python regex. 97 | * Block Rules: blocks any domain in the list. 98 | * WebBrowserWindow Rules: deny any domain in the list. 99 | * WebBrowserTab Rules: only allow domains in the list, if empty all are allowed, if they start with https:// they open in a new window. 100 | 101 | Looking for wrapper's examples? Check [Branches](https://github.com/codesardine/Jade-Application-Kit/branches) starting with `wrapper/`. 102 | 103 | #### Api 104 | * [Application](https://codesardine.github.io/Jade-Application-Kit/docs/Application.html) 105 | * [IPC](https://codesardine.github.io/Jade-Application-Kit/docs/IPC.html) 106 | * [KeyBindings](https://codesardine.github.io/Jade-Application-Kit/docs/KeyBindings.html) 107 | * [RequestInterceptor](https://codesardine.github.io/Jade-Application-Kit/docs/RequestInterceptor.html) 108 | * [Utils](https://codesardine.github.io/Jade-Application-Kit/docs/Utils.html) 109 | * [WebEngine](https://codesardine.github.io/Jade-Application-Kit/docs/WebEngine.html) 110 | * [DevTools](https://codesardine.github.io/Jade-Application-Kit/docs/DevTools.html) 111 | * [Settings](https://codesardine.github.io/Jade-Application-Kit/docs/Settings.html) 112 | 113 | ## Versioning 114 | 115 | [SemVer](http://semver.org/) is used for versioning. For the versions available, see the [tags on this repository](https://github.com/codesardine/Jade-Application-Kit/tags). 116 | 117 | ## Authors 118 | 119 | * **Vitor Lopes** - [Twitter Codesardine](https://twitter.com/codesardine) 120 | 121 | See also the list of [contributors](https://github.com/codesardine/Jade-Application-Kit/graphs/contributors) who participated in this project. 122 | 123 | 124 | ## Acknowledgments 125 | 126 | Applications 127 | * [Just Another Desktop Environment](https://github.com/codesardine/Jadesktop) 128 | * [Microsoft Office online](https://github.com/codesardine/Jade-Application-Kit/tree/wrapper/microsoft-office-online) for [Manjaro](https://manjaro.org) 129 | 130 | 131 | Wrappers 132 | * [Slack online](https://github.com/codesardine/Jade-Application-Kit/tree/wrapper/slack-online) 133 | * [Skype online](https://github.com/codesardine/Jade-Application-Kit/tree/wrapper/skype-online) 134 | * [Udemy online](https://github.com/Steffan153/udemy-online) by [Caleb Miller](https://github.com/Steffan153) 135 | * [WhatsApp online](https://github.com/codesardine/Jade-Application-Kit/tree/wrapper/whatsapp-online) 136 | 137 | Missing yours?, let me know. 138 | 139 | ## Known Issues 140 | * Does not like NVIDIA cards and as such falls back to software rendering, so if you use one of them you have to do without GPU acceleration. Only PCI devices. 141 | 142 | ## License 143 | Jade Application Kit is covered by the GPL license. 144 | 145 | Copyright (c) 2015-2019, Vitor Lopes. All rights reserved. 146 | 147 | -------------------------------------------------------------------------------- /bin/JAK: -------------------------------------------------------------------------------- 1 | ../JAK -------------------------------------------------------------------------------- /bin/jak-cli: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | #### Jade Application Kit 3 | # * https://codesardine.github.io/Jade-Application-Kit 4 | # * Vitor Lopes Copyright (c) 2016 - 2020 5 | # * https://vitorlopes.me 6 | import argparse 7 | import os 8 | import sys 9 | import subprocess 10 | """ 11 | App Name - Jade Application Kit 12 | App Url - https://codesardine.github.io/Jade-Application-Kit 13 | Author - Vitor Lopes -> Copyright (c) 2016 - 2020 14 | Author Url - https://vitorlopes.me 15 | """ 16 | from JAK.Application import JWebApp 17 | 18 | 19 | def run(url, title, online, transparent, debug, disable_gpu, icon, cookies_path, user_agent, custom_css, custom_js): 20 | app = JWebApp( 21 | debug=debug, 22 | disableGPU=disable_gpu, 23 | window={ 24 | "title": title, 25 | "icon": icon, 26 | "transparent": transparent, 27 | "showHelpMenu": True, 28 | }, 29 | webview={ 30 | "webContents": url, 31 | "addCSS": custom_css, 32 | "cookiesPath": cookies_path, 33 | "online": online, 34 | "userAgent": user_agent, 35 | "runJavaScript": custom_js 36 | }) 37 | app.run() 38 | 39 | 40 | def command_line_options(): 41 | """Parse commandline arguments.""" 42 | options = argparse.ArgumentParser(description='''\ 43 | ------------------------------------------------------- 44 | Jade Application Kit 45 | ------------------------------------------------------- 46 | Toggle Full Screen [ F11 ] 47 | Zoom In [ CTRL + ] 48 | Zoom Out [ CTRL - ] 49 | ------------------------------------------------------- 50 | Create hybrid desktop applications 51 | with Python, JavaScript or Shell 52 | Author : Vitor Lopes 53 | Licence: GPL 54 | url: https://codesardine.github.io/Jade-Application-Kit 55 | -------------------------------------------------------''', epilog='''\ 56 | ''', formatter_class=argparse.RawTextHelpFormatter) 57 | 58 | options.add_argument( 59 | "--url", 60 | type=str, 61 | required=True, 62 | help="Url or path to HTML file." 63 | ) 64 | options.add_argument( 65 | "--title", 66 | type=str, 67 | help="Application Title.", 68 | required=True 69 | ) 70 | options.add_argument( 71 | "--icon", 72 | default="applications-internet", 73 | type=str, 74 | help="Path to app icon, if omitted, uses url icon.", 75 | ) 76 | options.add_argument( 77 | "--transparent", 78 | default=False, 79 | type=bool, 80 | help="Transparent Background.", 81 | ) 82 | options.add_argument( 83 | "--online", 84 | default=False, 85 | type=bool, 86 | help="cache/cookies/dns prefetch ON.", 87 | ) 88 | options.add_argument( 89 | "--cookies_path", 90 | default="", 91 | type=str, 92 | help="Set path, /home/username/.jak/cookies-path.", 93 | ) 94 | options.add_argument( 95 | "--user_agent", 96 | default="", 97 | type=str, 98 | help="Set WebEngine user agent", 99 | ) 100 | options.add_argument( 101 | "--css", 102 | default="", 103 | type=str, 104 | help='Inject CSS, file path or string.', 105 | ) 106 | options.add_argument( 107 | "--js", 108 | default="", 109 | type=str, 110 | help='Inject JavaScript, file path or string.', 111 | ) 112 | options.add_argument( 113 | "--dev", 114 | default=False, 115 | action='store_true', 116 | help="Debug On", 117 | ) 118 | options.add_argument( 119 | "--cde", 120 | default=False, 121 | action='store_true', 122 | help="Create Desktop Entry", 123 | ) 124 | options.add_argument( 125 | "--desc", 126 | type=str, 127 | help="Desktop Entry Application Description" 128 | ) 129 | options.add_argument( 130 | "--disable-gpu", 131 | default=False, 132 | action='store_true', 133 | help="Disable GPU acceleration, use this if you have a NVIDIA card", 134 | ) 135 | # Todo pass dictionary as argument, this one is tricky 136 | """ 137 | options.add_argument( 138 | "--toolbar", 139 | default="", 140 | type=dict, 141 | help='Define toolbar links, set in quotes -> "CSS"', 142 | ) 143 | options.add_argument( 144 | "--url_rules", 145 | default="", 146 | help="if online, allowed url's.", 147 | ) 148 | """ 149 | 150 | return options.parse_args() 151 | 152 | 153 | if len(sys.argv) == 1: 154 | # if no arguments are passed run help message 155 | process = subprocess.Popen([os.path.realpath(__file__), "--help"]) 156 | process.wait() 157 | process.terminate() 158 | 159 | option = command_line_options() 160 | 161 | if option.url and option.title: 162 | if option.cde: 163 | if option.desc: 164 | from JAK.Utils import create_desktop_entry as cde 165 | cde(option.url, option.title, option.desc, option.icon) 166 | else: 167 | print("Description required\n --desc 'My description'") 168 | else: 169 | run(option.url, option.title, option.online, option.transparent, option.dev, option.disable_gpu, option.icon, 170 | option.cookies_path, option.user_agent, option.css, option.js) 171 | 172 | -------------------------------------------------------------------------------- /contributing.md: -------------------------------------------------------------------------------- 1 | I would love for you to contribute to Jade Application Kit and help making it better! Here are some guidelines i would like you to follow: 2 | 3 | When contributing to this repository, please first discuss the change you wish to make via issue. 4 | 5 | ## Pull Request Process 6 | 7 | 1. Ensure you create separate pull requests for each issue that will make it easier to merge back without interfering with other issues, once i have reviewed the code i will merge. 8 | 9 | 10 | 11 | ### Our Pledge 12 | 13 | In the interest of fostering an open and welcoming environment, we as 14 | contributors and maintainers pledge to making participation in our project and 15 | our community a harassment-free experience for everyone, regardless of age, body 16 | size, disability, ethnicity, gender identity and expression, level of experience, 17 | nationality, personal appearance, race, religion, or sexual identity and 18 | orientation. 19 | 20 | ### Our Standards 21 | 22 | Examples of behavior that contributes to creating a positive environment 23 | include: 24 | 25 | * Using welcoming and inclusive language 26 | * Being respectful of differing viewpoints and experiences 27 | * Gracefully accepting constructive criticism 28 | * Focusing on what is best for the community 29 | * Showing empathy towards other community members 30 | 31 | Examples of unacceptable behavior by participants include: 32 | 33 | * The use of sexualized language or imagery and unwelcome sexual attention or 34 | advances 35 | * Trolling, insulting/derogatory comments, and personal or political attacks 36 | * Public or private harassment 37 | * Publishing others' private information, such as a physical or electronic 38 | address, without explicit permission 39 | * Other conduct which could reasonably be considered inappropriate in a 40 | professional setting 41 | 42 | ### Our Responsibilities 43 | 44 | Project maintainers are responsible for clarifying the standards of acceptable 45 | behavior and are expected to take appropriate and fair corrective action in 46 | response to any instances of unacceptable behavior. 47 | 48 | Project maintainers have the right and responsibility to remove, edit, or 49 | reject comments, commits, code, wiki edits, issues, and other contributions 50 | that are not aligned to this Code of Conduct, or to ban temporarily or 51 | permanently any contributor for other behaviors that they deem inappropriate, 52 | threatening, offensive, or harmful. 53 | 54 | ### Scope 55 | 56 | This Code of Conduct applies both within project spaces and in public spaces 57 | when an individual is representing the project or its community. Examples of 58 | representing a project or community include using an official project e-mail 59 | address, posting via an official social media account, or acting as an appointed 60 | representative at an online or offline event. Representation of a project may be 61 | further defined and clarified by project maintainers. 62 | 63 | ### Enforcement 64 | 65 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 66 | reported by contacting the project team at [INSERT EMAIL ADDRESS]. All 67 | complaints will be reviewed and investigated and will result in a response that 68 | is deemed necessary and appropriate to the circumstances. The project team is 69 | obligated to maintain confidentiality with regard to the reporter of an incident. 70 | Further details of specific enforcement policies may be posted separately. 71 | 72 | Project maintainers who do not follow or enforce the Code of Conduct in good 73 | faith may face temporary or permanent repercussions as determined by other 74 | members of the project's leadership. 75 | 76 | ### Attribution 77 | 78 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 79 | available at [http://contributor-covenant.org/version/1/4][version] 80 | 81 | [homepage]: http://contributor-covenant.org 82 | [version]: http://contributor-covenant.org/version/1/4/ 83 | -------------------------------------------------------------------------------- /docs/Application.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Application.py 6 | 7 | 8 | 9 |
10 |
11 |
12 |

Application.py

13 |
14 |
15 |
16 |
17 |
18 | # 19 |
20 |

Jade Application Kit

21 |
    22 |
  • https://codesardine.github.io/Jade-Application-Kit
  • 23 |
  • Vitor Lopes Copyright (c) 2016 - 2020
  • 24 |
  • https://vitorlopes.me
  • 25 |
26 |
27 |
28 |
import sys
 29 | import subprocess
 30 | from JAK.Utils import Instance, bindings, getScreenGeometry
 31 | from JAK import Settings
 32 | from JAK.Widgets import JWindow
 33 | from JAK.WebEngine import JWebView
 34 | from JAK import __version__
 35 | if bindings() == "PyQt5":
 36 |     print("PyQt5 Bindings")
 37 |     from PyQt5.QtCore import Qt, QCoreApplication, QRect
 38 |     from PyQt5.QtWidgets import QApplication
 39 |     from PyQt5.QtWebEngineWidgets import QWebEnginePage
 40 | else:
 41 |     print("JAK_PREFERRED_BINDING environment variable not set, falling back to PySide2 Bindings.")
 42 |     from PySide2.QtCore import Qt, QCoreApplication
 43 |     from PySide2.QtWidgets import QApplication
44 |
45 |
46 |
47 |
48 |
49 |
50 | # 51 |
52 | 53 |
54 |
55 |
class JWebApp(QApplication):
56 |
57 |
58 |
59 |
60 |
61 |
62 | # 63 |
64 |

Imports: from JAK.Application import JWebApp

65 |
66 |
67 |
    def __init__(self, config=Settings.config(), **app_config):
 68 |         super(JWebApp, self).__init__(sys.argv)
 69 |         self.config = config
 70 |         self.setAAttribute(Qt.AA_UseHighDpiPixmaps)
 71 |         self.setAAttribute(Qt.AA_EnableHighDpiScaling)
 72 |         self.applicationStateChanged.connect(self._applicationStateChanged_cb)
 73 |         for key, value in app_config.items():
 74 |             if isinstance(value, dict):
 75 |                 for subkey, subvalue in app_config[key].items():
 76 |                     config[key][subkey] = subvalue
 77 |             else:
 78 |                 config[key] = value
 79 | 
 80 |         for attr in config["setAAttribute"]:
 81 |             self.setAAttribute(attr)
 82 | 
 83 |         if config["remote-debug"] or "--remote-debug" in sys.argv:
 84 |             sys.argv.append("--remote-debugging-port=9000")
 85 | 
 86 |         if config["debug"] or "--dev" in sys.argv:
 87 |             print("Debugging On")
 88 |             if not config["debug"]:
 89 |                 config["debug"] = True
 90 |         else:
 91 |             print("Production Mode On, use (--dev) for debugging")
92 |
93 |
94 |
95 |
96 |
97 |
98 | # 99 |
100 |

Enable/Disable GPU acceleration

101 |
102 |
103 |
        if not config["disableGPU"]:
104 |
105 |
106 |
107 |
108 |
109 |
110 | # 111 |
112 |

Virtual machine detection using SystemD

113 |
114 |
115 |
            detect_virtual_machine = subprocess.Popen(
116 |                 ["systemd-detect-virt"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT
117 |             )
118 |
119 |
120 |
121 |
122 |
123 |
124 | # 125 |
126 |

FIXME find a more reliable way of detecting NVIDIA cards

127 |
128 |
129 |
            detect_nvidia_pci = subprocess.Popen(
130 |                 "lspci | grep -i --color 'vga\|3d\|2d'", stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
131 |                 shell=True
132 |             )
133 |             virtual = detect_virtual_machine.communicate()
134 |             nvidia_pci = detect_nvidia_pci.communicate()
135 |             nvidia_pci = nvidia_pci[0].decode("utf-8").lower()
136 | 
137 |         if config["disableGPU"]:
138 |             self.disable_opengl()
139 |             print("Disabling GPU, Software Rendering explicitly activated")
140 |         else:
141 |             if virtual[-1]:
142 |
143 |
144 |
145 |
146 |
147 |
148 | # 149 |
150 |

Detect virtual machine

151 |
152 |
153 |
                print(f"Virtual machine detected:{virtual}")
154 |                 self.disable_opengl()
155 | 
156 |             elif nvidia_pci:
157 |
158 |
159 |
160 |
161 |
162 |
163 | # 164 |
165 |

Detect NVIDIA cards

166 |
167 |
168 |
                if "nvidia" in nvidia_pci:
169 |                     print("NVIDIA detected:Known bug - kernel rejected pushbuf")
170 |                     print("Falling back to Software Rendering")
171 |                     self.disable_opengl()
172 |             else:
173 |                 print(f"Virtual Machine:{virtual[-1]}")
174 |
175 |
176 |
177 |
178 |
179 |
180 | # 181 |
182 |

Desktop file must match application name in lowercase with dashes instead of white space.

183 |
184 |
185 |
        self.setDesktopFileName(f"{self.config['window']['title'].lower().replace(' ', '-')}.desktop")
186 |         self.setOrganizationDomain(self.config['webview']['webContents'])
187 |         self.setApplicationVersion(__version__)
188 |         if not self.config['webview']['online'] and self.config['webview']['IPC']:
189 |             if bindings() == "PyQt5":
190 |                 from PyQt5.QtWebEngineCore import QWebEngineUrlScheme
191 |             else:
192 |                 from PySide2.QtWebEngineCore import QWebEngineUrlScheme
193 |             QWebEngineUrlScheme.registerScheme(QWebEngineUrlScheme("ipc".encode()))
194 |
195 |
196 |
197 |
198 |
199 |
200 | # 201 |
202 | 203 |
204 |
205 |
    def _applicationStateChanged_cb(self, event):
206 |         view = Instance.retrieve("view")
207 |         page = view.page()
208 |
209 |
210 |
211 |
212 |
213 |
214 | # 215 |
216 |

TODO freeze view when inactive to save ram

217 |
218 |
219 |
        if event == Qt.ApplicationInactive:
220 |             print("inactive")
221 |         elif event == Qt.ApplicationActive:
222 |             print("active")
223 |
224 |
225 |
226 |
227 |
228 |
229 | # 230 |
231 | 232 |
233 |
234 |
    def disable_opengl(self):
235 |
236 |
237 |
238 |
239 |
240 |
241 | # 242 |
243 |

Disable GPU acceleration 244 | https://codereview.qt-project.org/c/qt/qtwebengine-chromium/+/206307

245 |
246 |
247 |
        self.setAAttribute(Qt.AA_UseSoftwareOpenGL)
248 |
249 |
250 |
251 |
252 |
253 |
254 | # 255 |
256 | 257 |
258 |
259 |
    def setAAttribute(self, attr):
260 |         QCoreApplication.setAttribute(attr, True)
261 |
262 |
263 |
264 |
265 |
266 |
267 | # 268 |
269 | 270 |
271 |
272 |
    def run(self):
273 |         Instance.record("view", JWebView(self.config))
274 | 
275 |         if self.config['window']["transparent"]:
276 |             from JAK.Utils import JavaScript
277 |             JavaScript.css(
278 |                 "body, html {background-color:transparent !important;background-image:none !important;}", "JAK"
279 |             )
280 | 
281 |         if self.config['webview']["addCSS"]:
282 |             from JAK.Utils import JavaScript
283 |             JavaScript.css(self.config['webview']["addCSS"], "user")
284 |             print("Custom CSS detected")
285 | 
286 |         if self.config['webview']["runJavaScript"]:
287 |             from JAK.Utils import JavaScript
288 |             JavaScript.send(self.config['webview']["runJavaScript"])
289 |             print("Custom JavaScript detected")
290 | 
291 |         win = Instance.auto("win", JWindow(self.config))
292 |         if self.config['window']["fullScreen"]:
293 |             screen = getScreenGeometry()
294 |             win.resize(screen.width(), screen.height())
295 |         else:
296 |             win.resize(win.default_size("width"), win.default_size("height"))
297 | 
298 |         win.setFocusPolicy(Qt.WheelFocus)
299 |         win.show()
300 |         win.setFocus()
301 |         win.window_original_position = win.frameGeometry()
302 |         result = self.exec_()
303 |         sys.exit(result)
304 | 
305 | 
306 |
307 |
308 |
309 |
310 | 311 | -------------------------------------------------------------------------------- /docs/DevTools.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | DevTools.py 6 | 7 | 8 | 9 |
10 |
11 |
12 |

DevTools.py

13 |
14 |
15 |
16 |
17 |
18 | # 19 |
20 |

Jade Application Kit

21 |
    22 |
  • https://codesardine.github.io/Jade-Application-Kit
  • 23 |
  • Vitor Lopes Copyright (c) 2016 - 2020
  • 24 |
  • https://vitorlopes.me
  • 25 |
26 |
27 |
28 |
from JAK.Utils import  bindings
 29 | if bindings() == "PyQt5":
 30 |     from PyQt5.QtCore import Qt
 31 |     from PyQt5.QtWebEngineWidgets import QWebEngineView
 32 |     from PyQt5.QtWidgets import QDockWidget
 33 | else:
 34 |     from PySide2.QtCore import Qt
 35 |     from PySide2.QtWebEngineWidgets import QWebEngineView
 36 |     from PySide2.QtWidgets import QDockWidget
37 |
38 |
39 |
40 |
41 |
42 |
43 | # 44 |
45 | 46 |
47 |
48 |
class WebView(QWebEngineView):
49 |
50 |
51 |
52 |
53 |
54 |
55 | # 56 |
57 | 58 |
59 |
60 |
    def __init__(self, parent=None):
 61 |         QWebEngineView.__init__(self, parent)
62 |
63 |
64 |
65 |
66 |
67 |
68 | # 69 |
70 | 71 |
72 |
73 |
    def set_inspected_view(self, view=None):
 74 |         self.page().setInspectedPage(view.page() if view else None)
75 |
76 |
77 |
78 |
79 |
80 |
81 | # 82 |
83 | 84 |
85 |
86 |
class InspectorDock(QDockWidget):
87 |
88 |
89 |
90 |
91 |
92 |
93 | # 94 |
95 | 96 |
97 |
98 |
    def __init__(self, parent=None):
 99 |         super().__init__(parent=parent)
100 |         title = "Inspector"
101 |         self.setWindowTitle(title)
102 |         self.setObjectName(title)
103 | 
104 | 
105 |
106 |
107 |
108 |
109 | 110 | -------------------------------------------------------------------------------- /docs/IPC.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IPC.py 6 | 7 | 8 | 9 |
10 |
11 |
12 |

IPC.py

13 |
14 |
15 |
16 |
17 |
18 | # 19 |
20 | 21 |
22 |
23 |
from JAK.Utils import Instance
24 |
25 |
26 |
27 |
28 |
29 |
30 | # 31 |
32 |
    33 |
  • Usage: from JAK import IPC
  • 34 |
  • Create your own class and point to this one: IPC.Bind = MyOverrride
  • 35 |
36 |
37 |
38 |
class Bind:
39 |
40 |
41 |
42 |
43 |
44 |
45 | # 46 |
47 |
    48 |
  • Do something with the data.
  • 49 |
  • :param data:
  • 50 |
  • :return: url output
  • 51 |
52 |
53 |
54 |
    @staticmethod
 55 |     def listen(data):
56 |
57 |
58 |
59 |
60 |
61 |
62 | # 63 |
64 | 65 |
66 |
67 |
        raise NotImplementedError()
68 |
69 |
70 |
71 |
72 |
73 |
74 | # 75 |
76 |

Call python methods from JavaScript.

77 |
78 |
79 |
class Communication:
80 |
81 |
82 |
83 |
84 |
85 |
86 | # 87 |
88 | 89 |
90 |
91 |
    @staticmethod
 92 |     def send(url) -> None:
 93 |         if ":" in url:
 94 |             url = url.split(':')[1]
 95 |         if url.endswith("()"):
 96 |             eval(f"Bind.{url}")
 97 |         else:
 98 |             Bind.listen(url)
 99 | 
100 | 
101 |
102 |
103 |
104 |
105 | 106 | -------------------------------------------------------------------------------- /docs/KeyBindings.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | KeyBindings.py 6 | 7 | 8 | 9 |
10 |
11 |
12 |

KeyBindings.py

13 |
14 |
15 |
16 |
17 |
18 | # 19 |
20 |

Jade Application Kit

21 |
    22 |
  • https://codesardine.github.io/Jade-Application-Kit
  • 23 |
  • Vitor Lopes Copyright (c) 2016 - 2020
  • 24 |
  • https://vitorlopes.me
  • 25 |
26 |
27 |
28 |
from JAK.Utils import Instance, bindings
 29 | if bindings() == "PyQt5":
 30 |     from PyQt5.QtCore import Qt
 31 | else:
 32 |     from PySide2.QtCore import Qt
33 |
34 |
35 |
36 |
37 |
38 |
39 | # 40 |
41 |

Imports: from JAK.Keybindings import KeyPress

42 |
43 |
44 |
class KeyPress:
45 |
46 |
47 |
48 |
49 |
50 |
51 | # 52 |
53 | 54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 | # 64 |
65 | 66 |
67 |
68 |
    def __init__(self, event, config):
69 |
70 |
71 |
72 |
73 |
74 |
75 | # 76 |
77 |
    78 |
  • self.win = QMainWindow Instance
  • 79 |
  • self.view = QTWebEngine Instance
  • 80 |
81 |
82 |
83 |
        if event.type() == event.KeyPress:
 84 |             if event.key() == Qt.Key_F11:
 85 |                 if config['webview']["online"] is True or config['window']["showHelpMenu"] is True:
 86 |                     self.full_screen()
 87 |             elif event.key() == Qt.Key_F10:
 88 |                 if config['webview']["online"] is True or config['window']["showHelpMenu"] is True:
 89 |                     self.win = Instance.retrieve("win")
 90 |                     self.win.corner_window()
 91 | 
 92 |             elif event.modifiers() == Qt.ControlModifier:
 93 | 
 94 |                 if event.key() == Qt.Key_Minus:
 95 |                     self._zoom_out()
 96 | 
 97 |                 elif event.key() == Qt.Key_Equal:
 98 |                     self._zoom_in()
99 |
100 |
101 |
102 |
103 |
104 |
105 | # 106 |
107 | 108 |
109 |
110 |
    def _current_zoom(self):
111 |         self.view = Instance.retrieve("view")
112 |         return self.view.zoomFactor()
113 |
114 |
115 |
116 |
117 |
118 |
119 | # 120 |
121 | 122 |
123 |
124 |
    def _zoom_in(self):
125 |         new_zoom = self._current_zoom() * 1.5
126 |         self.view.setZoomFactor(new_zoom)
127 |         self._save_zoom()
128 |
129 |
130 |
131 |
132 |
133 |
134 | # 135 |
136 | 137 |
138 |
139 |
    def _zoom_out(self):
140 |         new_zoom = self._current_zoom() / 1.5
141 |         self.view.setZoomFactor(new_zoom)
142 |         self._save_zoom()
143 |
144 |
145 |
146 |
147 |
148 |
149 | # 150 |
151 |

TODO only zoom to a certain lvl then reset

152 |
153 |
154 |
    def _reset_zoom(self):
155 |         self.view.setZoomFactor(1)
156 |
157 |
158 |
159 |
160 |
161 |
162 | # 163 |
164 | 165 |
166 |
167 |
    def _save_zoom(self):
168 |         percent = int(self._current_zoom() * 100)
169 |         print(f"Zoom:{percent}%")
170 |
171 |
172 |
173 |
174 |
175 |
176 | # 177 |
178 |

TODO save zoom

179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 | # 189 |
190 | 191 |
192 |
193 |
    def full_screen(self):
194 |
195 |
196 |
197 |
198 |
199 |
200 | # 201 |
202 |

TODO animate window resize

203 |
204 |
205 |
        self.win = Instance.retrieve("win")
206 |         if self.win.isFullScreen():
207 |             self.win.showNormal()
208 |             self.win.hide_show_bar()
209 |         else:
210 |             self.win.showFullScreen()
211 |             self.win.hide_show_bar()
212 | 
213 | 
214 |
215 |
216 |
217 |
218 | 219 | -------------------------------------------------------------------------------- /docs/RequestInterceptor.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | RequestInterceptor.py 6 | 7 | 8 | 9 |
10 |
11 |
12 |

RequestInterceptor.py

13 |
14 |
15 |
16 |
17 |
18 | # 19 |
20 |

Jade Application Kit

21 |
    22 |
  • https://codesardine.github.io/Jade-Application-Kit
  • 23 |
  • Vitor Lopes Copyright (c) 2016 - 2020
  • 24 |
  • https://vitorlopes.me
  • 25 |
26 |
27 |
28 |
from JAK.Utils import check_url_rules, bindings
 29 | if bindings() == "PyQt5":
 30 |     from PyQt5.QtWebEngineCore import QWebEngineUrlRequestInterceptor, QWebEngineUrlRequestInfo
 31 | else:
 32 |     from PySide2.QtWebEngineCore import QWebEngineUrlRequestInterceptor, QWebEngineUrlRequestInfo
33 |
34 |
35 |
36 |
37 |
38 |
39 | # 40 |
41 | 42 |
43 |
44 |
class Interceptor(QWebEngineUrlRequestInterceptor):
45 |
46 |
47 |
48 |
49 |
50 |
51 | # 52 |
53 |

Imports: from JAK.RequestInterceptor import Interceptor

54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 | # 64 |
65 |
    66 |
  • :param debug:bool:
  • 67 |
  • :param block_rules:dict: URL’s to block
  • 68 |
69 |
70 |
71 |
    def __init__(self, config):
 72 |         self.config = config
73 |
74 |
75 |
76 |
77 |
78 |
79 | # 80 |
81 | 82 |
83 |
84 |
        super(Interceptor, self).__init__()
85 |
86 |
87 |
88 |
89 |
90 |
91 | # 92 |
93 |
    94 |
  • All method calls to the profile on the main thread will block until execution of this function is finished.
  • 95 |
  • :param info: QWebEngineUrlRequestInfo
  • 96 |
97 |
98 |
99 |
    def interceptRequest(self, info) -> None:
100 |
101 |
102 |
103 |
104 |
105 |
106 | # 107 |
108 | 109 |
110 |
111 |
        if self.config['webview']["urlRules"] is not None:
112 |
113 |
114 |
115 |
116 |
117 |
118 | # 119 |
120 |

If we have any URL’s in the block dictionary

121 |
122 |
123 |
            url = info.requestUrl().toString()
124 |             try:
125 |                 if check_url_rules("Block", url, self.config['webview']["urlRules"]["block"]):
126 |
127 |
128 |
129 |
130 |
131 |
132 | # 133 |
134 |

block url’s

135 |
136 |
137 |
                    info.block(True)
138 |                     print(f"Blocked:{url}")
139 |             except KeyError:
140 |                 pass
141 | 
142 |         if self.config["debug"]:
143 |             url = info.requestUrl().toString()
144 |             resource = info.resourceType()
145 |             if resource == QWebEngineUrlRequestInfo.ResourceType.ResourceTypeMainFrame:
146 |                 print(f"Intercepted link:{url}")
147 | 
148 |             elif resource != QWebEngineUrlRequestInfo.ResourceType.ResourceTypeMainFrame:
149 |                 print(f"Intercepted resource:{url}")
150 | 
151 | 
152 |
153 |
154 |
155 |
156 | 157 | -------------------------------------------------------------------------------- /docs/Settings.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Settings.py 6 | 7 | 8 | 9 |
10 |
11 |
12 |

Settings.py

13 |
14 |
15 |
16 |
17 |
18 | # 19 |
20 |

Jade Application Kit

21 |
    22 |
  • https://codesardine.github.io/Jade-Application-Kit
  • 23 |
  • Vitor Lopes Copyright (c) 2016 - 2020
  • 24 |
  • https://vitorlopes.me
  • 25 |
26 |
27 |
28 |
from JAK.Utils import bindings
 29 | if bindings() == "PyQt5":
 30 |     from PyQt5.QtCore import Qt
 31 |     from PyQt5.QtWebEngineWidgets import QWebEngineSettings
 32 | else:
 33 |     from PySide2.QtCore import Qt
 34 |     from PySide2.QtWebEngineWidgets import QWebEngineSettings
35 |
36 |
37 |
38 |
39 |
40 |
41 | # 42 |
43 | 44 |
45 |
46 |
def config():
 47 |     return {
 48 |         "debug": False,
 49 |         "remote-debug": False,
 50 |         "setAAttribute": (),
 51 |         "disableGPU": False,
 52 |         "window": {
 53 |             "title": "Jade Application Kit",
 54 |             "icon": None,
 55 |             "backgroundImage": None,
 56 |             "setFlags": Qt.Window,
 57 |             "setAttribute": (),
 58 |             "state": None,
 59 |             "fullScreen": False,
 60 |             "transparent": False,
 61 |             "toolbar": None,
 62 |             "menus": None,
 63 |             "SystemTrayIcon": False,
 64 |             "showHelpMenu": False,
 65 |         },
 66 |         "webview": {
 67 |             "webContents": "https://codesardine.github.io/Jade-Application-Kit",
 68 |             "online": False,
 69 |             "urlRules": None,
 70 |             "cookiesPath": None,
 71 |             "userAgent": None,
 72 |             "addCSS": None,
 73 |             "runJavaScript": None,
 74 |             "IPC": True,
 75 |             "MediaAudioVideoCapture": False,
 76 |             "MediaVideoCapture": False,
 77 |             "MediaAudioCapture": False,
 78 |             "Geolocation": False,
 79 |             "MouseLock": False,
 80 |             "DesktopVideoCapture": False,
 81 |             "DesktopAudioVideoCapture": False,
 82 |             "injectJavaScript": {
 83 |                 "JavaScript": None,
 84 |                 "name": "Application Script"
 85 |             },
 86 |             "webChannel": {
 87 |                 "active": False,
 88 |                 "sharedOBJ": None
 89 |             },
 90 |             "enabledSettings": (
 91 |                 QWebEngineSettings.JavascriptCanPaste,
 92 |                 QWebEngineSettings.FullScreenSupportEnabled,
 93 |                 QWebEngineSettings.AllowWindowActivationFromJavaScript,
 94 |                 QWebEngineSettings.LocalContentCanAccessRemoteUrls,
 95 |                 QWebEngineSettings.JavascriptCanAccessClipboard,
 96 |                 QWebEngineSettings.SpatialNavigationEnabled,
 97 |                 QWebEngineSettings.TouchIconsEnabled
 98 |             ),
 99 |             "disabledSettings": (
100 |                 QWebEngineSettings.PlaybackRequiresUserGesture
101 |             )
102 |         }
103 | }
104 | 
105 | 
106 |
107 |
108 |
109 |
110 | 111 | -------------------------------------------------------------------------------- /docs/__init__.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | __init__.py 6 | 7 | 8 | 9 |
10 |
11 |
12 |

__init__.py

13 |
14 |
15 |
16 |
17 |
18 | # 19 |
20 | 21 |
22 |
23 |
__version__ = "v3.5.3"
24 | print(f"JAK {__version__}")
25 | 
26 | 
27 |
28 |
29 |
30 |
31 | 32 | -------------------------------------------------------------------------------- /docs/pycco.css: -------------------------------------------------------------------------------- 1 | /*--------------------- Layout and Typography ----------------------------*/ 2 | body { 3 | font-family: 'Palatino Linotype', 'Book Antiqua', Palatino, FreeSerif, serif; 4 | font-size: 16px; 5 | line-height: 24px; 6 | color: #252519; 7 | margin: 0; padding: 0; 8 | background: #f5f5ff; 9 | } 10 | a { 11 | color: #261a3b; 12 | } 13 | a:visited { 14 | color: #261a3b; 15 | } 16 | p { 17 | margin: 0 0 15px 0; 18 | } 19 | h1, h2, h3, h4, h5, h6 { 20 | margin: 40px 0 15px 0; 21 | } 22 | h2, h3, h4, h5, h6 { 23 | margin-top: 0; 24 | } 25 | #container { 26 | background: white; 27 | } 28 | #container, div.section { 29 | position: relative; 30 | } 31 | #background { 32 | position: absolute; 33 | top: 0; left: 580px; right: 0; bottom: 0; 34 | background: #f5f5ff; 35 | border-left: 1px solid #e5e5ee; 36 | z-index: 0; 37 | } 38 | #jump_to, #jump_page { 39 | background: white; 40 | -webkit-box-shadow: 0 0 25px #777; -moz-box-shadow: 0 0 25px #777; 41 | -webkit-border-bottom-left-radius: 5px; -moz-border-radius-bottomleft: 5px; 42 | font: 10px Arial; 43 | text-transform: uppercase; 44 | cursor: pointer; 45 | text-align: right; 46 | } 47 | #jump_to, #jump_wrapper { 48 | position: fixed; 49 | right: 0; top: 0; 50 | padding: 5px 10px; 51 | } 52 | #jump_wrapper { 53 | padding: 0; 54 | display: none; 55 | } 56 | #jump_to:hover #jump_wrapper { 57 | display: block; 58 | } 59 | #jump_page { 60 | padding: 5px 0 3px; 61 | margin: 0 0 25px 25px; 62 | } 63 | #jump_page .source { 64 | display: block; 65 | padding: 5px 10px; 66 | text-decoration: none; 67 | border-top: 1px solid #eee; 68 | } 69 | #jump_page .source:hover { 70 | background: #f5f5ff; 71 | } 72 | #jump_page .source:first-child { 73 | } 74 | div.docs { 75 | float: left; 76 | max-width: 500px; 77 | min-width: 500px; 78 | min-height: 5px; 79 | padding: 10px 25px 1px 50px; 80 | vertical-align: top; 81 | text-align: left; 82 | } 83 | .docs pre { 84 | margin: 15px 0 15px; 85 | padding-left: 15px; 86 | } 87 | .docs p tt, .docs p code { 88 | background: #f8f8ff; 89 | border: 1px solid #dedede; 90 | font-size: 12px; 91 | padding: 0 0.2em; 92 | } 93 | .octowrap { 94 | position: relative; 95 | } 96 | .octothorpe { 97 | font: 12px Arial; 98 | text-decoration: none; 99 | color: #454545; 100 | position: absolute; 101 | top: 3px; left: -20px; 102 | padding: 1px 2px; 103 | opacity: 0; 104 | -webkit-transition: opacity 0.2s linear; 105 | } 106 | div.docs:hover .octothorpe { 107 | opacity: 1; 108 | } 109 | div.code { 110 | margin-left: 580px; 111 | padding: 14px 15px 16px 50px; 112 | vertical-align: top; 113 | } 114 | .code pre, .docs p code { 115 | font-size: 12px; 116 | } 117 | pre, tt, code { 118 | line-height: 18px; 119 | font-family: Monaco, Consolas, "Lucida Console", monospace; 120 | margin: 0; padding: 0; 121 | } 122 | div.clearall { 123 | clear: both; 124 | } 125 | 126 | 127 | /*---------------------- Syntax Highlighting -----------------------------*/ 128 | td.linenos { background-color: #f0f0f0; padding-right: 10px; } 129 | span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; } 130 | body .hll { background-color: #ffffcc } 131 | body .c { color: #408080; font-style: italic } /* Comment */ 132 | body .err { border: 1px solid #FF0000 } /* Error */ 133 | body .k { color: #954121 } /* Keyword */ 134 | body .o { color: #666666 } /* Operator */ 135 | body .cm { color: #408080; font-style: italic } /* Comment.Multiline */ 136 | body .cp { color: #BC7A00 } /* Comment.Preproc */ 137 | body .c1 { color: #408080; font-style: italic } /* Comment.Single */ 138 | body .cs { color: #408080; font-style: italic } /* Comment.Special */ 139 | body .gd { color: #A00000 } /* Generic.Deleted */ 140 | body .ge { font-style: italic } /* Generic.Emph */ 141 | body .gr { color: #FF0000 } /* Generic.Error */ 142 | body .gh { color: #000080; font-weight: bold } /* Generic.Heading */ 143 | body .gi { color: #00A000 } /* Generic.Inserted */ 144 | body .go { color: #808080 } /* Generic.Output */ 145 | body .gp { color: #000080; font-weight: bold } /* Generic.Prompt */ 146 | body .gs { font-weight: bold } /* Generic.Strong */ 147 | body .gu { color: #800080; font-weight: bold } /* Generic.Subheading */ 148 | body .gt { color: #0040D0 } /* Generic.Traceback */ 149 | body .kc { color: #954121 } /* Keyword.Constant */ 150 | body .kd { color: #954121; font-weight: bold } /* Keyword.Declaration */ 151 | body .kn { color: #954121; font-weight: bold } /* Keyword.Namespace */ 152 | body .kp { color: #954121 } /* Keyword.Pseudo */ 153 | body .kr { color: #954121; font-weight: bold } /* Keyword.Reserved */ 154 | body .kt { color: #B00040 } /* Keyword.Type */ 155 | body .m { color: #666666 } /* Literal.Number */ 156 | body .s { color: #219161 } /* Literal.String */ 157 | body .na { color: #7D9029 } /* Name.Attribute */ 158 | body .nb { color: #954121 } /* Name.Builtin */ 159 | body .nc { color: #0000FF; font-weight: bold } /* Name.Class */ 160 | body .no { color: #880000 } /* Name.Constant */ 161 | body .nd { color: #AA22FF } /* Name.Decorator */ 162 | body .ni { color: #999999; font-weight: bold } /* Name.Entity */ 163 | body .ne { color: #D2413A; font-weight: bold } /* Name.Exception */ 164 | body .nf { color: #0000FF } /* Name.Function */ 165 | body .nl { color: #A0A000 } /* Name.Label */ 166 | body .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */ 167 | body .nt { color: #954121; font-weight: bold } /* Name.Tag */ 168 | body .nv { color: #19469D } /* Name.Variable */ 169 | body .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */ 170 | body .w { color: #bbbbbb } /* Text.Whitespace */ 171 | body .mf { color: #666666 } /* Literal.Number.Float */ 172 | body .mh { color: #666666 } /* Literal.Number.Hex */ 173 | body .mi { color: #666666 } /* Literal.Number.Integer */ 174 | body .mo { color: #666666 } /* Literal.Number.Oct */ 175 | body .sb { color: #219161 } /* Literal.String.Backtick */ 176 | body .sc { color: #219161 } /* Literal.String.Char */ 177 | body .sd { color: #219161; font-style: italic } /* Literal.String.Doc */ 178 | body .s2 { color: #219161 } /* Literal.String.Double */ 179 | body .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */ 180 | body .sh { color: #219161 } /* Literal.String.Heredoc */ 181 | body .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */ 182 | body .sx { color: #954121 } /* Literal.String.Other */ 183 | body .sr { color: #BB6688 } /* Literal.String.Regex */ 184 | body .s1 { color: #219161 } /* Literal.String.Single */ 185 | body .ss { color: #19469D } /* Literal.String.Symbol */ 186 | body .bp { color: #954121 } /* Name.Builtin.Pseudo */ 187 | body .vc { color: #19469D } /* Name.Variable.Class */ 188 | body .vg { color: #19469D } /* Name.Variable.Global */ 189 | body .vi { color: #19469D } /* Name.Variable.Instance */ 190 | body .il { color: #666666 } /* Literal.Number.Integer.Long */ 191 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | PySide2 >= 5.13 2 | PyQt5 >= 5.13 3 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | description-file = README.md 3 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from setuptools import setup 3 | from os import path 4 | from JAK import __version__ 5 | #from setuptools import setup, find_packages 6 | 7 | readme = path.abspath(path.dirname(__file__)) 8 | 9 | # Get the long description from the README file 10 | with open(path.join(readme, 'README.md'), encoding='utf-8') as f: 11 | long_description = f.read() 12 | 13 | setup( 14 | name = "Jade-Application-Kit", 15 | version = __version__, 16 | packages = ["JAK"], 17 | python_requires = ">=3.6", 18 | url = "https://codesardine.github.io/Jade-Application-Kit", 19 | license = "GPL", 20 | author = "Vitor Lopes", 21 | description = "Create native web wrappers or write hybrid Desktop applications on Linux," 22 | " with Python, JavaScript, HTML, and Blink", 23 | long_description = long_description, 24 | long_description_content_type='text/markdown', 25 | download_url = "https://github.com/codesardine/Jade-Application-Kit/zipball/master", 26 | keywords = ["Jade Application Kit", "gui", "blink", "html5", "web technologies", "javascript", "python", 27 | "webgl", "CSS", "QTWebEngine", "linux", "webview"], 28 | classifiers = [ 29 | "Development Status :: 4 - Beta", 30 | "Intended Audience :: Developers", 31 | "Intended Audience :: End Users/Desktop", 32 | "License :: OSI Approved :: GNU General Public License (GPL) ", 33 | "Operating System :: POSIX :: Linux", 34 | "Environment :: Web Environment", 35 | "Topic :: Desktop Environment", 36 | "Environment :: X11 Applications", 37 | "Programming Language :: Python :: 3.6", 38 | "Topic :: Software Development :: Libraries :: Application Frameworks", 39 | "Topic :: Software Development :: Libraries :: Python Modules", 40 | "Topic :: Software Development :: User Interfaces", 41 | ], 42 | data_files=[ 43 | ("/usr/bin/", ["bin/jak-cli"]) 44 | ], 45 | install_requires=[ 46 | "PySide2", 47 | "PyQt5" 48 | ], 49 | ) 50 | --------------------------------------------------------------------------------