def event(view, event): #TODO manage sound and video pass data = event.mimeData() ext = (".mp4", ".ogv", ".webm") if str(data.text().endswith(ext)): video = str(data.text()) js = f"desktop.playVideo(`{video}`)" JavaScript.send(js)
def package_sync_callback(*args): print(args) window = Instance.retrieve("win") msg = f"Would you like to update your software and operating system from {self.branch_lock['branch']} branch now?" Dialog.question(window, " ", msg, update) self.branch_lock["branch"] = "" JavaScript.send(f""" desktop.elem(`#{self.branch_lock["branch"]}-btn`).checked = true """)
def setBranch(self, desired_branch): current_branch = Desktop.getBranch() if current_branch != desired_branch: if self.branch_lock["branch"] == "": self.branch_lock["branch"] = desired_branch.upper() notify( f"Setting branch to {desired_branch.upper()} and synchronising mirrors.", "Might take a while.") def update(): run(["pamac-manager", "--updates"]) def package_sync_callback(*args): print(args) window = Instance.retrieve("win") msg = f"Would you like to update your software and operating system from {self.branch_lock['branch']} branch now?" Dialog.question(window, " ", msg, update) self.branch_lock["branch"] = "" JavaScript.send(f""" desktop.elem(`#{self.branch_lock["branch"]}-btn`).checked = true """) def branch_sync_callback(sucprocess: Gio.Subprocess, result: Gio.AsyncResult, data): proc1.communicate_utf8_finish(result) notify("Mirrors done, Synchronising packages", "") proc2 = Gio.Subprocess.new( ['pkexec', 'pacman', '-Sy'], Gio.SubprocessFlags.STDIN_PIPE | Gio.SubprocessFlags.STDOUT_PIPE | Gio.SubprocessFlags.STDERR_PIPE) proc2.communicate_utf8_async('package sync', None, package_sync_callback, None) cmd = [ 'pkexec', 'pacman-mirrors', '--fasttrack', '--api', '--set-branch', f'{desired_branch}' ] proc1 = Gio.Subprocess.new( cmd, Gio.SubprocessFlags.STDIN_PIPE | Gio.SubprocessFlags.STDOUT_PIPE | Gio.SubprocessFlags.STDERR_PIPE) proc1.communicate_utf8_async('mirrors sync', None, branch_sync_callback, None) else: notify( f"Hold on, still changing to {self.branch_lock['branch']}.", "") JavaScript.send(f""" desktop.elem(`#{current_branch}-btn`).checked = true """)
def callback(sucprocess: Gio.Subprocess, result: Gio.AsyncResult, data): proc.communicate_utf8_finish(result) current_branch = Desktop.getBranch() if current_branch != desired_branch: JavaScript.send(f""" desktop.elem(`#{current_branch}-btn`).checked = true """) notify("Something went wrong", "") else: from JAK.Widgets import JCancelConfirmDialog window = Instance.retrieve("win") msg = f"All Done, would you like to update your software and operating system from {current_branch.upper()} branch now?" JCancelConfirmDialog(window, " ", msg, update)
def _page_load_finish(self) -> None: result = time.localtime(time.time()) print(f"Document Ready in: {result.tm_sec} seconds") try: if self.custom_css: print("Custom CSS loaded") JavaScript.css(self, self.custom_css) except AttributeError: pass try: if self.custom_js: print("Custom JavaScript loaded") JavaScript.send(self, self.custom_js) except AttributeError: pass
def run(self): Instance.record("view", JWebView(self.config)) if self.config["add_CSS"]: from JAK.Utils import JavaScript JavaScript.css(self.config["add_CSS"]) print("Custom CSS detected") if self.config["run_JavaScript"]: from JAK.Utils import JavaScript JavaScript.send(self.config["run_JavaScript"]) print("Custom JavaScript detected") win = Instance.auto("win", JWindow(self.config)) win.resize(win.default_size("width"), win.default_size("height")) win.show() win.window_original_position = win.frameGeometry() result = self.exec_() sys.exit(result)
def run(self): Instance.record("view", JWebView(self.config)) if self.config['window']["transparent"]: from JAK.Utils import JavaScript JavaScript.css( "body, html {background-color:transparent !important;background-image:none !important;}", "JAK") if self.config['webview']["addCSS"]: from JAK.Utils import JavaScript JavaScript.css(self.config['webview']["addCSS"], "user") print("Custom CSS detected") if self.config['webview']["runJavaScript"]: from JAK.Utils import JavaScript JavaScript.send(self.config['webview']["runJavaScript"]) print("Custom JavaScript detected") win = Instance.auto("win", JWindow(self.config)) if self.config['window']["fullScreen"]: screen = getScreenGeometry() win.resize(screen.width(), screen.height()) else: win.resize(win.default_size("width"), win.default_size("height")) win.setFocusPolicy(Qt.WheelFocus) win.show() win.setFocus() win.window_original_position = win.frameGeometry() result = self.exec_() sys.exit(result)
def toggleLauncher(): JavaScript.send("desktop.toggleLauncher();")
def toggleSettings(): JavaScript.send("desktop.toggleSettings();")
def updateMenu(): menu = Menu.Get().items() JavaScript.send(f"Jade.menu = { json.dumps( menu ) }")
def toggleSearch(): JavaScript.send("desktop.toggleSearch();")
def __init__(self, config): self.config = config super(JWebView, self).__init__() self.setAttribute(Qt.WA_DeleteOnClose, True) self.profile = QWebEngineProfile.defaultProfile() self.webpage = JWebPage(self.profile, self, config) self.setPage(self.webpage) if config["inject_JavaScript"]["JavaScript"]: from JAK.Utils import JavaScript JavaScript.inject(self.page(), config["inject_JavaScript"]) self.interceptor = Interceptor(config) if config["user_agent"]: # Set user agent self.profile.setHttpUserAgent(config["user_agent"]) if config["debug"]: self.settings().setAttribute(QWebEngineSettings.XSSAuditingEnabled, True) else: self.setContextMenuPolicy(Qt.PreventContextMenu) if config["transparent"]: # Activates background transparency self.setAttribute(Qt.WA_TranslucentBackground) self.page().setBackgroundColor(Qt.transparent) self.setStyleSheet("background:transparent;") print( "Transparency detected, make sure you set [ body {background:transparent;} ]" ) # * Set Engine options if self.config["JavascriptCanPaste"]: self.settings().setAttribute(QWebEngineSettings.JavascriptCanPaste, True) else: self.settings().setAttribute(QWebEngineSettings.JavascriptCanPaste, False) if self.config["PlaybackRequiresUserGesture"]: self.settings().setAttribute( QWebEngineSettings.PlaybackRequiresUserGesture, True) else: self.settings().setAttribute( QWebEngineSettings.PlaybackRequiresUserGesture, False) if self.config["FullScreenSupportEnabled"]: self.settings().setAttribute( QWebEngineSettings.FullScreenSupportEnabled, True) else: self.settings().setAttribute( QWebEngineSettings.FullScreenSupportEnabled, False) if self.config["AllowWindowActivationFromJavaScript"]: self.settings().setAttribute( QWebEngineSettings.AllowWindowActivationFromJavaScript, True) else: self.settings().setAttribute( QWebEngineSettings.AllowWindowActivationFromJavaScript, False) if self.config["LocalContentCanAccessRemoteUrls"]: self.settings().setAttribute( QWebEngineSettings.LocalContentCanAccessRemoteUrls, True) else: self.settings().setAttribute( QWebEngineSettings.LocalContentCanAccessRemoteUrls, False) if self.config["JavascriptCanAccessClipboard"]: self.settings().setAttribute( QWebEngineSettings.JavascriptCanAccessClipboard, True) else: self.settings().setAttribute( QWebEngineSettings.JavascriptCanAccessClipboard, False) if self.config["SpatialNavigationEnabled"]: self.settings().setAttribute( QWebEngineSettings.SpatialNavigationEnabled, True) else: self.settings().setAttribute( QWebEngineSettings.SpatialNavigationEnabled, False) if self.config["TouchIconsEnabled"]: self.settings().setAttribute(QWebEngineSettings.TouchIconsEnabled, True) else: self.settings().setAttribute(QWebEngineSettings.TouchIconsEnabled, False) if self.config["FocusOnNavigationEnabled"]: self.settings().setAttribute( QWebEngineSettings.FocusOnNavigationEnabled, True) else: self.settings().setAttribute( QWebEngineSettings.FocusOnNavigationEnabled, False) if config["online"]: self.settings().setAttribute(QWebEngineSettings.DnsPrefetchEnabled, True) print("Engine online (IPC) Disabled") self.page().profile().downloadRequested.connect( self._download_requested) # Set persistent cookies self.profile.setPersistentCookiesPolicy( QWebEngineProfile.ForcePersistentCookies) # set cookies on user folder if config["cookies_path"]: # allow specific path per application. _cookies_path = f"{os.getenv('HOME')}/.jak/{config['cookies_path']}" else: # use separate cookies database per application title = config["title"].lower().replace(" ", "-") _cookies_path = f"{os.getenv('HOME')}/.jak/{title}" self.profile.setPersistentStoragePath(_cookies_path) print(f"Cookies PATH:{_cookies_path}") else: self.settings().setAttribute(QWebEngineSettings.ShowScrollBars, False) print("Engine interprocess communication (IPC) up and running:") self._ipc_scheme_handler = IpcSchemeHandler() self.profile.installUrlSchemeHandler('ipc'.encode(), self._ipc_scheme_handler) if config["webChannel"]["active"]: from JAK.Utils import JavaScript if bindings() == "PyQt5": from PyQt5.QtCore import QFile, QIODevice from PyQt5.QtWebChannel import QWebChannel webchannel_js = QFile(':/qtwebchannel/qwebchannel.js') webchannel_js.open(QIODevice.ReadOnly) webchannel_js = bytes(webchannel_js.readAll()).decode('utf-8') webchannel_js += """ var JAK; new QWebChannel(qt.webChannelTransport, function (channel) { JAK = channel.objects.Bridge; });""" JavaScript.inject(self.page(), { "JavaScript": webchannel_js, "name": "QWebChannel API" }) self.channel = QWebChannel(self.page()) if config["webChannel"]["shared_obj"]: self.bridge_obj = config["webChannel"]["shared_obj"] else: raise NotImplementedError("QWebChannel shared QObject") self.channel.registerObject("Bridge", self.bridge_obj) self.page().setWebChannel(self.channel) print("QWebChannel bridge active") self.profile.setRequestInterceptor(self.interceptor) print(self.profile.httpUserAgent()) validate_url(self, config["web_contents"])
def _inject_script(self, script: dict): from JAK.Utils import JavaScript JavaScript.inject(self.page(), script)
def show(): JavaScript.send("desktop.closeSettings();desktop.closeApplications();") Desktop.showScreen()
def update(self, *args): from JAK.Utils import JavaScript JavaScript.send(f"Jade.menu = { json.dumps( self.menu() ) }")