Add a "Share via Telegram plugin". It's a copy of the KDE Connect plugin with name/command substituted. Telegram expects the path without file:// prefix so it is removed when found.
If it's 99% identical except for the name and command, would it make more sense to create a generic "send to app/service" plugin that you can feed different executables into? Then we could even expose that configuration in the UI somewhere to allow people to easily define their own!
Also I would Check if(url.isLocalFile()).
Instead of finding the program, we could execute using org.telegram.desktop.desktop, it would allow it to work even if it's installed from appimage/flatpak.
I'm not sure how this would work without bumping the tier.
Fix or remove debug message.
I've played around with flatpaked Telegram and made it working. However:
My Telegram.desktop file executes this:
/usr/bin/flatpak run --branch=stable --arch=x86_64 --command=telegram-desktop --file-forwarding org.telegram.desktop -- @@u %u @@
I can share a file using
/usr/bin/flatpak run --branch=stable --arch=x86_64 --command=telegram-desktop --file-forwarding org.telegram.desktop -sendpath @@ /home/nico/test.py @@
But that would require changing the command I get from the desktop file. I can achieve the same goal just by appending something to the command from the desktop file:
/usr/bin/flatpak run --branch=stable --arch=x86_64 --command=telegram-desktop --file-forwarding org.telegram.desktop -- @@u %u @@ -sendpath @@ /home/nico/test.py @@
However, appending this to the command does not work with the regular command.
I don't see any way to support all without some special-case handling for flatpak. I didn't even test snap.
I'm not quite sure what to do. Best I came up with is something like
execStr = parseExec() if (execStr.contains("flatpak")) execStr += "-sendpath @@ url @@" else execStr += "-sendpath url"
Is this what you had in mind?
I played around a bit and it turns out more difficult than expected.
- telegram-desktop-bin from AUR has telegramdesktop.desktop whereas the Flatpak version has org.telegram.desktop.desktop, so we would need to look for at least those desktop files
- the flatpak command needs @@ around the url, the AUR version not
- the flatpak command contains "--" which hinders the appending of the -sendpath parameter
This makes parsing the desktop file and building the correct command utterly complex and when we know whether its flatpak or not we know the overall command
My much simpler suggestion would be hardcoding the two commands and try them all until we succeed.
Those would be
telegram-desktop $URL (regular package)
/usr/bin/flatpak run --file-forwarding org.telegram.desktop -sendpath @@ $URL @@ (flatpak)
More commands (e.g. for Snap) could be added, making it more maintainable than complex and error-prone parsing (which would also rely on case-handling and assumptions)