Add auto-away feature for Linux X11
This commit is contained in:
45
src/gui/IdleManager.qml
Normal file
45
src/gui/IdleManager.qml
Normal 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()
|
||||
}
|
||||
}
|
@@ -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
|
||||
|
Reference in New Issue
Block a user