Skip to content

Commit

Permalink
fix: Added BackgroundMode.
Browse files Browse the repository at this point in the history
  • Loading branch information
mathrunet committed Dec 26, 2023
1 parent 8c5b4e6 commit e35bc87
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions packages/katana_cli/lib/action/app/text_to_speech.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,66 @@ class AppTextToSpeechCliAction extends CliCommand with CliActionMixin {
await file.writeAsString(
document.toXmlString(pretty: true, indent: " ", newLine: "\n"),
);
label("Edit Info.plist.");
final plist = File("ios/Runner/Info.plist");
final plistDocument = XmlDocument.parse(await plist.readAsString());
final dict = plistDocument.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 == "UIBackgroundModes";
});
if (node == null) {
dict.children.addAll(
[
XmlElement(
XmlName("key"),
[],
[XmlText("UIBackgroundModes")],
),
XmlElement(
XmlName("array"),
[],
[
XmlElement(
XmlName("string"),
[],
[XmlText("audio")],
)
],
),
],
);
} else {
final next = node.nextElementSibling;
if (next is XmlElement && next.name.toString() == "array") {
if (!next.children.any(
(p1) =>
p1 is XmlElement &&
p1.name.toString() == "string" &&
p1.innerText == "audio",
)) {
next.children.add(
XmlElement(
XmlName("string"),
[],
[XmlText("audio")],
),
);
}
} else {
throw Exception(
"The `ios/Runner/Info.plist` configuration is broken.",
);
}
}
await plist.writeAsString(
plistDocument.toXmlString(pretty: true, indent: "\t", newLine: "\n"),
);
}
}

0 comments on commit e35bc87

Please sign in to comment.