Skip to content

Commit a78e53e

Browse files
committed
Update fix
1 parent 765df6c commit a78e53e

File tree

10 files changed

+116
-115
lines changed

10 files changed

+116
-115
lines changed

lib/src/commands/config_command.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ class ConfigCommand extends BaseCommand {
3939
logger.info(
4040
'Setting ${key.paramKey} to: ${yellow.wrap(value.toString())}',
4141
);
42+
43+
logger.info(updatedMap.toString());
4244
updatedConfig = updatedConfig.merge(updatedMap);
4345
}
4446
}

lib/src/models/config_model.dart

Lines changed: 37 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ class FileConfig extends BaseConfig with FileConfigMappable {
159159
}
160160
}
161161

162-
@MappableClass()
162+
@MappableClass(ignoreNull: true)
163163
class AppConfig extends FileConfig with AppConfigMappable {
164164
/// Disables update notification
165165
@@ -171,16 +171,16 @@ class AppConfig extends FileConfig with AppConfigMappable {
171171

172172
/// Constructor
173173
const AppConfig({
174-
required this.disableUpdateCheck,
175-
required this.lastUpdateCheck,
176-
required super.cachePath,
177-
required super.useGitCache,
178-
required super.gitCachePath,
179-
required super.flutterUrl,
180-
required super.priviledgedAccess,
181-
required super.runPubGetOnSdkChanges,
182-
required super.updateVscodeSettings,
183-
required super.updateGitIgnore,
174+
this.disableUpdateCheck,
175+
this.lastUpdateCheck,
176+
super.cachePath,
177+
super.useGitCache,
178+
super.gitCachePath,
179+
super.flutterUrl,
180+
super.priviledgedAccess,
181+
super.runPubGetOnSdkChanges,
182+
super.updateVscodeSettings,
183+
super.updateGitIgnore,
184184
});
185185

186186
static AppConfig empty() {
@@ -208,55 +208,47 @@ class AppConfig extends FileConfig with AppConfigMappable {
208208

209209
AppConfig merge(BaseConfig? config) {
210210
if (config == null) return this;
211+
AppConfig newConfig;
211212
if (config is EnvConfig) {
212-
return copyWith(
213-
cachePath: config.cachePath,
213+
newConfig = AppConfig(
214214
disableUpdateCheck: disableUpdateCheck,
215-
flutterUrl: config.flutterUrl,
216-
gitCachePath: config.gitCachePath,
215+
cachePath: config.cachePath,
217216
useGitCache: config.useGitCache,
217+
gitCachePath: config.gitCachePath,
218+
flutterUrl: config.flutterUrl,
218219
);
219220
}
220221

221222
if (config is ProjectConfig) {
222-
return copyWith(
223+
newConfig = AppConfig(
223224
cachePath: config.cachePath,
224-
flutterUrl: config.flutterUrl,
225+
useGitCache: config.useGitCache,
225226
gitCachePath: config.gitCachePath,
227+
flutterUrl: config.flutterUrl,
226228
priviledgedAccess: config.priviledgedAccess,
227229
runPubGetOnSdkChanges: config.runPubGetOnSdkChanges,
228-
updateGitIgnore: config.updateGitIgnore,
229230
updateVscodeSettings: config.updateVscodeSettings,
230-
useGitCache: config.useGitCache,
231+
updateGitIgnore: config.updateGitIgnore,
231232
);
232233
}
233234

234235
if (config is AppConfig) {
235-
return copyWith(
236-
cachePath: config.cachePath,
237-
disableUpdateCheck: config.disableUpdateCheck,
238-
flutterUrl: config.flutterUrl,
239-
gitCachePath: config.gitCachePath,
240-
lastUpdateCheck: config.lastUpdateCheck,
241-
priviledgedAccess: config.priviledgedAccess,
242-
runPubGetOnSdkChanges: config.runPubGetOnSdkChanges,
243-
updateGitIgnore: config.updateGitIgnore,
244-
updateVscodeSettings: config.updateVscodeSettings,
245-
useGitCache: config.useGitCache,
246-
);
236+
return copyWith.$merge(config);
247237
}
248238

249-
return copyWith(
239+
newConfig = AppConfig(
250240
cachePath: config.cachePath,
251-
flutterUrl: config.flutterUrl,
252-
gitCachePath: config.gitCachePath,
253241
useGitCache: config.useGitCache,
242+
gitCachePath: config.gitCachePath,
243+
flutterUrl: config.flutterUrl,
254244
);
245+
246+
return copyWith.$merge(newConfig);
255247
}
256248
}
257249

258250
/// Project config
259-
@MappableClass()
251+
@MappableClass(ignoreNull: true)
260252
class ProjectConfig extends FileConfig with ProjectConfigMappable {
261253
final String? flutterSdkVersion;
262254
final Map<String, String>? flavors;
@@ -265,16 +257,16 @@ class ProjectConfig extends FileConfig with ProjectConfigMappable {
265257

266258
/// Constructor
267259
const ProjectConfig({
268-
required this.flutterSdkVersion,
269-
required this.flavors,
270-
required super.cachePath,
271-
required super.useGitCache,
272-
required super.gitCachePath,
273-
required super.flutterUrl,
274-
required super.priviledgedAccess,
275-
required super.runPubGetOnSdkChanges,
276-
required super.updateVscodeSettings,
277-
required super.updateGitIgnore,
260+
this.flutterSdkVersion,
261+
this.flavors,
262+
super.cachePath,
263+
super.useGitCache,
264+
super.gitCachePath,
265+
super.flutterUrl,
266+
super.priviledgedAccess,
267+
super.runPubGetOnSdkChanges,
268+
super.updateVscodeSettings,
269+
super.updateGitIgnore,
278270
});
279271

280272
static ProjectConfig empty() {

lib/src/models/config_model.mapper.dart

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -470,34 +470,34 @@ class AppConfigMapper extends ClassMapperBase<AppConfig> {
470470

471471
static bool? _$disableUpdateCheck(AppConfig v) => v.disableUpdateCheck;
472472
static const Field<AppConfig, bool> _f$disableUpdateCheck =
473-
Field('disableUpdateCheck', _$disableUpdateCheck);
473+
Field('disableUpdateCheck', _$disableUpdateCheck, opt: true);
474474
static DateTime? _$lastUpdateCheck(AppConfig v) => v.lastUpdateCheck;
475475
static const Field<AppConfig, DateTime> _f$lastUpdateCheck =
476-
Field('lastUpdateCheck', _$lastUpdateCheck);
476+
Field('lastUpdateCheck', _$lastUpdateCheck, opt: true);
477477
static String? _$cachePath(AppConfig v) => v.cachePath;
478478
static const Field<AppConfig, String> _f$cachePath =
479-
Field('cachePath', _$cachePath);
479+
Field('cachePath', _$cachePath, opt: true);
480480
static bool? _$useGitCache(AppConfig v) => v.useGitCache;
481481
static const Field<AppConfig, bool> _f$useGitCache =
482-
Field('useGitCache', _$useGitCache);
482+
Field('useGitCache', _$useGitCache, opt: true);
483483
static String? _$gitCachePath(AppConfig v) => v.gitCachePath;
484484
static const Field<AppConfig, String> _f$gitCachePath =
485-
Field('gitCachePath', _$gitCachePath);
485+
Field('gitCachePath', _$gitCachePath, opt: true);
486486
static String? _$flutterUrl(AppConfig v) => v.flutterUrl;
487487
static const Field<AppConfig, String> _f$flutterUrl =
488-
Field('flutterUrl', _$flutterUrl);
488+
Field('flutterUrl', _$flutterUrl, opt: true);
489489
static bool? _$priviledgedAccess(AppConfig v) => v.priviledgedAccess;
490490
static const Field<AppConfig, bool> _f$priviledgedAccess =
491-
Field('priviledgedAccess', _$priviledgedAccess);
491+
Field('priviledgedAccess', _$priviledgedAccess, opt: true);
492492
static bool? _$runPubGetOnSdkChanges(AppConfig v) => v.runPubGetOnSdkChanges;
493493
static const Field<AppConfig, bool> _f$runPubGetOnSdkChanges =
494-
Field('runPubGetOnSdkChanges', _$runPubGetOnSdkChanges);
494+
Field('runPubGetOnSdkChanges', _$runPubGetOnSdkChanges, opt: true);
495495
static bool? _$updateVscodeSettings(AppConfig v) => v.updateVscodeSettings;
496496
static const Field<AppConfig, bool> _f$updateVscodeSettings =
497-
Field('updateVscodeSettings', _$updateVscodeSettings);
497+
Field('updateVscodeSettings', _$updateVscodeSettings, opt: true);
498498
static bool? _$updateGitIgnore(AppConfig v) => v.updateGitIgnore;
499499
static const Field<AppConfig, bool> _f$updateGitIgnore =
500-
Field('updateGitIgnore', _$updateGitIgnore);
500+
Field('updateGitIgnore', _$updateGitIgnore, opt: true);
501501

502502
@override
503503
final MappableFields<AppConfig> fields = const {
@@ -512,6 +512,8 @@ class AppConfigMapper extends ClassMapperBase<AppConfig> {
512512
#updateVscodeSettings: _f$updateVscodeSettings,
513513
#updateGitIgnore: _f$updateGitIgnore,
514514
};
515+
@override
516+
final bool ignoreNull = true;
515517

516518
static AppConfig _instantiate(DecodingData data) {
517519
return AppConfig(
@@ -669,36 +671,36 @@ class ProjectConfigMapper extends ClassMapperBase<ProjectConfig> {
669671

670672
static String? _$flutterSdkVersion(ProjectConfig v) => v.flutterSdkVersion;
671673
static const Field<ProjectConfig, String> _f$flutterSdkVersion =
672-
Field('flutterSdkVersion', _$flutterSdkVersion);
674+
Field('flutterSdkVersion', _$flutterSdkVersion, opt: true);
673675
static Map<String, String>? _$flavors(ProjectConfig v) => v.flavors;
674676
static const Field<ProjectConfig, Map<String, String>> _f$flavors =
675-
Field('flavors', _$flavors);
677+
Field('flavors', _$flavors, opt: true);
676678
static String? _$cachePath(ProjectConfig v) => v.cachePath;
677679
static const Field<ProjectConfig, String> _f$cachePath =
678-
Field('cachePath', _$cachePath);
680+
Field('cachePath', _$cachePath, opt: true);
679681
static bool? _$useGitCache(ProjectConfig v) => v.useGitCache;
680682
static const Field<ProjectConfig, bool> _f$useGitCache =
681-
Field('useGitCache', _$useGitCache);
683+
Field('useGitCache', _$useGitCache, opt: true);
682684
static String? _$gitCachePath(ProjectConfig v) => v.gitCachePath;
683685
static const Field<ProjectConfig, String> _f$gitCachePath =
684-
Field('gitCachePath', _$gitCachePath);
686+
Field('gitCachePath', _$gitCachePath, opt: true);
685687
static String? _$flutterUrl(ProjectConfig v) => v.flutterUrl;
686688
static const Field<ProjectConfig, String> _f$flutterUrl =
687-
Field('flutterUrl', _$flutterUrl);
689+
Field('flutterUrl', _$flutterUrl, opt: true);
688690
static bool? _$priviledgedAccess(ProjectConfig v) => v.priviledgedAccess;
689691
static const Field<ProjectConfig, bool> _f$priviledgedAccess =
690-
Field('priviledgedAccess', _$priviledgedAccess);
692+
Field('priviledgedAccess', _$priviledgedAccess, opt: true);
691693
static bool? _$runPubGetOnSdkChanges(ProjectConfig v) =>
692694
v.runPubGetOnSdkChanges;
693695
static const Field<ProjectConfig, bool> _f$runPubGetOnSdkChanges =
694-
Field('runPubGetOnSdkChanges', _$runPubGetOnSdkChanges);
696+
Field('runPubGetOnSdkChanges', _$runPubGetOnSdkChanges, opt: true);
695697
static bool? _$updateVscodeSettings(ProjectConfig v) =>
696698
v.updateVscodeSettings;
697699
static const Field<ProjectConfig, bool> _f$updateVscodeSettings =
698-
Field('updateVscodeSettings', _$updateVscodeSettings);
700+
Field('updateVscodeSettings', _$updateVscodeSettings, opt: true);
699701
static bool? _$updateGitIgnore(ProjectConfig v) => v.updateGitIgnore;
700702
static const Field<ProjectConfig, bool> _f$updateGitIgnore =
701-
Field('updateGitIgnore', _$updateGitIgnore);
703+
Field('updateGitIgnore', _$updateGitIgnore, opt: true);
702704

703705
@override
704706
final MappableFields<ProjectConfig> fields = const {
@@ -713,6 +715,8 @@ class ProjectConfigMapper extends ClassMapperBase<ProjectConfig> {
713715
#updateVscodeSettings: _f$updateVscodeSettings,
714716
#updateGitIgnore: _f$updateGitIgnore,
715717
};
718+
@override
719+
final bool ignoreNull = true;
716720

717721
static ProjectConfig _instantiate(DecodingData data) {
718722
return ProjectConfig(

lib/src/runner.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,12 @@ class FvmCommandRunner extends CommandRunner<int> {
6262
/// user.
6363
Future<Function()?> _checkForUpdates() async {
6464
try {
65+
final lastUpdateCheck = ctx.lastUpdateCheck ?? DateTime.now();
6566
if (ctx.updateCheckDisabled) return null;
66-
final oneDayAgo = DateTime.now().subtract(const Duration(days: 1));
67-
if (ctx.lastUpdateCheck?.isBefore(oneDayAgo) ?? false) {
67+
final oneDay = lastUpdateCheck.add(const Duration(days: 1));
68+
69+
print(DateTime.now().isBefore(oneDay));
70+
if (DateTime.now().isBefore(oneDay)) {
6871
return null;
6972
}
7073

lib/src/services/config_repository.dart

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import '../utils/constants.dart';
77
import '../utils/extensions.dart';
88
import '../utils/helpers.dart';
99
import '../utils/pretty_json.dart';
10+
import 'logger_service.dart';
1011

1112
const String flutterGitUrl = 'FLUTTER_GIT_URL';
1213

@@ -24,13 +25,17 @@ class ConfigRepository {
2425

2526
static AppConfig loadAppConfig() {
2627
final appConfig = AppConfig.loadFromPath(_configPath);
27-
if (appConfig != null) return appConfig;
28+
if (appConfig == null) {
29+
save(AppConfig.empty());
30+
}
2831

29-
return AppConfig.empty();
32+
return AppConfig.loadFromPath(_configPath)!;
3033
}
3134

3235
static void save(AppConfig config) {
3336
final jsonContents = prettyJson(config.toMap());
37+
logger.warn('Saving config to $_configPath');
38+
print(jsonContents);
3439

3540
_configPath.file.write(jsonContents);
3641
}
@@ -56,24 +61,24 @@ class ConfigRepository {
5661

5762
static void update({
5863
String? cachePath,
59-
bool? useGitCache,
6064
String? gitCachePath,
6165
String? flutterUrl,
6266
bool? disableUpdateCheck,
6367
DateTime? lastUpdateCheck,
6468
bool? priviledgedAccess,
69+
bool? useGitCache,
6570
}) {
6671
final currentConfig = loadAppConfig();
67-
final newConfig = currentConfig.copyWith(
68-
cachePath: cachePath,
72+
final newConfig = AppConfig(
6973
disableUpdateCheck: disableUpdateCheck,
70-
flutterUrl: flutterUrl,
71-
gitCachePath: gitCachePath,
7274
lastUpdateCheck: lastUpdateCheck,
73-
priviledgedAccess: priviledgedAccess,
75+
cachePath: cachePath,
7476
useGitCache: useGitCache,
77+
gitCachePath: gitCachePath,
78+
flutterUrl: flutterUrl,
79+
priviledgedAccess: priviledgedAccess,
7580
);
76-
save(newConfig);
81+
save(currentConfig.copyWith.$merge(newConfig));
7782
}
7883

7984
static EnvConfig _loadEnvironment() {

lib/src/utils/deprecation_util.dart

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,12 @@
1-
import 'dart:convert';
21
import 'dart:io';
32

43
import 'package:mason_logger/mason_logger.dart';
5-
import 'package:path/path.dart';
64

75
import '../models/config_model.dart';
8-
import '../services/config_repository.dart';
96
import '../services/logger_service.dart';
10-
import 'constants.dart';
11-
import 'context.dart';
127

138
void deprecationWorkflow() {
149
_warnDeprecatedEnvVars();
15-
final fvmDir = ctx.fvmDir;
16-
final legacySettingsFile = File(join(fvmDir, '.settings'));
17-
18-
if (!legacySettingsFile.existsSync()) {
19-
return;
20-
}
21-
22-
final payload = legacySettingsFile.readAsStringSync();
23-
try {
24-
final settings = jsonDecode(payload);
25-
final settingsCachePath = settings['cachePath'] as String?;
26-
if (settingsCachePath != null && settingsCachePath != fvmDir) {
27-
var appConfig = ConfigRepository.loadAppConfig();
28-
appConfig = appConfig.copyWith(cachePath: fvmDir);
29-
ConfigRepository.save(appConfig);
30-
legacySettingsFile.deleteSync(recursive: true);
31-
logger.success(
32-
'We have moved the settings file ${legacySettingsFile.path}'
33-
'Your settings have been migrated to $kAppConfigFile'
34-
'Your cachePath is now $settingsCachePath. FVM will exit now. Please run the command again.',
35-
);
36-
// Exit to prevent execution with wrong cache path
37-
exit(ExitCode.success.code);
38-
}
39-
} catch (_) {
40-
logger.warn('Could not parse legacy settings file');
41-
legacySettingsFile.deleteSync(recursive: true);
42-
}
4310
}
4411

4512
// TODO: Removed on future version of the app

lib/src/version.dart

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pubspec.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,15 @@ packages:
106106
source: hosted
107107
version: "7.3.0"
108108
build_verify:
109-
dependency: "direct main"
109+
dependency: "direct dev"
110110
description:
111111
name: build_verify
112112
sha256: abbb9b9eda076854ac1678d284c053a5ec608e64da741d0801f56d4bbea27e23
113113
url: "https://pub.dev"
114114
source: hosted
115115
version: "3.1.0"
116116
build_version:
117-
dependency: "direct main"
117+
dependency: "direct dev"
118118
description:
119119
name: build_version
120120
sha256: "4e8eafbf722eac3bd60c8d38f108c04bd69b80100f8792b32be3407725c7fa6a"

0 commit comments

Comments
 (0)