When opening files by file-browsers on fresh images, user has to choose the application to open from the pool af ALL known applications even those not designed to open the file selected. By inheriting this classs in recipes the assosiations in /usr/share/applications/mimeinfo.cache are build by calling update-desktop-database.
Signed-off-by: Andreas Müller <[email protected]> --- meta/classes/mime-xdg.bbclass | 62 +++++++++++++++++++ .../update_desktop_database | 8 +++ 2 files changed, 70 insertions(+) create mode 100644 meta/classes/mime-xdg.bbclass create mode 100644 scripts/postinst-intercepts/update_desktop_database diff --git a/meta/classes/mime-xdg.bbclass b/meta/classes/mime-xdg.bbclass new file mode 100644 index 0000000000..07194ce037 --- /dev/null +++ b/meta/classes/mime-xdg.bbclass @@ -0,0 +1,62 @@ +# +# This class creates mime <-> application associations based on entry +# 'MimeType' in *.desktop files +# + +DEPENDS += "desktop-file-utils" +PACKAGE_WRITE_DEPS += "desktop-file-utils-native" + +mime_xdg_postinst() { +if [ "x$D" != "x" ]; then + $INTERCEPT_DIR/postinst_intercept update_desktop_database ${PKG} \ + mlprefix=${MLPREFIX} \ + desktop_dir=${desktopdir} +else + update-desktop-database $D${desktopdir} +fi +} + +mime_xdg_postrm() { +if [ "x$D" != "x" ]; then + $INTERCEPT_DIR/postinst_intercept update_desktop_database ${PKG} \ + mlprefix=${MLPREFIX} \ + desktop_dir=${desktopdir} +else + update-desktop-database $D${desktopdir} +fi +} + +python populate_packages_append () { + import re + packages = d.getVar('PACKAGES').split() + pkgdest = d.getVar('PKGDEST') + desktop_base = d.getVar('desktopdir') + + for pkg in packages: + desktop_dir = '%s/%s%s' % (pkgdest, pkg, desktop_base) + desktops_with_mime_found = False + if os.path.exists(desktop_dir): + for df in os.listdir(desktop_dir): + if df.endswith('.desktop'): + with open(desktop_dir + '/'+ df, 'r') as f: + for line in f.read().split('\n'): + if 'MimeType' in line: + desktops_with_mime_found = True + break; + if desktops_with_mime_found: + break + if desktops_with_mime_found: + bb.note("adding mime-xdg postinst and postrm scripts to %s" % pkg) + postinst = d.getVar('pkg_postinst_%s' % pkg) + if not postinst: + postinst = '#!/bin/sh\n' + postinst += d.getVar('mime_xdg_postinst') + d.setVar('pkg_postinst_%s' % pkg, postinst) + postrm = d.getVar('pkg_postrm_%s' % pkg) + if not postrm: + postrm = '#!/bin/sh\n' + postrm += d.getVar('mime_xdg_postrm') + d.setVar('pkg_postrm_%s' % pkg, postrm) + bb.note("adding desktop-file-utils dependency to %s" % pkg) + d.appendVar('RDEPENDS_' + pkg, " " + d.getVar('MLPREFIX')+"desktop-file-utils") +} 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 @@ +#!/bin/sh +# +# SPDX-License-Identifier: MIT +# +# Post-install intercept for mime-xdg.bbclass + +update-desktop-database $D${desktop_dir} + -- 2.21.0 -- _______________________________________________ Openembedded-core mailing list [email protected] http://lists.openembedded.org/mailman/listinfo/openembedded-core
