(Enhancement) Support Qt sessions/KDE Activities

Anki desktop for Linux does not correctly support KDE Activities (userbase.kde. org/Plasma#Activities).

The biggest problem to me is that if I close an activity but forget to close Anki first, Anki remains as a ‘zombie process’. See this in action:
youtu.be LhuSRUw5XeA

Not just KDE programs work correctly with activities. As you can see in the recording, Thunderbird (has nothing to do with KDE or Qt AFAIK), works perfectly. Anki is written in Qt, which is very close to KDE, so I thought perhaps adding activity support is just implementing a simple callback or enabling some option.

Unfortunately, there is no easily accessible information how to make a Qt application handle KDE Activities correctly. I found a GitHub issue where people claim to correctly implement activities support in a Python application (github.c om/git-cola/git-cola/issues/164). People say that activities are based on XSMP protocol – I wasn’t able to verify it. I assume that Qt has an abstraction layer over session handling, so I looked on the official docs in doc.qt.i o/qt-6/session.html.

My knowledge of Qt and Python is minimal. I tried to fiddle a bit with Anki code, but with no success. My code was:

class AnkiApp(QApplication):

    # Single instance support on Win32/Linux
    ##################################################

    appMsg = pyqtSignal(str)

    KEY = f"anki{checksum(getpass.getuser())}"
    TMOUT = 30000

    def __init__(self, argv: list[str]) -> None:
        QApplication.__init__(self, argv)
        self.installEventFilter(self)
        self._argv = argv
        print('connecting slot')
        self.commitDataRequest.connect(lambda manager: self.commitData(manager))
        self.saveStateRequest.connect(lambda manager: self.saveState(manager))
        self.applicationStateChanged.connect(lambda manager: self.stateChanged(manager))

    #@QtCore.pyqtSlot(QtGui.QSessionManager)
    def commitData(self, manager):
        print('commit data')

    def saveState(self, manager):
        print('save state')

    def stateChanged(self, state):
        print('state changed ' + str(state))

Out of my slots, only stateChanged was executed. Naturally, after my modifications there wasn’t any improvement. Maybe Qt Session Management has nothing to do with KDE Activities. Or maybe session slots were not called because Anki does something in a specific way. I don’t know.

My request is to support activities at a very minimum level. Just a clean shutdown of Anki when an activity is stopped would be terrific. Running Anki again when the activity is started again would be a nice plus, but is less critical (I can always start it manually, it’s a minor inconvenience compared to a zombie process).