1

I'm having a hard time finding any literature or examples on how to write notifications for plasmoids.

My plasmoid can so far display notifications and sound alarms when certain conditions are met but i don't know how to:

  1. add a 'Dismiss' button to the notification to stop playing a continuous alarm, or
  2. get the alarm to stop sounding when the notification is closed.

This is my (abridged) code so far:

PlasmaCore.DataSource {
    id: notificationSource
    engine: "notifications"
}

SoundEffect {
    id: notificationSound
    source: plasmoid.file("data", "beep-alarm.wav")
    loops: SoundEffect.Infinite
}

function createNotification(text) {
    var service = notificationSource.serviceForSource("notification");
    var operation = service.operationDescription("createNotification");

    operation["appName"] = root.appName;
    operation["appIcon"] = plasmoid.configuration.icon;
    operation.summary = root.title;
    operation["body"] = '<b>' + text + '</b>';
    operation["expireTimeout"] = 0;
    operation["isPersistent"] = 'isPersistent';
    operation["urgency"] = 2;

    var tmp = service.startOperationCall(operation);
    if (plasmoid.configuration.alarmEnabled) {
        notificationSound.play();
    }
}

Plasmoid.compactRepresentation: Item {
...
    PlasmaComponents.Label {
        text: {
            if (Number(root.x) >= plasmoid.configuration.y) {
                root.createNotification(root.x);
            }
            root.x
        }
    }
...
}
yamahama
  • 39
  • 2
  • I'm in the same boat as you. I also have added actions to the notifications, and the buttons show. But how to read the result escape from my knowledge and can't find anything. – Marc Carné Bori Feb 12 '19 at 16:18

0 Answers0