def configure_drop_cache_on_changes(cache): '''Configure :cache: to be dropped when the Flatpak installation state changes. This creates a Gio.FileMonitor over each of the configured Flatpak installations on the system and drops all caches when they change. Note that we cannot use the Flatpak API here directly as we are running from within Flatpak. We are relying on an internal implementation detail, namely that Flatpak itself will update ".changed" in the installation directory on state changes. ''' def _on_installation_changed(*args): '''Callback for when something changes.''' del args cache.clear() return list( yield_monitors_over_changed_file_in_paths( EosCompanionAppService.flatpak_install_dirs(), _on_installation_changed ) )
def main(args=None): '''Entry point function. Since we're often running from within flatpak, make sure to override XDG_DATA_DIRS to include the flatpak exports too, since they don't get included by default. We use GLib.setenv here, since os.environ is only visible to Python code, but setting a variable in os.environ does not actually update the 'environ' global variable on the C side. ''' flatpak_export_share_dirs = [ os.path.join(d, 'exports', 'share') for d in EosCompanionAppService.flatpak_install_dirs() ] GLib.setenv( 'XDG_DATA_DIRS', os.pathsep.join([GLib.getenv('XDG_DATA_DIRS') or ''] + flatpak_export_share_dirs), True) logging.basicConfig( format='CompanionAppService %(levelname)s: %(message)s', level=get_log_level()) CompanionAppApplication().run(args or sys.argv)