Skip to content

Commit 13f945a

Browse files
committed
refactor: move AppConfigFactory to resources and enhance color handling
1 parent 37ca684 commit 13f945a

7 files changed

Lines changed: 32 additions & 17 deletions

File tree

lib/src/commands/resources/processors/local_config_processor.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import 'package:data/dto/dto.dart';
88
import 'package:webtrit_phone_tools/src/commands/constants.dart';
99
import 'package:webtrit_phone_tools/src/utils/utils.dart';
1010

11+
import '../utils/utils.dart';
12+
1113
class LocalConfigProcessor {
1214
const LocalConfigProcessor({required this.logger});
1315

lib/src/commands/resources/processors/translation_processor.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ class TranslationProcessor {
2121
required String Function(String) resolvePath,
2222
}) async {
2323
final configFile = File(resolvePath('localizely.yml'));
24-
if (!configFile.existsSync()) return;
24+
25+
if (!configFile.existsSync()) {
26+
logger.warn('localizely.yml file not found in the working directory.');
27+
return;
28+
}
2529

2630
final config = loadYaml(await configFile.readAsString());
2731
final localeCodes = (config['download']['files'] as List).map((e) => e['locale_code']).toSet();

lib/src/commands/resources/runners/external_generator_runner.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import 'package:mason_logger/mason_logger.dart';
66

77
import 'package:data/dto/dto.dart';
88

9-
import '../../../utils/app_config_factory.dart';
9+
import '../utils/app_config_factory.dart';
1010

1111
class ExternalGeneratorRunner {
1212
const ExternalGeneratorRunner({required this.logger});
@@ -20,16 +20,19 @@ class ExternalGeneratorRunner {
2020
required LaunchAssetsEnvelopeDto launchIcons,
2121
}) async {
2222
final launchBgColor = launchIcons.entity.source?.backgroundColorHex;
23+
final splashBgColor = splashInfo.source?.backgroundColorHex;
2324

2425
if (launchBgColor != null) {
2526
logger.info('- Running: generate-launcher-icons-config');
26-
final env = AppConfigFactory.createLauncherIconsEnv(launchBgColor);
27+
final env = AppConfigFactory.createLauncherIconsEnv(
28+
launchBackgroundColorHex: launchBgColor,
29+
splashBackgroundColorHex: splashBgColor ?? launchBgColor,
30+
);
2731
await _runMakeCommand(workingDirectoryPath, 'generate-launcher-icons-config', env);
2832
} else {
2933
logger.warn('Skipping launcher generation: backgroundColorHex is null.');
3034
}
3135

32-
final splashBgColor = splashInfo.source?.backgroundColorHex;
3336
if (splashBgColor != null) {
3437
logger.info('- Running: generate-native-splash-config');
3538
final env = AppConfigFactory.createNativeSplashEnv(splashBgColor);
@@ -65,4 +68,4 @@ class ExternalGeneratorRunner {
6568
}
6669
logger.success('✓ Generator $target completed');
6770
}
68-
}
71+
}

lib/src/utils/app_config_factory.dart renamed to lib/src/commands/resources/utils/app_config_factory.dart

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import 'package:data/dto/dto.dart';
2+
23
import 'package:webtrit_phone_tools/src/commands/constants.dart';
34
import 'package:webtrit_phone_tools/src/extension/extension.dart';
45

56
class AppConfigFactory {
67
static Map<String, dynamic> createBuildCacheConfig(ApplicationDTO application, String keystorePath) {
7-
if (application.androidVersion?.buildName == null || application.iosVersion?.buildName == null) {
8+
if (application.androidVersion?.buildName == null ||
9+
application.androidVersion?.buildNumber == null ||
10+
application.iosVersion?.buildName == null ||
11+
application.iosVersion?.buildNumber == null) {
812
throw Exception('Android or iOS version build info is missing.');
913
}
1014

@@ -25,24 +29,25 @@ class AppConfigFactory {
2529
return env;
2630
}
2731

28-
static Map<String, String> createLauncherIconsEnv(String backgroundColorHex) {
29-
final hexCode = backgroundColorHex.toHex6WithHash();
32+
static Map<String, String> createLauncherIconsEnv({
33+
required String launchBackgroundColorHex,
34+
required String splashBackgroundColorHex,
35+
}) {
3036
return {
3137
'LAUNCHER_ICON_IMAGE_ANDROID': assetLauncherAndroidIconPath,
32-
'ICON_BACKGROUND_COLOR': hexCode,
38+
'ICON_BACKGROUND_COLOR': splashBackgroundColorHex.toHex6WithHash(),
3339
'LAUNCHER_ICON_FOREGROUND': assetLauncherIconAdaptiveForegroundPath,
3440
'LAUNCHER_ICON_IMAGE_IOS': assetLauncherIosIconPath,
3541
'LAUNCHER_ICON_IMAGE_WEB': assetLauncherWebIconPath,
36-
'THEME_COLOR': hexCode,
42+
'THEME_COLOR': launchBackgroundColorHex.toHex6WithHash(),
3743
};
3844
}
3945

4046
static Map<String, String> createNativeSplashEnv(String backgroundColorHex) {
41-
final hexCode = backgroundColorHex.toHex6WithHash();
4247
return {
43-
'SPLASH_COLOR': hexCode,
48+
'SPLASH_COLOR': backgroundColorHex.toHex6WithHash(),
4449
'SPLASH_IMAGE': assetSplashIconPath,
45-
'ANDROID_12_SPLASH_COLOR': hexCode,
50+
'ANDROID_12_SPLASH_COLOR': backgroundColorHex.toHex6WithHash(),
4651
};
4752
}
4853

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export 'app_config_factory.dart';

lib/src/extension/string_extension.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ extension StringExtensions on String {
1414
/// Handles alpha channel stripping if present (8 chars).
1515
String toHex6WithHash() {
1616
final hex = replaceAll('#', '').toUpperCase();
17+
1718
if (hex.length == 8) {
1819
return '#${hex.substring(2)}';
1920
}
21+
2022
if (hex.length == 6) {
2123
return '#$hex';
2224
}
23-
// Fallback: return as is with hash if it fits reasonable criteria,
24-
// or just ensure hash prefix.
25-
return '#$hex';
25+
26+
throw FormatException('Invalid hex color string: "$this"');
2627
}
2728
}

lib/src/utils/utils.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
export 'app_config_factory.dart';
21
export 'asset_migrator.dart';
32
export 'command_help_formatter.dart';
43
export 'http_client.dart';

0 commit comments

Comments
 (0)