From 2a30e5de89097791e969c398f9d6260574c9d475 Mon Sep 17 00:00:00 2001 From: albemala Date: Wed, 8 May 2024 10:04:58 +0200 Subject: [PATCH 1/3] feat: added optional short_app_name web config (#54) --- README.md | 3 ++- example/package_rename_config.yaml | 1 + lib/constants.dart | 1 + lib/exceptions.dart | 5 +++++ lib/messages.dart | 6 ++++++ lib/platforms/web.dart | 15 ++++++++++----- 6 files changed, 25 insertions(+), 6 deletions(-) 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..8f55a05 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..727c148 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,10 +62,11 @@ 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; + final actualShortAppName = shortAppName is String ? shortAppName : appName; final webManifestFile = File(_webManifestFilePath); if (!webManifestFile.existsSync()) { @@ -76,21 +80,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); } From b236f7b7f66323f0faf51d2f0650c97d327afce3 Mon Sep 17 00:00:00 2001 From: albemala Date: Fri, 10 May 2024 14:33:32 +0200 Subject: [PATCH 2/3] fix: message decoration --- lib/messages.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/messages.dart b/lib/messages.dart index 8f55a05..208d957 100644 --- a/lib/messages.dart +++ b/lib/messages.dart @@ -43,9 +43,9 @@ const _invalidAppNameMessage = ''' '''; const _invalidShortAppNameMessage = ''' -╔═════════════════════════════════════════════════════════════╗ +╔═══════════════════════════════════════════════════════╗ ║ short_app_name (Short App Name) must be a String. ║ -╚═════════════════════════════════════════════════════════════╝ +╚═══════════════════════════════════════════════════════╝ '''; const _androidMainManifestNotFoundMessage = ''' From 9bd7dcb7241ec9a84a0f8d022a281ad28d9b8364 Mon Sep 17 00:00:00 2001 From: albemala Date: Tue, 14 May 2024 09:49:26 +0200 Subject: [PATCH 3/3] fix: check short app name type --- lib/platforms/web.dart | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/platforms/web.dart b/lib/platforms/web.dart index 727c148..6c43c74 100644 --- a/lib/platforms/web.dart +++ b/lib/platforms/web.dart @@ -66,6 +66,10 @@ 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);