diff options
| -rw-r--r-- | meta/classes/mime-xdg.bbclass | 74 | ||||
| -rw-r--r-- | scripts/postinst-intercepts/update_desktop_database | 8 |
2 files changed, 82 insertions, 0 deletions
diff --git a/meta/classes/mime-xdg.bbclass b/meta/classes/mime-xdg.bbclass new file mode 100644 index 0000000000..63169e990d --- /dev/null +++ b/meta/classes/mime-xdg.bbclass | |||
| @@ -0,0 +1,74 @@ | |||
| 1 | # | ||
| 2 | # This class creates mime <-> application associations based on entry | ||
| 3 | # 'MimeType' in *.desktop files | ||
| 4 | # | ||
| 5 | |||
| 6 | DEPENDS += "desktop-file-utils" | ||
| 7 | PACKAGE_WRITE_DEPS += "desktop-file-utils-native" | ||
| 8 | DESKTOPDIR = "${datadir}/applications" | ||
| 9 | |||
| 10 | # There are recipes out there installing their .desktop files as absolute | ||
| 11 | # symlinks. For us these are dangling and cannot be introspected for "MymeType" | ||
| 12 | # easily. By addding package-names to MIME_XDG_PACKAGES, packager can force | ||
| 13 | # proper update-desktop-database handling. Note that all introspection is | ||
| 14 | # skipped for MIME_XDG_PACKAGES not empty | ||
| 15 | MIME_XDG_PACKAGES ?= "" | ||
| 16 | |||
| 17 | mime_xdg_postinst() { | ||
| 18 | if [ "x$D" != "x" ]; then | ||
| 19 | $INTERCEPT_DIR/postinst_intercept update_desktop_database ${PKG} \ | ||
| 20 | mlprefix=${MLPREFIX} \ | ||
| 21 | desktop_dir=${DESKTOPDIR} | ||
| 22 | else | ||
| 23 | update-desktop-database $D${DESKTOPDIR} | ||
| 24 | fi | ||
| 25 | } | ||
| 26 | |||
| 27 | mime_xdg_postrm() { | ||
| 28 | if [ "x$D" != "x" ]; then | ||
| 29 | $INTERCEPT_DIR/postinst_intercept update_desktop_database ${PKG} \ | ||
| 30 | mlprefix=${MLPREFIX} \ | ||
| 31 | desktop_dir=${DESKTOPDIR} | ||
| 32 | else | ||
| 33 | update-desktop-database $D${DESKTOPDIR} | ||
| 34 | fi | ||
| 35 | } | ||
| 36 | |||
| 37 | python populate_packages_append () { | ||
| 38 | packages = d.getVar('PACKAGES').split() | ||
| 39 | pkgdest = d.getVar('PKGDEST') | ||
| 40 | desktop_base = d.getVar('DESKTOPDIR') | ||
| 41 | forced_mime_xdg_pkgs = (d.getVar('MIME_XDG_PACKAGES') or '').split() | ||
| 42 | |||
| 43 | for pkg in packages: | ||
| 44 | desktops_with_mime_found = pkg in forced_mime_xdg_pkgs | ||
| 45 | if d.getVar('MIME_XDG_PACKAGES') == '': | ||
| 46 | desktop_dir = '%s/%s%s' % (pkgdest, pkg, desktop_base) | ||
| 47 | if os.path.exists(desktop_dir): | ||
| 48 | for df in os.listdir(desktop_dir): | ||
| 49 | if df.endswith('.desktop'): | ||
| 50 | try: | ||
| 51 | with open(desktop_dir + '/'+ df, 'r') as f: | ||
| 52 | for line in f.read().split('\n'): | ||
| 53 | if 'MimeType' in line: | ||
| 54 | desktops_with_mime_found = True | ||
| 55 | break; | ||
| 56 | except: | ||
| 57 | bb.warn('Could not open %s. Set MIME_XDG_PACKAGES in recipe or add mime-xdg to INSANE_SKIP.' % desktop_dir + '/'+ df) | ||
| 58 | if desktops_with_mime_found: | ||
| 59 | break | ||
| 60 | if desktops_with_mime_found: | ||
| 61 | bb.note("adding mime-xdg postinst and postrm scripts to %s" % pkg) | ||
| 62 | postinst = d.getVar('pkg_postinst_%s' % pkg) | ||
| 63 | if not postinst: | ||
| 64 | postinst = '#!/bin/sh\n' | ||
| 65 | postinst += d.getVar('mime_xdg_postinst') | ||
| 66 | d.setVar('pkg_postinst_%s' % pkg, postinst) | ||
| 67 | postrm = d.getVar('pkg_postrm_%s' % pkg) | ||
| 68 | if not postrm: | ||
| 69 | postrm = '#!/bin/sh\n' | ||
| 70 | postrm += d.getVar('mime_xdg_postrm') | ||
| 71 | d.setVar('pkg_postrm_%s' % pkg, postrm) | ||
| 72 | bb.note("adding desktop-file-utils dependency to %s" % pkg) | ||
| 73 | d.appendVar('RDEPENDS_' + pkg, " " + d.getVar('MLPREFIX')+"desktop-file-utils") | ||
| 74 | } | ||
diff --git a/scripts/postinst-intercepts/update_desktop_database b/scripts/postinst-intercepts/update_desktop_database new file mode 100644 index 0000000000..8903b496f3 --- /dev/null +++ b/scripts/postinst-intercepts/update_desktop_database | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | # | ||
| 3 | # SPDX-License-Identifier: MIT | ||
| 4 | # | ||
| 5 | # Post-install intercept for mime-xdg.bbclass | ||
| 6 | |||
| 7 | update-desktop-database $D${desktop_dir} | ||
| 8 | |||
