警报& Plasmoids的通知

时间:2018-03-12 13:02:38

标签: notifications qml plasmoid

我很难找到关于如何为plasmoids写通知的任何文献或例子。

我的等离子体可以在满足某些条件时显示通知和声音警报,但我不知道如何:

  1. 在通知中添加“关闭”按钮以停止播放连续闹铃,或
  2. 在通知关闭时收到警报以停止发声。
  3. 到目前为止,这是我的(删节)代码:

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

0 个答案:

没有答案