1

我很难找到有关如何为 plasmoid 编写通知的任何文献或示例。

到目前为止,当满足某些条件时,我的 plasmoid 可以显示通知和声音警报,但我不知道如何:

  1. 在通知中添加“关闭”按钮以停止连续播放警报,或
  2. 通知关闭时让警报停止响起。

到目前为止,这是我的(删节)代码:

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
        }
    }
...
}
4

0 回答 0