Apply saved settings

Signed-off-by: Juraj Oravec <sgd.orava@gmail.com>
This commit is contained in:
Juraj Oravec 2019-06-20 21:41:29 +02:00
parent c887232dff
commit bbce8c6ee1
No known key found for this signature in database
GPG Key ID: 63ACB65056BC8D07
3 changed files with 59 additions and 3 deletions

View File

@ -36,7 +36,10 @@ class Readability(Falkon.PluginInterface, QtCore.QObject):
self.config = {
"settingsFile": os.path.join(settingsPath, "readability", "settings.ini"),
"icon": "dark",
"contextMenu": False
"contextMenu": False,
"colorTheme": "sepia",
"font": "sans-serif",
"fontSize": 5
}
self.buttons = {}
self.loadSettings()
@ -153,7 +156,16 @@ class Readability(Falkon.PluginInterface, QtCore.QObject):
self.scriptCall = self.scriptCall.replace("{toolbar.js}", self.scriptToolbar)
self.scriptCall = self.scriptCall.replace("{style.css}", self.style)
self.view.page().runJavaScript(self.scriptCall)
initConfigScript = "initConfig('{}', '{}', {});".format(
self.config["colorTheme"],
self.config["font"],
self.config["fontSize"]
)
self.view.page().runJavaScript(
self.scriptCall + initConfigScript,
Falkon.WebPage.SafeJsWorld
)
def showSettings(self, parent):
settings = SettingsDialog(self.config, parent)
@ -167,6 +179,9 @@ class Readability(Falkon.PluginInterface, QtCore.QObject):
settings.beginGroup("Readability")
settings.setValue("icon", self.config["icon"])
settings.setValue("showInContextMenu", self.config["contextMenu"])
settings.setValue("colorTheme", self.config["colorTheme"])
settings.setValue("font", self.config["font"])
settings.setValue("fontSize", self.config["fontSize"])
settings.endGroup()
settings.sync()
@ -179,6 +194,9 @@ class Readability(Falkon.PluginInterface, QtCore.QObject):
self.config["contextMenu"] = str2bool(
settings.value("showInContextMenu", self.config["contextMenu"])
)
self.config["colorTheme"] = str(settings.value("colorTheme", self.config["colorTheme"]))
self.config["font"] = str(settings.value("font", self.config["font"]))
self.config["fontSize"] = int(settings.value("fontSize", self.config["fontSize"]))
settings.endGroup()
def onConfigUpdate(self):

View File

@ -108,4 +108,28 @@ function renderPage(article){
}
}
callReadability();
function initConfig(colorTheme, font, fontSize){
switch(colorTheme) {
case "light":
switchToLight();
break;
case "dark":
switchToDark();
break;
case "sepia":
default:
switchToSepia();
}
switch(font){
case "serif":
switchToSerif();
break;
case "sans-serif":
default:
switchToSansSerif();
}
fontSizeSet(fontSize);
}
callReadability();

View File

@ -143,3 +143,17 @@ function fontSizeMinus(){
}
}
}
function fontSizeSet(fontSize){
if (fontSize < 1 || fontSize > 9)
return
var container = document.getElementById('container');
for (var i = 0; i < container.classList.length; i++){
if(container.classList[i].indexOf('font-size') > -1){
container.classList.remove(container.classList[i]);
container.classList.add('font-size' + fontSize);
return;
}
}
}