Add auto-away feature for Linux X11

This commit is contained in:
miruka
2020-07-11 00:51:53 -04:00
parent 10f47f71ac
commit 3c620f6fd1
10 changed files with 107 additions and 15 deletions

45
src/gui/IdleManager.qml Normal file
View File

@@ -0,0 +1,45 @@
// SPDX-License-Identifier: LGPL-3.0-or-later
import QtQuick 2.12
import CppUtils 0.1
import "."
Timer {
readonly property ListModel accounts: ModelStore.get("accounts")
readonly property var accountsSet: new Set()
function setPresence(userId, presence) {
py.callClientCoro(userId, "set_presence", [presence, undefined, false])
}
interval: 1000
running: window.settings.beUnavailableAfterSecondsIdle > 0
repeat: true
onTriggered: {
let changes = false
const beUnavailable =
CppUtils.idleMilliseconds() / 1000 >=
window.settings.beUnavailableAfterSecondsIdle
for (let i = 0; i < accounts.count; i++) {
const account = accounts.get(i)
if (beUnavailable && account.presence === "online") {
setPresence(account.id, "unavailable")
accountsSet.add(account.id)
changes = true
} else if (! beUnavailable && accountsSet.has(account.id)) {
setPresence(account.id, "online")
accountsSet.delete(account.id)
changes = true
}
}
if (changes) accountsSetChanged()
}
}

View File

@@ -33,6 +33,7 @@ Item {
readonly property alias pageLoader: pageLoader
readonly property alias pressAnimation: pressAnimation
readonly property alias fontMetrics: fontMetrics
readonly property alias idleManager: idleManager
function reloadSettings() {
@@ -96,6 +97,10 @@ Item {
visible: false
}
IdleManager {
id: idleManager
}
LinearGradient {
id: mainUIGradient
visible: ! image.visible