Skip to content

Instantly share code, notes, and snippets.

@NonLogicalDev
Last active February 17, 2025 23:03
Show Gist options
  • Save NonLogicalDev/f518e93aa19d3fc620bae15d388cba58 to your computer and use it in GitHub Desktop.
Save NonLogicalDev/f518e93aa19d3fc620bae15d388cba58 to your computer and use it in GitHub Desktop.
Fix up KDE apps distributed as flatpacks being unable to open Remote files (ex: Samba shares) from Dolphin (File Explorer)

KDE Flatpak Remote File Fix

Context: Fedora/Bazzite/Kinoite/universal-blue/KDE/Flatpacks

The Problem

When using KDE applications (like Okular or Gwenview) installed as Flatpaks in Fedora KDE Bazzite or other containerized Linux distributions, they may fail to open remote files (like those on Samba shares) when launched from Dolphin File Explorer.

Example error from Okular:

Could not open smb://... Reason: Unable to create KIO worker. Unknown protocol 'smb'.

Quick Fix

Run this command in your terminal:

curl -s https://gist.githubusercontent.com/NonLogicalDev/f518e93aa19d3fc620bae15d388cba58/raw/068b82a4c7ca32ec7c8428b72dda196520f2e888/fixup-kde-flatpacks.py | python3 -

After running the script, highly suggest to reboot the system to ensure KDE picks those new entries as defaults, instead of orginal flatpack exported ones.

(Let me know in the comments if you know of a better way to force KDE to re-index .desktop files)

What it Does

  • Identifies Flatpak KDE applications on your system
  • Creates modified .desktop files that allow KDE apps to properly handle remote files
  • Places these modified files in ~/.local/share/applications/flatpak-overrides
  • Does not modify your original Flatpak installations

Technical Details

This temporarily works around KDE Bug #477615 by removing the KDE category from application desktop entries, which forces Dolphin to resolve remote URLs to local mount points before launching the applications.

Affected Applications

  • Okular (PDF viewer)
  • Gwenview (Image viewer)
  • Other KDE Flatpak applications that need to access remote files

Confirmed working in:

For Fedora/uBlue variants: Combo of neofetch and rpm-ostree status

Fedora 41 / Bazzite

Bazzite 41 (FROM Fedora Kinoite)

● ostree-image-signed:docker://ghcr.io/ublue-os/bazzite-nvidia:stable
                   Digest: sha256:8d112f5c3cc01c4dd5b6d7ba80d4ff82d146594f5a81c089c0e7cc120be0a751
                  Version: 41.20241125 (2024-11-26T03:48:04Z)

Per @ninagrosse (thank you for validating):

Aurora-dx 41 (FROM Fedora Kinoite)

● ostree-image-signed:docker://ghcr.io/ublue-os/aurora-dx:stable
                   Digest: sha256:3b5b44627aed06d59fccbe2edd904a743a84601965ef23776b5dcd5b44ce832d
                  Version: 41.20241216.1 (2024-12-16T13:48:37Z)
#!/usr/bin/env python3
import os
import shutil
from pathlib import Path
import re
def find_desktop_files():
"""Find all .desktop files in flatpak export directories."""
flatpak_dirs = [
os.path.expanduser('~/.local/share/flatpak/exports/share/applications'),
'/var/lib/flatpak/exports/share/applications'
]
desktop_files = []
for directory in flatpak_dirs:
if os.path.exists(directory):
desktop_files.extend([
os.path.join(directory, f)
for f in os.listdir(directory)
if f.endswith('.desktop')
])
return desktop_files
def has_kde_category(lines):
"""Check if the desktop file content has a KDE category."""
for line in lines:
if line.startswith('Categories='):
return 'KDE;' in line or ';KDE;' in line or line.endswith(';KDE')
return False
def process_desktop_file(source_path, target_dir):
"""Process a desktop file by removing KDE category and updating the Name."""
# Read the original file
with open(source_path, 'r', encoding='utf-8') as f:
lines = f.readlines()
# Process the lines
processed_lines = []
in_desktop_entry = False
for line in lines:
# Keep track of whether we're in the [Desktop Entry] section
if line.strip() == '[Desktop Entry]':
in_desktop_entry = True
elif line.startswith('['):
in_desktop_entry = False
# Only modify lines in the [Desktop Entry] section
if in_desktop_entry:
# Handle Categories
if line.startswith('Categories='):
categories = line.strip().split('=')[1].split(';')
categories = [cat for cat in categories if cat != 'KDE' and cat]
line = 'Categories=' + ';'.join(categories) + ';\n'
# Handle Name entries
elif line.startswith('Name=') or line.startswith('Name['):
key, value = line.strip().split('=', 1)
if not value.endswith('(KDE)'):
line = f"{key}={value} (KDE)\n"
processed_lines.append(line)
# Create target directory if it doesn't exist
os.makedirs(target_dir, exist_ok=True)
# Write to new location
filename = os.path.basename(source_path)
target_path = os.path.join(target_dir, filename)
with open(target_path, 'w', encoding='utf-8') as f:
f.writelines(processed_lines)
def main():
target_dir = os.path.expanduser('~/.local/share/applications/flatpak-overrides')
# Ensure target directory exists
try:
os.makedirs(target_dir, exist_ok=True)
except PermissionError:
print(f"Error: Cannot create target directory: {target_dir}")
print("Please check your permissions and try again.")
return
except Exception as e:
print(f"Error creating target directory: {e}")
return
desktop_files = find_desktop_files()
processed_count = 0
for file_path in desktop_files:
with open(file_path, 'r', encoding='utf-8') as f:
content = f.readlines()
if has_kde_category(content):
print("FOUND:", file_path)
process_desktop_file(file_path, target_dir)
processed_count += 1
print(f"Processed {processed_count} KDE desktop files")
print(f"Modified files have been saved to: {target_dir}")
if __name__ == "__main__":
main()
@NonLogicalDev
Copy link
Author

Thank you @ninagrosse, good point will add suggestion to restart the system, I think that was enough for me to get the KDE to pick the overloaded .desktop entries as defaults.

@sbancuz
Copy link

sbancuz commented Dec 19, 2024

Hi, thank you so much for this!! I can also confirm that works on Ublue Kinoite

● ostree-image-signed:docker://ghcr.io/ublue-os/kinoite-main:latest
                   Digest: sha256:b23cf5775e980a8034b108ae5d84ea29ce0cadb299cf81b2f314969cd0555e10
                  Version: 41.20241219.0 (2024-12-19T04:16:24Z)
          LayeredPackages: hunspell-it plasma-workspace-x11 podman-compose qphotorec

One little thing (but not really a big deal), after running the script only okular (KDE) was set as the default. Gwenview however remained the non (KDE) version, but it sill created the new .desktop file.

EDIT: Also for some reason I can't access directly the smb share, so when I try to open the shared folder it fails. To see more than one image I have to do ctrl+a -> open with Gwenview (KDE)

@B-T-ND
Copy link

B-T-ND commented Feb 17, 2025

Thank you! ❤️
worked on bazzite

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment