From a6464a5a50ce989c29f30aeefd8e5b720c2b89ff Mon Sep 17 00:00:00 2001 From: Balazs Perlaki-Horvath Date: Fri, 14 Feb 2025 12:35:45 +0100 Subject: [PATCH] Dynamically replace info plist values for custom apps, cutting out audio background if needed, removing live activity for all --- README.md | 1 + dwds/info.json | 1 + src/info_parser.py | 12 ++++++++++++ testapp/info.json | 1 + wikimed/info.json | 1 + 5 files changed, 16 insertions(+) diff --git a/README.md b/README.md index 1932042..80269d1 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,7 @@ existing one if you need to create a new custom app. - **"neverLoad"**: it won't ask the user, and won't open any external links. This is handy if the external links handling is already contained in the zimfile itself, and we don't want to trigger any system level behaviour. - `settings_show_external_link_option` - **true/false** in the app settings, the user is allowed to change the external link handling behaviour. If we want to restrict that and remove this option from the settings UI (so that the user cannot change the value), we can do that by setting this value to false. - `settings_show_search_snippet` - in most cases this should be **false** for a custom app. This removes the snippet from the search, which is used to filter the search results by ZIM files in the Kiwix app. Since custom apps come with a single ZIM file, this filter is not needed. +- `uses_audio` - (true | false) this will enable or disable the [UIBackgroundModes](https://developer.apple.com/documentation/bundleresources/information-property-list/uibackgroundmodes) audio property in the final .plist file. Please note if the custom app is not using any media playback, it's recommended to turn this off, otherwise the release build might be rejected by Apple with: "The app declares support for audio in the UIBackgroundModes key in your Info.plist but we are unable to locate any features that require persistent audio." - `zim_url` - this **is required** for a custom app, without this, it is not a custom app at all. This is used in a download step to create the custom app, and then bundled into the app itself. The **filename must end with the date format: YYYY-MM-DD.zim or with: YYYY-MM.zim**, as the version of the app is dictated by this. See more on that in the "Versioning and creating the app" section below. If your download requires standard http authentication, see `zim_auth`. diff --git a/dwds/info.json b/dwds/info.json index 6afd3b8..026d71d 100644 --- a/dwds/info.json +++ b/dwds/info.json @@ -9,6 +9,7 @@ "settings_default_external_link_to": "alwaysLoad", "settings_show_external_link_option": false, "settings_show_search_snippet": false, + "uses_audio": false, "zim_auth": "HTTP_BASIC_ACCESS_AUTHENTICATION", "zim_url": "https://www.dwds.de/kiwix/f/dwds_de_dictionary_nopic_2025-02-11.zim" } diff --git a/src/info_parser.py b/src/info_parser.py index 65fed31..7f603e4 100644 --- a/src/info_parser.py +++ b/src/info_parser.py @@ -8,12 +8,16 @@ import os import shutil import plistlib +PLIST_KEY_BACKGROUND_MODES = "UIBackgroundModes" +PLIST_KEY_LIVE_ACTIVITY = "NSSupportsLiveActivities" +PLIST_KEY_LIVE_ACTIVITY_FREQUENT = "NSSupportsLiveActivitiesFrequentUpdates" JSON_KEY_ZIM_URL = "zim_url" JSON_KEY_AUTH = "zim_auth" JSON_BUNDLE_ID = "bundle_id" JSON_KEY_APP_NAME = "app_name" JSON_KEY_ENFORCED_LANGUAGE = "enforced_lang" JSON_KEY_DEVELOPMENT_TEAM = "development_team" +JSON_KEY_USES_AUDIO = "uses_audio" CUSTOM_ZIM_FILE_KEY = "CUSTOM_ZIM_FILE" JSON_TO_PLIST_MAPPING = { "app_store_id": "APP_STORE_ID", @@ -43,10 +47,18 @@ class InfoParser: self.version = Version.from_file_name(file_name=self.zim_file_name, build_number=build_number) self.development_team_id = self._development_team() + self.uses_audio = self.data[JSON_KEY_USES_AUDIO] == True def create_plist(self, based_on_plist_file): with based_on_plist_file.open(mode="rb") as file: plist = plistlib.load(file) + # handle Background mode audio: + if self.uses_audio == False: + plist[PLIST_KEY_BACKGROUND_MODES].remove("audio") + # remove live activity for custom apps: + plist.pop(PLIST_KEY_LIVE_ACTIVITY, None) + plist.pop(PLIST_KEY_LIVE_ACTIVITY_FREQUENT, None) + # replace plist values according to custom json: for keyValues in self._plist_key_values(): for key in keyValues: plist[key] = keyValues[key] diff --git a/testapp/info.json b/testapp/info.json index ca0f875..60728d2 100644 --- a/testapp/info.json +++ b/testapp/info.json @@ -8,5 +8,6 @@ "settings_default_external_link_to": "alwaysLoad", "settings_show_external_link_option": true, "settings_show_search_snippet": false, + "uses_audio": true, "zim_url": "https://dev.kiwix.org/apple/custom/test/wikipedia_en_ray_charles_maxi_2023-12.zim" } diff --git a/wikimed/info.json b/wikimed/info.json index 070396a..26de8d7 100644 --- a/wikimed/info.json +++ b/wikimed/info.json @@ -9,5 +9,6 @@ "settings_default_external_link_to": "alwaysLoad", "settings_show_external_link_option": true, "settings_show_search_snippet": false, + "uses_audio": true, "zim_url": "https://mirror.download.kiwix.org/zim/.hidden/custom_apps/mdwiki_en_all-app_maxi_2024-03.zim" }