Skip to content

Commit

Permalink
fix: Correction of IOS app title.
Browse files Browse the repository at this point in the history
  • Loading branch information
mathrunet committed Jun 30, 2023
1 parent 31e5d6e commit 69efcd9
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions packages/katana_cli/lib/src/app_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ class AppInfo {
await _replaceAndroidManifest();
label("Replace ios information");
await XCode.createIOSInfoPlistStrings(data.keys.toList());
if (defaultLocale.isNotEmpty) {
await _createIOSInfoPlist(data[defaultLocale!]!);
}
await _createIOSInfoPlistStrings({
if (defaultLocale.isNotEmpty) "": data[defaultLocale!]!,
...data,
Expand Down Expand Up @@ -294,6 +297,57 @@ class AppInfo {
);
}

static Future<void> _createIOSInfoPlist(Map<String, String> data) async {
label("Edit Info.plist.");
final plist = File("ios/Runner/Info.plist");
final document = XmlDocument.parse(await plist.readAsString());
final dict = document.findAllElements("dict").firstOrNull;
if (dict == null) {
throw Exception(
"Could not find `dict` element in `ios/Runner/Info.plist`. File is corrupt.",
);
}
final node = dict.children.firstWhereOrNull((p0) {
return p0 is XmlElement &&
p0.name.toString() == "key" &&
p0.innerText == "CFBundleDisplayName";
});
if (node == null) {
dict.children.addAll(
[
XmlElement(
XmlName("key"),
[],
[XmlText("CFBundleDisplayName")],
),
XmlElement(
XmlName("string"),
[],
[
XmlText(data.get("short_title", "")),
],
),
],
);
} else {
final next = node.nextElementSibling;
if (next is XmlElement && next.name.toString() == "string") {
next.children
..clear()
..add(
XmlText(data.get("short_title", "")),
);
} else {
throw Exception(
"The `ios/Runner/Info.plist` configuration is broken.",
);
}
}
await plist.writeAsString(
document.toXmlString(pretty: true, indent: "\t", newLine: "\n"),
);
}

static Future<void> _createIOSInfoPlistStrings(
Map<String, Map<String, String>> data,
) async {
Expand Down

0 comments on commit 69efcd9

Please sign in to comment.