diff --git a/android/app/build.gradle b/android/app/build.gradle
index f81c24ede..be6c05e4a 100644
--- a/android/app/build.gradle
+++ b/android/app/build.gradle
@@ -33,6 +33,8 @@ android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
+ // Required by flutter_local_notifications
+ coreLibraryDesugaringEnabled true
}
@@ -80,3 +82,7 @@ kotlin {
flutter {
source '../..'
}
+
+dependencies {
+ coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.1.4'
+}
diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index fe564095e..c394fde5b 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -8,6 +8,8 @@
+
+
+
+
+
+
+
+
+
diff --git a/android/app/src/main/res/raw/keep.xml b/android/app/src/main/res/raw/keep.xml
new file mode 100644
index 000000000..2a8d6c080
--- /dev/null
+++ b/android/app/src/main/res/raw/keep.xml
@@ -0,0 +1,4 @@
+
+
+
diff --git a/ios/Runner/AppDelegate.swift b/ios/Runner/AppDelegate.swift
index fa82d5621..758e0a42a 100644
--- a/ios/Runner/AppDelegate.swift
+++ b/ios/Runner/AppDelegate.swift
@@ -1,5 +1,6 @@
import Flutter
import UIKit
+import flutter_local_notifications
private final class StorageExclusionPlugin: NSObject, FlutterPlugin {
static let pluginName = "StorageExclusionPlugin"
@@ -49,17 +50,83 @@ private final class StorageExclusionPlugin: NSObject, FlutterPlugin {
}
}
+/// Keeps the app running while the main isolate handles a notification
+/// action, until Dart reports it as handled
+private final class NotificationActionTasks: NSObject, FlutterPlugin {
+ static let pluginName = "NotificationActionTasks"
+ private static let channelName = "de.wger.flutter/notification_actions"
+ /// Upper bound if Dart never reports back, e.g. without a running workout
+ private static let timeout: TimeInterval = 20
+ private static var tasks: [UIBackgroundTaskIdentifier] = []
+
+ static func register(with registrar: FlutterPluginRegistrar) {
+ let channel = FlutterMethodChannel(name: channelName, binaryMessenger: registrar.messenger())
+ registrar.addMethodCallDelegate(NotificationActionTasks(), channel: channel)
+ }
+
+ static func begin() {
+ var task: UIBackgroundTaskIdentifier = .invalid
+ task = UIApplication.shared.beginBackgroundTask { end(task) }
+ tasks.append(task)
+ DispatchQueue.main.asyncAfter(deadline: .now() + timeout) { end(task) }
+ }
+
+ private static func end(_ task: UIBackgroundTaskIdentifier) {
+ guard let index = tasks.firstIndex(of: task) else {
+ return
+ }
+ tasks.remove(at: index)
+ UIApplication.shared.endBackgroundTask(task)
+ }
+
+ func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
+ guard call.method == "actionHandled" else {
+ result(FlutterMethodNotImplemented)
+ return
+ }
+ for task in Self.tasks {
+ Self.end(task)
+ }
+ result(nil)
+ }
+}
+
@main
@objc class AppDelegate: FlutterAppDelegate, FlutterImplicitEngineDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
+ // Lets notifications show in the foreground and delivers action responses
+ UNUserNotificationCenter.current().delegate = self as UNUserNotificationCenterDelegate
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
+ // A notification action is handled by the main isolate, but the plugin
+ // completes the response right away and iOS suspends the app again
+ override func userNotificationCenter(
+ _ center: UNUserNotificationCenter,
+ didReceive response: UNNotificationResponse,
+ withCompletionHandler completionHandler: @escaping () -> Void
+ ) {
+ NotificationActionTasks.begin()
+ super.userNotificationCenter(
+ center, didReceive: response, withCompletionHandler: completionHandler)
+ }
+
func didInitializeImplicitFlutterEngine(_ engineBridge: FlutterImplicitEngineBridge) {
+ // Notification actions run in a separate engine, which needs the plugins too
+ FlutterLocalNotificationsPlugin.setPluginRegistrantCallback { registry in
+ GeneratedPluginRegistrant.register(with: registry)
+ }
GeneratedPluginRegistrant.register(with: engineBridge.pluginRegistry)
+ if let registrar = engineBridge.pluginRegistry.registrar(
+ forPlugin: NotificationActionTasks.pluginName
+ ) {
+ NotificationActionTasks.register(with: registrar)
+ } else {
+ NSLog("NotificationActionTasks registrar unavailable")
+ }
guard
let registrar = engineBridge.pluginRegistry.registrar(
forPlugin: StorageExclusionPlugin.pluginName
diff --git a/lib/core/network/auth_notifier.dart b/lib/core/network/auth_notifier.dart
index 136d6bad3..fcce86727 100644
--- a/lib/core/network/auth_notifier.dart
+++ b/lib/core/network/auth_notifier.dart
@@ -20,7 +20,7 @@ import 'dart:async';
import 'dart:convert';
import 'package:connectivity_plus/connectivity_plus.dart';
-import 'package:flutter/foundation.dart' show visibleForTesting;
+import 'package:flutter/foundation.dart' show kDebugMode, visibleForTesting;
import 'package:flutter/widgets.dart' show AppLifecycleListener;
import 'package:http/http.dart' as http;
import 'package:logging/logging.dart';
@@ -874,11 +874,12 @@ class AuthNotifier extends _$AuthNotifier {
state = AsyncData(current.copyWith(serverVersion: v));
}
- /// Loads the last server URL the user successfully logged in with.
+ /// Loads the last server URL the user successfully logged in with, or the
+ /// default server of this build (the test server in debug builds).
static Future getServerUrlFromPrefs() async {
final prefs = PreferenceHelper.asyncPref;
if (!(await prefs.containsKey(PREFS_LAST_SERVER))) {
- return DEFAULT_SERVER_PROD;
+ return kDebugMode ? DEFAULT_SERVER_TEST : DEFAULT_SERVER_PROD;
}
final userData = json.decode((await prefs.getString(PREFS_LAST_SERVER))!);
diff --git a/lib/features/routines/models/set_config_data.dart b/lib/features/routines/models/set_config_data.dart
index ff3696078..5fc175300 100644
--- a/lib/features/routines/models/set_config_data.dart
+++ b/lib/features/routines/models/set_config_data.dart
@@ -45,6 +45,10 @@ class SetConfigData {
String get textReprWithType => '$textRepr${type.typeLabel}';
+ /// [textRepr] without sets, RiR and rest, null from older servers
+ @JsonKey(name: 'text_repr_short')
+ String? textReprShort;
+
@JsonKey(required: true, name: 'sets')
num? nrOfSets;
@@ -120,6 +124,7 @@ class SetConfigData {
this.maxRestTime,
this.comment = '',
this.textRepr = '',
+ this.textReprShort,
Exercise? exercise,
WeightUnit? weightUnit,
RepetitionUnit? repetitionsUnit,
@@ -140,6 +145,7 @@ class SetConfigData {
int? slotEntryId,
SlotEntryType? type,
String? textRepr,
+ String? textReprShort,
num? nrOfSets,
num? maxNrOfSets,
num? weight,
@@ -165,6 +171,7 @@ class SetConfigData {
slotEntryId: slotEntryId ?? this.slotEntryId,
type: type ?? this.type,
textRepr: textRepr ?? this.textRepr,
+ textReprShort: textReprShort ?? this.textReprShort,
nrOfSets: nrOfSets ?? this.nrOfSets,
maxNrOfSets: maxNrOfSets ?? this.maxNrOfSets,
weight: weight ?? this.weight,
diff --git a/lib/features/routines/models/set_config_data.g.dart b/lib/features/routines/models/set_config_data.g.dart
index eba87c76a..d02616fc4 100644
--- a/lib/features/routines/models/set_config_data.g.dart
+++ b/lib/features/routines/models/set_config_data.g.dart
@@ -55,6 +55,7 @@ SetConfigData _$SetConfigDataFromJson(Map json) {
maxRestTime: stringToNumNull(json['max_rest'] as String?),
comment: json['comment'] as String? ?? '',
textRepr: json['text_repr'] as String? ?? '',
+ textReprShort: json['text_repr_short'] as String?,
);
}
@@ -63,6 +64,7 @@ Map _$SetConfigDataToJson(SetConfigData instance) => .
+ * Copyright (c) 2026 wger Team
+ *
+ * wger Workout Manager is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+import 'dart:convert';
+
+import 'package:collection/collection.dart';
+import 'package:equatable/equatable.dart';
+import 'package:wger/core/consts.dart';
+import 'package:wger/core/misc.dart';
+import 'package:wger/features/routines/models/log.dart';
+import 'package:wger/features/routines/models/set_config_data.dart';
+import 'package:wger/features/routines/providers/gym_state.dart';
+import 'package:wger/features/routines/validators.dart';
+import 'package:wger/l10n/generated/app_localizations.dart';
+
+/// How much "+30 s" adds to a rest
+const REST_EXTENSION = Duration(seconds: 30);
+
+/// Identifies the gym session and the slot pages a notification action targets
+class WorkoutNotificationPayload extends Equatable {
+ final int routineId;
+ final int dayId;
+ final int iteration;
+ final DateTime workoutStart;
+
+ /// The log page the "log set" action logs
+ final String? logSlotKey;
+
+ /// The timer page the "skip rest" action leaves
+ final String? restSlotKey;
+
+ const WorkoutNotificationPayload({
+ required this.routineId,
+ required this.dayId,
+ required this.iteration,
+ required this.workoutStart,
+ this.logSlotKey,
+ this.restSlotKey,
+ });
+
+ /// Whether this belongs to the session [state] is running
+ bool matches(GymModeState state) =>
+ state.isInitialized &&
+ state.routine.id == routineId &&
+ state.dayId == dayId &&
+ state.iteration == iteration &&
+ state.workoutStart.isAtSameMomentAs(workoutStart);
+
+ String encode() => jsonEncode({
+ 'routineId': routineId,
+ 'dayId': dayId,
+ 'iteration': iteration,
+ 'workoutStart': workoutStart.toUtc().toIso8601String(),
+ 'logSlotKey': logSlotKey,
+ 'restSlotKey': restSlotKey,
+ });
+
+ /// Null if [payload] is missing or not one of ours
+ static WorkoutNotificationPayload? decode(String? payload) {
+ if (payload == null) {
+ return null;
+ }
+ try {
+ final json = jsonDecode(payload) as Map;
+ return WorkoutNotificationPayload(
+ routineId: json['routineId'] as int,
+ dayId: json['dayId'] as int,
+ iteration: json['iteration'] as int,
+ workoutStart: DateTime.parse(json['workoutStart'] as String),
+ logSlotKey: json['logSlotKey'] as String?,
+ restSlotKey: json['restSlotKey'] as String?,
+ );
+ } on Object {
+ return null;
+ }
+ }
+
+ @override
+ List