Skip to content

Commit e67d992

Browse files
committed
Add (for now) simple settings page to reset the exercise cache
This should be expanded later to allow to re-fetch all available exercises, etc.
1 parent 95eed70 commit e67d992

32 files changed

+261
-122
lines changed

flatpak/scripts/flatpak_shared.dart

Lines changed: 22 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ class Icon {
4444
_fileExtension = path.split('.').last;
4545
}
4646

47-
String getFilename(String appId) => (type == _symbolicType)
48-
? '$appId-symbolic.$_fileExtension'
49-
: '$appId.$_fileExtension';
47+
String getFilename(String appId) =>
48+
(type == _symbolicType) ? '$appId-symbolic.$_fileExtension' : '$appId.$_fileExtension';
5049
}
5150

5251
class GithubReleases {
@@ -75,8 +74,7 @@ class GithubReleases {
7574
final releaseJsonContent = (await http.get(Uri(
7675
scheme: 'https',
7776
host: 'api.github.com',
78-
path:
79-
'/repos/$githubReleaseOrganization/$githubReleaseProject/releases')))
77+
path: '/repos/$githubReleaseOrganization/$githubReleaseProject/releases')))
8078
.body;
8179
final decodedJson = jsonDecode(releaseJsonContent) as List;
8280

@@ -87,23 +85,19 @@ class GithubReleases {
8785
await Future.forEach<dynamic>(decodedJson, (dynamic releaseDynamic) async {
8886
final releaseMap = releaseDynamic as Map;
8987

90-
final releaseDateAndTime =
91-
DateTime.parse(releaseMap['published_at'] as String);
92-
final releaseDateString =
93-
releaseDateAndTime.toIso8601String().split('T').first;
88+
final releaseDateAndTime = DateTime.parse(releaseMap['published_at'] as String);
89+
final releaseDateString = releaseDateAndTime.toIso8601String().split('T').first;
9490

9591
if (latestReleaseAssetDate == null ||
9692
(latestReleaseAssetDate?.compareTo(releaseDateAndTime) == -1)) {
97-
final assets =
98-
await _parseGithubReleaseAssets(releaseMap['assets'] as List);
93+
final assets = await _parseGithubReleaseAssets(releaseMap['assets'] as List);
9994
if (assets != null) {
10095
_latestReleaseAssets = assets;
10196
latestReleaseAssetDate = releaseDateAndTime;
10297
}
10398
}
10499

105-
releases.add(Release(
106-
version: releaseMap['name'] as String, date: releaseDateString));
100+
releases.add(Release(version: releaseMap['name'] as String, date: releaseDateString));
107101
});
108102

109103
if (releases.isNotEmpty || canBeEmpty) {
@@ -124,8 +118,7 @@ class GithubReleases {
124118
final downloadUrl = amMap['browser_download_url'] as String;
125119
final filename = amMap['name'] as String;
126120
final fileExtension = filename.substring(filename.indexOf('.') + 1);
127-
final filenameWithoutExtension =
128-
filename.substring(0, filename.indexOf('.'));
121+
final filenameWithoutExtension = filename.substring(0, filename.indexOf('.'));
129122

130123
final arch = filenameWithoutExtension.endsWith('aarch64')
131124
? CPUArchitecture.aarch64
@@ -221,8 +214,7 @@ class FlatpakMeta {
221214
: _localReleases = localReleases,
222215
_localReleaseAssets = localReleaseAssets {
223216
if (githubReleaseOrganization != null && githubReleaseProject != null) {
224-
_githubReleases =
225-
GithubReleases(githubReleaseOrganization!, githubReleaseProject!);
217+
_githubReleases = GithubReleases(githubReleaseOrganization!, githubReleaseProject!);
226218
}
227219
}
228220

@@ -231,20 +223,17 @@ class FlatpakMeta {
231223
final releases = List<Release>.empty(growable: true);
232224
if (addedTodaysVersion != null) {
233225
releases.add(Release(
234-
version: addedTodaysVersion,
235-
date: DateTime.now().toIso8601String().split("T").first));
226+
version: addedTodaysVersion, date: DateTime.now().toIso8601String().split("T").first));
236227
}
237228
if (fetchReleasesFromGithub) {
238229
if (_githubReleases == null) {
239230
throw Exception(
240231
'Metadata must include Github repository info if fetching releases from Github.');
241232
}
242-
releases.addAll(
243-
await _githubReleases!.getReleases(addedTodaysVersion != null));
233+
releases.addAll(await _githubReleases!.getReleases(addedTodaysVersion != null));
244234
} else {
245235
if (_localReleases == null && addedTodaysVersion == null) {
246-
throw Exception(
247-
'Metadata must include releases if not fetching releases from Github.');
236+
throw Exception('Metadata must include releases if not fetching releases from Github.');
248237
}
249238
if (_localReleases?.isNotEmpty ?? false) {
250239
releases.addAll(_localReleases!);
@@ -253,8 +242,7 @@ class FlatpakMeta {
253242
return releases;
254243
}
255244

256-
Future<List<ReleaseAsset>?> getLatestReleaseAssets(
257-
bool fetchReleasesFromGithub) async {
245+
Future<List<ReleaseAsset>?> getLatestReleaseAssets(bool fetchReleasesFromGithub) async {
258246
if (fetchReleasesFromGithub) {
259247
if (_githubReleases == null) {
260248
throw Exception(
@@ -263,8 +251,7 @@ class FlatpakMeta {
263251
return await _githubReleases!.getLatestReleaseAssets();
264252
} else {
265253
if (_localReleases == null) {
266-
throw Exception(
267-
'Metadata must include releases if not fetching releases from Github.');
254+
throw Exception('Metadata must include releases if not fetching releases from Github.');
268255
}
269256
return _localReleaseAssets;
270257
}
@@ -276,24 +263,20 @@ class FlatpakMeta {
276263
return FlatpakMeta(
277264
appId: json['appId'] as String,
278265
lowercaseAppName: json['lowercaseAppName'] as String,
279-
githubReleaseOrganization:
280-
json['githubReleaseOrganization'] as String?,
266+
githubReleaseOrganization: json['githubReleaseOrganization'] as String?,
281267
githubReleaseProject: json['githubReleaseProject'] as String?,
282268
localReleases: skipLocalReleases
283269
? null
284270
: (json['localReleases'] as List?)?.map((dynamic r) {
285271
final rMap = r as Map;
286-
return Release(
287-
version: rMap['version'] as String,
288-
date: rMap['date'] as String);
272+
return Release(version: rMap['version'] as String, date: rMap['date'] as String);
289273
}).toList(),
290274
localReleaseAssets: skipLocalReleases
291275
? null
292276
: (json['localReleaseAssets'] as List?)?.map((dynamic ra) {
293277
final raMap = ra as Map;
294278
final archString = raMap['arch'] as String;
295-
final arch = (archString ==
296-
CPUArchitecture.x86_64.flatpakArchCode)
279+
final arch = (archString == CPUArchitecture.x86_64.flatpakArchCode)
297280
? CPUArchitecture.x86_64
298281
: (archString == CPUArchitecture.aarch64.flatpakArchCode)
299282
? CPUArchitecture.aarch64
@@ -302,11 +285,10 @@ class FlatpakMeta {
302285
throw Exception(
303286
'Architecture must be either "${CPUArchitecture.x86_64.flatpakArchCode}" or "${CPUArchitecture.aarch64.flatpakArchCode}"');
304287
}
305-
final tarballFile = File(
306-
'${jsonFile.parent.path}/${raMap['tarballPath'] as String}');
288+
final tarballFile =
289+
File('${jsonFile.parent.path}/${raMap['tarballPath'] as String}');
307290
final tarballPath = tarballFile.absolute.path;
308-
final preShasum =
309-
Process.runSync('shasum', ['-a', '256', tarballPath]);
291+
final preShasum = Process.runSync('shasum', ['-a', '256', tarballPath]);
310292
final shasum = preShasum.stdout.toString().split(' ').first;
311293
if (preShasum.exitCode != 0) {
312294
throw Exception(preShasum.stderr);
@@ -321,17 +303,14 @@ class FlatpakMeta {
321303
appStreamPath: json['appStreamPath'] as String,
322304
desktopPath: json['desktopPath'] as String,
323305
icons: (json['icons'] as Map).entries.map((mapEntry) {
324-
return Icon(
325-
type: mapEntry.key as String, path: mapEntry.value as String);
306+
return Icon(type: mapEntry.key as String, path: mapEntry.value as String);
326307
}).toList(),
327308
freedesktopRuntime: json['freedesktopRuntime'] as String,
328309
buildCommandsAfterUnpack: (json['buildCommandsAfterUnpack'] as List?)
329310
?.map((dynamic bc) => bc as String)
330311
.toList(),
331312
extraModules: json['extraModules'] as List?,
332-
finishArgs: (json['finishArgs'] as List)
333-
.map((dynamic fa) => fa as String)
334-
.toList());
313+
finishArgs: (json['finishArgs'] as List).map((dynamic fa) => fa as String).toList());
335314
} catch (e) {
336315
throw Exception('Could not parse JSON file, due to this error:\n$e');
337316
}

flatpak/scripts/manifest_generator.dart

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ void main(List<String> arguments) async {
2626
'You must run this script with a metadata file argument, using the --meta flag.');
2727
}
2828
if (arguments.length == metaIndex + 1) {
29-
throw Exception(
30-
'The --meta flag must be followed by the path to the metadata file.');
29+
throw Exception('The --meta flag must be followed by the path to the metadata file.');
3130
}
3231

3332
final metaFile = File(arguments[metaIndex + 1]);
@@ -37,23 +36,19 @@ void main(List<String> arguments) async {
3736

3837
final fetchFromGithub = arguments.contains('--github');
3938

40-
final meta =
41-
FlatpakMeta.fromJson(metaFile, skipLocalReleases: fetchFromGithub);
39+
final meta = FlatpakMeta.fromJson(metaFile, skipLocalReleases: fetchFromGithub);
4240

43-
final outputDir =
44-
Directory('${Directory.current.path}/flatpak_generator_exports');
41+
final outputDir = Directory('${Directory.current.path}/flatpak_generator_exports');
4542
outputDir.createSync();
4643

4744
final manifestGenerator = FlatpakManifestGenerator(meta);
48-
final manifestContent =
49-
await manifestGenerator.generateFlatpakManifest(fetchFromGithub);
45+
final manifestContent = await manifestGenerator.generateFlatpakManifest(fetchFromGithub);
5046
final manifestPath = '${outputDir.path}/${meta.appId}.json';
5147
final manifestFile = File(manifestPath);
5248
manifestFile.writeAsStringSync(manifestContent);
5349
print('Generated $manifestPath');
5450

55-
final flathubJsonContent =
56-
await manifestGenerator.generateFlathubJson(fetchFromGithub);
51+
final flathubJsonContent = await manifestGenerator.generateFlathubJson(fetchFromGithub);
5752
if (flathubJsonContent != null) {
5853
final flathubJsonPath = '${outputDir.path}/flathub.json';
5954
final flathubJsonFile = File(flathubJsonPath);
@@ -132,8 +127,7 @@ class FlatpakManifestGenerator {
132127

133128
const encoder = JsonEncoder.withIndent(' ');
134129

135-
final onlyArchListInput =
136-
fetchFromGithub ? _githubArchSupport! : _localArchSupport!;
130+
final onlyArchListInput = fetchFromGithub ? _githubArchSupport! : _localArchSupport!;
137131

138132
final onlyArchList = List<String>.empty(growable: true);
139133
for (final e in onlyArchListInput.entries) {
@@ -149,8 +143,7 @@ class FlatpakManifestGenerator {
149143
}
150144
}
151145

152-
void _lazyGenerateArchSupportMap(
153-
bool fetchFromGithub, List<ReleaseAsset> assets) {
146+
void _lazyGenerateArchSupportMap(bool fetchFromGithub, List<ReleaseAsset> assets) {
154147
if (fetchFromGithub) {
155148
if (_githubArchSupport == null) {
156149
_githubArchSupport = <CPUArchitecture, bool>{

lib/database/exercises/exercise_database.g.dart

Lines changed: 8 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/l10n/app_en.arb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,10 @@
639639
"@baseData": {
640640
"description": "The base data for an exercise such as category, trained muscles, etc."
641641
},
642+
"settingsTitle": "Settings",
643+
"settingsCacheTitle": "Cache",
644+
"settingsCacheDescription": "Exercise cache",
645+
"settingsCacheDeletedSnackbar": "Cache successfully cleared",
642646
"aboutPageTitle": "About Wger",
643647
"contributeExerciseWarning": "You can only contribute exercises if your account is older than {days} days and have verified your email",
644648
"@contributeExerciseWarning": {

lib/main.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import 'package:wger/screens/workout_plan_screen.dart';
4949
import 'package:wger/screens/workout_plans_screen.dart';
5050
import 'package:wger/theme/theme.dart';
5151
import 'package:wger/widgets/core/about.dart';
52+
import 'package:wger/widgets/core/settings.dart';
5253

5354
import 'providers/auth.dart';
5455

@@ -164,6 +165,7 @@ class MyApp extends StatelessWidget {
164165
ExerciseDetailScreen.routeName: (ctx) => const ExerciseDetailScreen(),
165166
AddExerciseScreen.routeName: (ctx) => const AddExerciseScreen(),
166167
AboutPage.routeName: (ctx) => const AboutPage(),
168+
SettingsPage.routeName: (ctx) => const SettingsPage(),
167169
},
168170
localizationsDelegates: AppLocalizations.localizationsDelegates,
169171
supportedLocales: AppLocalizations.supportedLocales,

lib/models/exercises/exercise_api.freezed.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.

lib/widgets/core/about.dart

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,11 @@ class AboutEntry extends StatelessWidget {
5757
}
5858
}
5959

60-
class AboutPage extends StatefulWidget {
60+
class AboutPage extends StatelessWidget {
6161
static String routeName = '/AboutPage';
6262

6363
const AboutPage({super.key});
6464

65-
@override
66-
State<AboutPage> createState() => _AboutPageState();
67-
}
68-
69-
class _AboutPageState extends State<AboutPage> {
7065
@override
7166
Widget build(BuildContext context) {
7267
final deviceSize = MediaQuery.of(context).size;

0 commit comments

Comments
 (0)