diff --git a/README.md b/README.md index 2f40b8b..7911059 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,8 @@ package_rename_config: copyright_notice: # (String) The product copyright of the macos app web: - app_name: # (String) The title and display name of the web app and PWA + app_name: # (String) The title of the web app and PWA + short_app_name: # (String) The short display name of the PWA (Optional, defaults to app_name if not set) description: # (String) The description of the web app and PWA windows: diff --git a/example/package_rename_config.yaml b/example/package_rename_config.yaml index d5d7308..c94b61d 100644 --- a/example/package_rename_config.yaml +++ b/example/package_rename_config.yaml @@ -12,6 +12,7 @@ package_rename_config: web: app_name: Package Rename Demo + short_app_name: Package Rename description: CLI tool to rename package configurations in Flutter project. linux: diff --git a/lib/constants.dart b/lib/constants.dart index 34604fa..c00732a 100644 --- a/lib/constants.dart +++ b/lib/constants.dart @@ -36,6 +36,7 @@ const _projectFileName = 'project.pbxproj'; // ! Keys const _configKey = 'package_rename_config'; const _appNameKey = 'app_name'; +const _shortAppNameKey = 'short_app_name'; const _packageNameKey = 'package_name'; const _bundleNameKey = 'bundle_name'; const _descriptionKey = 'description'; diff --git a/lib/exceptions.dart b/lib/exceptions.dart index 3e919ee..d4524ba 100644 --- a/lib/exceptions.dart +++ b/lib/exceptions.dart @@ -180,4 +180,9 @@ class _PackageRenameErrors { _macOSProjectFileNotFoundMessage, 33, ); + + static const invalidShortAppName = _PackageRenameException( + _invalidShortAppNameMessage, + 34, + ); } diff --git a/lib/messages.dart b/lib/messages.dart index 7109334..208d957 100644 --- a/lib/messages.dart +++ b/lib/messages.dart @@ -42,6 +42,12 @@ const _invalidAppNameMessage = ''' ╚═══════════════════════════════════════════╝ '''; +const _invalidShortAppNameMessage = ''' +╔═══════════════════════════════════════════════════════╗ +║ short_app_name (Short App Name) must be a String. ║ +╚═══════════════════════════════════════════════════════╝ +'''; + const _androidMainManifestNotFoundMessage = ''' ╔═══════════════════════════════════════════════════════════════╗ ║ AndroidManifest.xml not found in `android/app/src/main/`. ║ diff --git a/lib/platforms/web.dart b/lib/platforms/web.dart index 3d26dad..6c43c74 100644 --- a/lib/platforms/web.dart +++ b/lib/platforms/web.dart @@ -8,7 +8,10 @@ void _setWebConfigurations(dynamic webConfig) { final webConfigMap = Map.from(webConfig); _setWebTitle(webConfigMap[_appNameKey]); - _setPWAAppName(webConfigMap[_appNameKey]); + _setPWAAppName( + webConfigMap[_appNameKey], + webConfigMap[_shortAppNameKey], + ); _setWebDescription(webConfigMap[_descriptionKey]); _setPWADescription(webConfigMap[_descriptionKey]); } on _PackageRenameException catch (e) { @@ -59,11 +62,16 @@ void _setWebTitle(dynamic appName) { } } -void _setPWAAppName(dynamic appName) { +void _setPWAAppName(dynamic appName, dynamic shortAppName) { try { if (appName == null) return; if (appName is! String) throw _PackageRenameErrors.invalidAppName; + if (shortAppName != null && shortAppName is! String) { + throw _PackageRenameErrors.invalidShortAppName; + } + final actualShortAppName = shortAppName is String ? shortAppName : appName; + final webManifestFile = File(_webManifestFilePath); if (!webManifestFile.existsSync()) { _logger.w('Web manifest.json not found!!!'); @@ -76,21 +84,22 @@ void _setPWAAppName(dynamic appName) { ) as Map; webManifestJson['name'] = appName; - webManifestJson['short_name'] = appName; + webManifestJson['short_name'] = actualShortAppName; const encoder = JsonEncoder.withIndent(' '); webManifestFile.writeAsStringSync('${encoder.convert(webManifestJson)}\n'); _logger.i('PWA name set to: `$appName` (manifest.json)'); + _logger.i('PWA short name set to: `$actualShortAppName` (manifest.json)'); } on _PackageRenameException catch (e) { _logger ..e('${e.message}ERR Code: ${e.code}') - ..e('PWA Name change failed!!!'); + ..e('PWA Name/Short Name change failed!!!'); } catch (e) { _logger ..w(e.toString()) ..e('ERR Code: 255') - ..e('PWA Name change failed!!!'); + ..e('PWA Name/Short Name change failed!!!'); } finally { if (appName != null) _logger.f(_minorTaskDoneLine); }