Fixing KDE Connect's Windows Notification Custom Actions
Today I forked KDE Connect, one of those excellent if rough round the edges projects I use everyday bring your phone (Android or iOS!!!) and desktop (Windows, macOS, GNU/Linux) together with features like notification syncing, remote control, file transfers, clipboard sharing, and much more that I never use.
I have taken the time to fix something that has been broken for a long time: custom notification actions on Windows.
In the current release, you can trigger notification actions on Linux, but not on Windows, as custom notifications are not exposed through the Win32 toast API.
I actually had some prior experience with this at university, Nottingham Trent, where I used BurntToast to post Windows notifications for a simple Android app I made that converted cooking times between microwave power levels. Most ready meals only listed instructions for 800 W or 900 W microwaves, so I had an inkling of the arguments Windows toasts accepted.
It turned out there were also compatibility issues with KDE Connect's own Android client. Luckily, I already had the required toolchains configured from yesterday's excursions.
Desktop Changes
The Windows desktop fork now:
- Shows Android notification actions as native Windows toast buttons, preserving exact labels such as
Pause,Turn Off,Watch Later,Archive, andMark as read. - Registers KDE Connect's Windows toast activator so clicking a toast button routes the action back through KDE Connect.
- Handles Windows' limitation where inline replies and ordinary toast buttons cannot appear together.
- Displays the same custom actions in the main app's notification history.
- Stores the latest 100 notifications as unencrypted JSON in the existing per device configuration.
- Restores notification history after restarts while disabling actions for notifications that are no longer active.
- Retries the notification history D Bus connection during startup to avoid an empty or broken history panel.
- Leaves platform specific toast behaviour outside Windows unchanged.
Android Change
The Android fork contains one functional code change:
if (a.title.toString() == title)
Previously, it used:
if (a.title == title)
Android notification action titles are CharSequence objects and may actually be styled objects such as SpannableString. KDE Connect sends the displayed title over the network as a plain JSON String.
Although both values display identical text, comparing a styled CharSequence directly with a plain String will fail obviously as they are not the same.
Converting the Android title with toString() makes the comparison text based (always be based), allowing the Windows toast and desktop history buttons to invoke the correct Android PendingIntent.
Submitted
I have submitted my changes to KDE. If they are not accepted, at least there is now a build that does this. <3
Repos:
invent.kde.org/unenvied/kdeconnect-kde-fork
invent.kde.org/unenvied/kdeconnect-android
Peace ✌️