updateLauncherName method
void
updateLauncherName(
)
override
Implementation
@override
void updateLauncherName() {
if (!common.fileExists(context.webManifestPath) &&
!common.fileExists(context.webIndexPath)) {
common.logSkipped(
"Web launcher name",
"${context.webManifestPath}, ${context.webIndexPath}",
"both files do not exist",
);
return;
}
final desiredName = common.fetchLauncherName(context);
final escapedDesiredName = common.escapeForDoubleQuotedString(desiredName);
if (common.fileExists(context.webManifestPath)) {
final manifestData = common.readFile(context.webManifestPath);
var updatedManifestData = common.replaceFirstMatchOrThrow(
manifestData,
RegExp(r'("name"\s*:\s*")([^"]*)(")'),
(match) => '${match.group(1)}$escapedDesiredName${match.group(3)}',
"web manifest name",
context.webManifestPath,
);
updatedManifestData = common.replaceFirstMatchOrThrow(
updatedManifestData,
RegExp(r'("short_name"\s*:\s*")([^"]*)(")'),
(match) => '${match.group(1)}$escapedDesiredName${match.group(3)}',
"web manifest short_name",
context.webManifestPath,
);
common.overwriteFile(context.webManifestPath, updatedManifestData);
} else {
common.logSkipped(
"Web manifest name",
context.webManifestPath,
"file does not exist",
);
}
if (common.fileExists(context.webIndexPath)) {
final webIndexData = common.readFile(context.webIndexPath);
var updatedWebIndexData = common.replaceFirstMatchOrThrow(
webIndexData,
RegExp(
r'(<meta\s+name="apple-mobile-web-app-title"\s+content=")([^"]*)(")'),
(match) => '${match.group(1)}$escapedDesiredName${match.group(3)}',
"apple-mobile-web-app-title",
context.webIndexPath,
);
updatedWebIndexData = common.replaceFirstMatchOrThrow(
updatedWebIndexData,
RegExp(r'(<title>)([^<]*)(</title>)'),
(match) => '${match.group(1)}$desiredName${match.group(3)}',
"web page title",
context.webIndexPath,
);
common.overwriteFile(context.webIndexPath, updatedWebIndexData);
} else {
common.logSkipped(
"Web page title",
context.webIndexPath,
"file does not exist",
);
}
}