Skip to content
This repository has been archived by the owner on Oct 29, 2018. It is now read-only.

Improve webkit memory usage (#595) #596

Merged
merged 1 commit into from
Sep 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions scudcloud/scudcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from PyQt5.QtCore import QUrl, QSettings
from PyQt5.QtWebKit import QWebSettings
from PyQt5.QtWebKitWidgets import QWebPage
from PyQt5.QtNetwork import QNetworkDiskCache
from PyQt5.QtNetwork import QNetworkDiskCache, QNetworkAccessManager

# Auto-detection of dbus and dbus.mainloop.qt
try:
Expand Down Expand Up @@ -122,13 +122,12 @@ def sendTickle(self):

def addWrapper(self, url):
webView = Wrapper(self)
webView.page().networkAccessManager().setCookieJar(self.cookiesjar)
webView.page().networkAccessManager().setCache(self.diskCache)
webView.load(QtCore.QUrl(url))
webView.show()
webView.setZoomFactor(self.zoom)
self.stackedWidget.addWidget(webView)
self.stackedWidget.setCurrentWidget(webView)
self.clearMemory()

def webSettings(self):
self.cookiesjar = PersistentCookieJar(self)
Expand All @@ -148,6 +147,10 @@ def webSettings(self):
QWebSettings.globalSettings().setAttribute(QWebSettings.JavascriptCanAccessClipboard, True)
# Enabling Inspeclet only when --debug=True (requires more CPU usage)
QWebSettings.globalSettings().setAttribute(QWebSettings.DeveloperExtrasEnabled, self.debug)
# Sharing the same networkAccessManager
self.networkAccessManager = QNetworkAccessManager(self)
self.networkAccessManager.setCookieJar(self.cookiesjar)
self.networkAccessManager.setCache(self.diskCache)

def snippetsSettings(self):
self.disable_snippets = self.settings.value("Snippets")
Expand Down Expand Up @@ -363,6 +366,7 @@ def switchTo(self, url):
self.quicklist(self.current().listChannels())
self.current().setFocus()
self.leftPane.click(i)
self.clearMemory()
exists = True
break
if not exists:
Expand Down Expand Up @@ -481,3 +485,7 @@ def count(self):
self.launcher.set_property("count_visible", True)
self.setWindowTitle("[{}]{}".format(str(total), self.title))
self.messages = total

def clearMemory(self):
QWebSettings.globalSettings().clearMemoryCaches()
QWebSettings.globalSettings().clearIconDatabase()
5 changes: 4 additions & 1 deletion scudcloud/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ def __init__(self, window):
if self.window.disable_snippets:
with open(Resources.get_path('disable_snippets.js'), 'r') as f:
self.disable_snippets_js = f.read()
self.setPage(Browser())
page = Browser()
page.setNetworkAccessManager(window.networkAccessManager)
self.setPage(page)
self.page().setLinkDelegationPolicy(QWebPage.DelegateAllLinks)
self.urlChanged.connect(self._urlChanged)
self.loadStarted.connect(self._loadStarted)
Expand Down Expand Up @@ -240,6 +242,7 @@ def populate(self, serialized):
# Download the file to use in notifications
self.downloader = Downloader(self, data['icon'], icon_path)
self.downloader.start()
self.window.clearMemory()

@QtCore.pyqtSlot(bool)
def enableMenus(self, enabled):
Expand Down