Restart timers after hibernation/sleep (#1511)

Schedules get missed, if system has been in hibernation/sleep state as
described in https://github.com/borgbase/vorta/issues/1214
Although, timers should be refreshed every 15min, it seems that all timers get
deranged by sleep state and schedules is still missed in most cases. This seems
to be a general issue with the underlying QTimer implementation.

This fix doesn't distinguish host OS and has only by tested on Linux.
If 'org.freedesktop.login1.Manager' is not available, Vorta simple doesn't
get notified if system awakes again. No no impact on other OS is expected

Co-authored-by: yfprojects <62463991+real-yfprojects@users.noreply.github.com>
This commit is contained in:
fixmeee 2022-12-16 11:10:40 +01:00 committed by GitHub
parent b072496b31
commit 667f3b3779
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 1 deletions

View File

@ -4,7 +4,7 @@ import threading
from datetime import datetime as dt
from datetime import timedelta
from typing import Dict, NamedTuple, Optional, Tuple, Union
from PyQt5 import QtCore
from PyQt5 import QtCore, QtDBus
from PyQt5.QtCore import QTimer
from PyQt5.QtWidgets import QApplication
from vorta import application
@ -58,6 +58,25 @@ class VortaScheduler(QtCore.QObject):
# connect signals
self.app.backup_finished_event.connect(lambda res: self.set_timer_for_profile(res['params']['profile_id']))
# connect to `systemd-logind` to receive sleep/resume events
# The signal `PrepareForSleep` will be emitted before and after hibernation.
service = "org.freedesktop.login1"
path = "/org/freedesktop/login1"
interface = "org.freedesktop.login1.Manager"
name = "PrepareForSleep"
bus = QtDBus.QDBusConnection.systemBus()
if bus.isConnected() and bus.interface().isServiceRegistered(service).value():
self.bus = bus
self.bus.connect(service, path, interface, name, "b", self.loginSuspendNotify)
else:
logger.warn('Failed to connect to DBUS interface to detect sleep/resume events')
@QtCore.pyqtSlot(bool)
def loginSuspendNotify(self, suspend: bool):
if not suspend:
logger.debug("Got login suspend/resume notification")
self.reload_all_timers()
def tr(self, *args, **kwargs):
scope = self.__class__.__name__
return translate(scope, *args, **kwargs)