Skip to content

Commit dcd98ad

Browse files
v7.1.1: Major bug fixes and improvements (#98)
* Major bug fixes Added start of `debugMode` Other minor improvements * Built Example Applications * Minor documentation improvements * Built Example Applications * Updated version to v7.1.1 Updated CHANGELOG * Built Example Applications --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Former-commit-id: bc8b7e6bec3e473c601fe633d65223a4e8678ddd [formerly fa43b1e] Former-commit-id: e289815a8818cbe45de1a3fddb03d5a29d219ef5
1 parent ce964d1 commit dcd98ad

File tree

12 files changed

+76
-36
lines changed

12 files changed

+76
-36
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ Many thanks to my sponsors, no matter how much or how little they donated. Spons
1313

1414
# Changelog
1515

16-
## [7.1.0] - 2023/02/12
16+
## [7.1.1] - 2023/02/16
17+
18+
* Major bug fixes
19+
* Added debug mode
20+
21+
## [7.1.0] - 2023/02/14
1722

1823
* Added URL query params obscurer feature
1924
* Added `headers` and `httpClient` parameters to `getTileProvider`

example/lib/main.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ void main() async {
2626
bool damagedDatabaseDeleted = false;
2727
await FlutterMapTileCaching.initialise(
2828
errorHandler: (error) => damagedDatabaseDeleted = error.wasFatal,
29+
debugMode: true,
2930
);
3031

3132
await FMTC.instance.rootDirectory.migrator.fromV6(urlTemplates: []);

example/lib/screens/main/pages/settingsAndAbout/settings_and_about.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class _SettingsAndAboutPageState extends State<SettingsAndAboutPage> {
8080
context: context,
8181
applicationName: 'FMTC Demo',
8282
applicationVersion:
83-
'for v7.0.0\n(on ${Platform().operatingSystemFormatted})',
83+
'for v7.1.0\n(on ${Platform().operatingSystemFormatted})',
8484
applicationIcon: Image.asset(
8585
'assets/icons/ProjectIcon.png',
8686
height: 48,

lib/src/bulk_download/downloader.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ Future<TileProgress> _getAndSaveTile({
119119
);
120120
}
121121

122-
BulkTileWriter.instance.sendPort.send(List.unmodifiable([url, bytes]));
122+
BulkTileWriter.instance.sendPort.send(
123+
List.unmodifiable([provider.settings.obscureQueryParams(url), bytes]),
124+
);
123125
bulkTileWriterResponse = await BulkTileWriter.instance.events.next;
124126
} catch (e) {
125127
if (errorHandler != null) errorHandler(e);

lib/src/db/registry.dart

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ class FMTCRegistry {
3939
required Directory directory,
4040
required int databaseMaxSize,
4141
required CompactCondition? databaseCompactCondition,
42-
void Function(FMTCInitialisationException error)? errorHandler,
43-
IOSink? initialisationSafetyWriteSink,
44-
List<String>? safeModeSuccessfulIDs,
42+
required void Function(FMTCInitialisationException error)? errorHandler,
43+
required IOSink? initialisationSafetyWriteSink,
44+
required List<String>? safeModeSuccessfulIDs,
45+
required bool debugMode,
4546
}) async {
4647
final recoveryFile = directory >>> '.recovery.isar';
4748

@@ -60,12 +61,19 @@ class FMTCRegistry {
6061
return instance = FMTCRegistry._(
6162
directory: directory,
6263
recoveryDatabase: await Isar.open(
63-
[DbRecoverableRegionSchema],
64+
[
65+
DbRecoverableRegionSchema,
66+
if (debugMode) ...[
67+
DbStoreDescriptorSchema,
68+
DbTileSchema,
69+
DbMetadataSchema,
70+
],
71+
],
6472
name: '.recovery',
6573
directory: directory.absolute.path,
6674
maxSizeMiB: databaseMaxSize,
6775
compactOnLaunch: databaseCompactCondition,
68-
inspector: false,
76+
inspector: debugMode,
6977
),
7078
storeDatabases: Map.fromEntries(
7179
await directory
@@ -102,7 +110,7 @@ class FMTCRegistry {
102110
directory: directory.absolute.path,
103111
maxSizeMiB: databaseMaxSize,
104112
compactOnLaunch: databaseCompactCondition,
105-
inspector: false,
113+
inspector: debugMode,
106114
),
107115
);
108116
initialisationSafetyWriteSink?.writeln(id);

lib/src/fmtc.dart

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,19 @@ class FlutterMapTileCaching {
2626
/// See [FMTCSettings]' properties for more information
2727
final FMTCSettings settings;
2828

29+
final bool _debugMode;
30+
31+
/// Whether FMTC should perform extra reporting and console logging
32+
///
33+
/// Depends on [_debugMode] (set via [initialise]) and [kDebugMode].
34+
bool get debugMode => _debugMode && kDebugMode;
35+
2936
/// Internal constructor, to be used by [initialise]
30-
FlutterMapTileCaching._({
37+
const FlutterMapTileCaching._({
3138
required this.rootDirectory,
3239
required this.settings,
33-
});
40+
required bool debugMode,
41+
}) : _debugMode = debugMode;
3442

3543
/// Initialise and prepare FMTC, by creating all neccessary directories/files
3644
/// and configuring the [FlutterMapTileCaching] singleton
@@ -57,6 +65,14 @@ class FlutterMapTileCaching {
5765
/// initialisation safety system, and is not recommended, as this may leave the
5866
/// application unable to launch if any database becomes corrupted.
5967
///
68+
/// Setting [debugMode] `true` can be useful to diagnose issues, either within
69+
/// your application or FMTC itself. It enables the Isar inspector and causes
70+
/// extra console logging in important areas. Prefer to leave disabled to
71+
/// prevent console pollution and to maximise performance. Whether FMTC chooses
72+
/// to listen to this value is also dependent on [kDebugMode] - see
73+
/// [FlutterMapTileCaching.debugMode] for more information.
74+
/// _Extra logging is currently limited._
75+
///
6076
/// This returns a configured [FlutterMapTileCaching], the same object as
6177
/// [FlutterMapTileCaching.instance]. Note that [FMTC] is an alias for this
6278
/// object.
@@ -65,6 +81,7 @@ class FlutterMapTileCaching {
6581
FMTCSettings? settings,
6682
void Function(FMTCInitialisationException error)? errorHandler,
6783
bool disableInitialisationSafety = false,
84+
bool debugMode = false,
6885
}) async {
6986
final directory = await ((rootDirectory == null
7087
? await getApplicationDocumentsDirectory()
@@ -90,6 +107,7 @@ class FlutterMapTileCaching {
90107
initialisationSafetyWriteSink: writeSink,
91108
safeModeSuccessfulIDs:
92109
needsRescue ? await initialisationSafetyFile.readAsLines() : null,
110+
debugMode: debugMode && kDebugMode,
93111
);
94112

95113
await writeSink.close();
@@ -100,12 +118,16 @@ class FlutterMapTileCaching {
100118
databaseMaxSize: fmtcSettings.databaseMaxSize,
101119
databaseCompactCondition: fmtcSettings.databaseCompactCondition,
102120
errorHandler: errorHandler,
121+
initialisationSafetyWriteSink: null,
122+
safeModeSuccessfulIDs: null,
123+
debugMode: debugMode && kDebugMode,
103124
);
104125
}
105126

106127
return _instance = FMTC._(
107128
rootDirectory: RootDirectory._(directory),
108129
settings: fmtcSettings,
130+
debugMode: debugMode,
109131
);
110132
}
111133

lib/src/providers/image_provider.dart

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -117,25 +117,11 @@ class FMTCImageProvider extends ImageProvider<FMTCImageProvider> {
117117
);
118118
}
119119

120-
final String networkUrl = provider.getTileUrl(coords, options);
121-
final String matcherUrl;
122-
123-
if (networkUrl.contains('?') &&
124-
provider.settings.obscuredQueryParams.isNotEmpty) {
125-
String secondPartUrl = networkUrl.split('?')[1];
126-
for (final r in provider.settings.obscuredQueryParams) {
127-
secondPartUrl = secondPartUrl.replaceAll(r, '');
128-
}
129-
130-
matcherUrl = '${networkUrl.split('?')[0]}?$secondPartUrl';
131-
} else {
132-
matcherUrl = networkUrl;
133-
}
120+
final networkUrl = provider.getTileUrl(coords, options);
121+
final matcherUrl = provider.settings.obscureQueryParams(networkUrl);
134122

135-
final DbTile? existingTile =
136-
await _db.tiles.get(DatabaseTools.hash(matcherUrl));
123+
final existingTile = await _db.tiles.get(DatabaseTools.hash(matcherUrl));
137124

138-
// Logic to check whether the tile needs creating or updating
139125
final bool needsCreating = existingTile == null;
140126
final bool needsUpdating = needsCreating
141127
? false
@@ -145,8 +131,7 @@ class FMTCImageProvider extends ImageProvider<FMTCImageProvider> {
145131
existingTile.lastModified.millisecondsSinceEpoch >
146132
settings.cachedValidDuration.inMilliseconds);
147133

148-
/* DEBUG ONLY
149-
print('---------');
134+
/*print('---------');
150135
print(networkUrl);
151136
print(matcherUrl);
152137
print(' Existing ID: ' + (existingTile?.id ?? 'None').toString());

lib/src/settings/tile_provider_settings.dart

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright © Luka S (JaffaKetchup) under GPL-v3
22
// A full license can be found at .\LICENSE
33

4+
import 'package:meta/meta.dart';
5+
46
import '../../flutter_map_tile_caching.dart';
57
import '../providers/image_provider.dart';
68

@@ -51,8 +53,10 @@ class FMTCTileProviderSettings {
5153
/// Defaults to 0 disabled.
5254
final int maxStoreLength;
5355

54-
/// A list of keys in the query part of the source URL (after the '?'), who's
55-
/// values will not be stored
56+
/// A list of regular expressions indicating key-value pairs to be remove from
57+
/// a URL's query parameter list
58+
///
59+
/// Used by [obscureQueryParams] to apply to a URL.
5660
///
5761
/// See the online documentation for more information.
5862
final Iterable<RegExp> obscuredQueryParams;
@@ -71,6 +75,19 @@ class FMTCTileProviderSettings {
7175
this.errorHandler,
7276
}) : obscuredQueryParams = obscuredQueryParams.map((e) => RegExp('$e=[^&]*'));
7377

78+
/// Apply the [obscuredQueryParams] to the input [url]
79+
@internal
80+
String obscureQueryParams(String url) {
81+
if (!url.contains('?') || obscuredQueryParams.isEmpty) return url;
82+
83+
String secondPartUrl = url.split('?')[1];
84+
for (final r in obscuredQueryParams) {
85+
secondPartUrl = secondPartUrl.replaceAll(r, '');
86+
}
87+
88+
return '${url.split('?')[0]}?$secondPartUrl';
89+
}
90+
7491
@override
7592
bool operator ==(Object other) =>
7693
identical(this, other) ||
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
f036026a51a5aac16b9bbea4e08b55c417e28a1f
1+
8dabf01a39e9ac151ce0b2c274c9031c4666e13f
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
cd8dd9ee2df97ddc57a3060546972d933df91a34
1+
61a6c17168569271fe64208142fa93eb65e01d5a

0 commit comments

Comments
 (0)