def _internal(_load_app_info_callback): def _on_got_application_info(_, result): '''Marshal the error and result into a tuple.''' try: info = application_listing_from_app_info( EosCompanionAppService.finish_load_application_info( result)) except GLib.Error as error: _load_app_info_callback(error, None) return _load_app_info_callback(None, info) application_id = desktop_id_to_app_id(desktop_id) EosCompanionAppService.load_application_info( application_id, cache, cancellable, _on_got_application_info)
def ascertain_application_sets_from_models(models, version, device_uuid, application_id, cache, cancellable, done_callback): '''Pass application sets or an entry for the global set to callback.''' def _on_received_application_info(_, result): '''Called when we receive requested application info.''' try: listing = application_listing_from_app_info( EosCompanionAppService.finish_load_application_info(result)) except Exception as error: done_callback(error, None) return done_callback(None, [{ 'tags': _GLOBAL_SET_INDICATOR_TAG, 'title': listing.display_name, 'contentType': 'application/x-ekncontent-set', 'thumbnail': format_app_icon_uri(version, listing.icon, device_uuid), 'id': '', 'global': True }]) try: any_featured = any([model.get('featured', True) for model in models]) application_sets_response = [ { 'tags': model['child_tags'], 'title': model['title'], 'contentType': 'application/x-ekncontent-set', 'thumbnail': optional_format_thumbnail_uri(version, application_id, model, device_uuid), 'id': urllib.parse.urlparse(model['id']).path[1:], 'global': False } for model in models # Filter out sets explicitly not marked featured, except # if nothing was featured - in that case include everything if model.get('featured', True) or not any_featured ] if application_sets_response: GLib.idle_add(done_callback, None, application_sets_response) return EosCompanionAppService.load_application_info( application_id, cache, cancellable=cancellable, callback=_on_received_application_info) except Exception as error: GLib.idle_add(done_callback, error, None)
def render_mobile_wrapper(renderer, app_id, rendered_content, metadata, content_db_conn, shards, version, query, cache, cancellable, callback): '''Render the page wrapper and initialize crosslinks. This is the final rendering step that EKN content needs to undergo before it becomes usable, at least before it leaves the server. This step initializes both a dictionary of metadata about the content and also a map of outgoing links to internal links. Then we inject some javascript which at browser-render time, rewrites the page to resolve all those links. ''' def _on_queried_sets(error, result): '''Called when we finish querying set objects.''' if error is not None: callback(error, None) return _, set_objects = result content_metadata = { 'title': metadata.get('title', ''), 'published': metadata.get('published', ''), 'authors': metadata.get('authors', []), 'license': metadata.get('license', ''), 'source': metadata.get('source', ''), 'source_name': metadata.get('sourceName', ''), 'originalURI': metadata.get('originalURI', ''), 'sets': [ { 'child_tags': set_object['child_tags'], 'id': set_object['id'], 'title': set_object['title'], 'tags': set_object['tags'] } for set_object in set_objects if any([ tag in set_object['child_tags'] for tag in metadata.get('tags', []) if not tag.startswith('Ekn') ]) ] } # Now that we have everything, read the template and render it variables = GLib.Variant('a{sv}', { 'css-files': GLib.Variant('as', [ 'clipboard.css', 'share-actions.css' ]), 'custom-css-files': GLib.Variant('as', []), 'javascript-files': GLib.Variant('as', [ 'jquery-min.js', 'collapse-infotable.js', 'crosslink.js' ]), 'content': GLib.Variant('s', rendered_content), 'crosslink-data': GLib.Variant('s', json.dumps(link_resolution_table)), 'content-metadata': GLib.Variant('s', json.dumps(content_metadata)), 'title': GLib.Variant( 's', metadata.get('title', 'Content from {app_id}'.format(app_id=app_id)) ) }) try: template_file = Gio.File.new_for_uri(_MOBILE_WRAPPER_TEMPLATE_URI) rendered_page = renderer.render_mustache_document_from_file(template_file, variables) except GLib.Error as page_render_error: callback(page_render_error, None) return callback(None, rendered_page) def _on_got_application_info(_, result): '''Callback function that gets called when we get the app info.''' try: app_info = EosCompanionAppService.finish_load_application_info(result) except GLib.Error as error: callback(error, None) return content_db_conn.query(application_listing=application_listing_from_app_info(app_info), query={ 'tags-match-all': ['EknSetObject'] }, cancellable=cancellable, callback=_on_queried_sets) link_tables = list(link_tables_from_shards(shards)) link_resolution_table = [ maybe_ekn_id_to_server_uri( resolve_outgoing_link_to_internal_link(link_tables, l), version, query ) for l in metadata.get('outgoingLinks', []) ] EosCompanionAppService.load_application_info(app_id, cache=cache, cancellable=cancellable, callback=_on_got_application_info)