1

I am trying to make a KDE Wallpaper Plugin. The QML code works fine. But when I try to connect a js script, even without invoking any functions the wallpaper plugin doesn't work.

QML Code:

import QtQuick 2.1

import QtQuick.Layouts 1.1

import org.kde.plasma.core 2.0
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.extras 2.0 as PlasmaExtras
import "datecompare.js" as decider

import org.kde.plasma.private.konbanwa 1.0

Item {
    id: root

    Rectangle {
        id: backgroundRect
        anchors.fill: parent
        Image{
              id: backgroundImage
              height: parent.height
              width: parent.width
              fillMode: Image.PreserveAspectCrop
              source: decider.deciding()
             }
    }
}

JS Code:

.pragma library


var today = new Date();
var syshour = today.getHours(); 
var sysminutes =  today.getMinutes(); 
var usertimehour = 17;
var usertimeminutes = 50;


function deciding () { 
    
    if (syshour >= usertimehour) {
    if (sysminutes>= usertimeminutes) {
        return "img/night2.png";
        }
    if (sysminutes < usertimeminutes){
        return "img/day.jpg";
        }
        
        }
    else {
        return "img/day.jpg";                
        }

}

I checked by myself several times but since I am beginner to javascript, it could be a small mistake that I oversaw. If its done wrong, how can I do it?

0

1 Answer 1

2

It seems that it is not documented but when importing the javascript the alias must start with capital letters, on the other hand the function will run once but it seems that you want it to run depending on the time so you should use a Timer:

import QtQuick 2.1

import QtQuick.Layouts 1.1

import org.kde.plasma.core 2.0
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.extras 2.0 as PlasmaExtras

import "datecompare.js" as Decider

// import org.kde.plasma.private.konbanwa 1.0

Item {
    id: root
    Timer{
        interval: 1000
        repeat: true
        running: true
        onTriggered: backgroundImage.source = Decider.deciding()
    }

    Rectangle {
        id: backgroundRect
        anchors.fill: parent
        Image{
            id: backgroundImage
            height: parent.height
            width: parent.width
            fillMode: Image.PreserveAspectCrop
        }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.