mirror of
https://github.com/wger-project/flutter.git
synced 2026-12-05 04:57:37 +01:00
Merge pull request #1337 from peter9teufel/release-2.7-ios-health-prep
Prepare iOS health release requirements
This commit is contained in:
@@ -1,6 +1,54 @@
|
||||
import Flutter
|
||||
import UIKit
|
||||
|
||||
private final class StorageExclusionPlugin: NSObject, FlutterPlugin {
|
||||
static let pluginName = "StorageExclusionPlugin"
|
||||
private static let channelName = "de.wger.flutter/storage"
|
||||
|
||||
static func register(with registrar: FlutterPluginRegistrar) {
|
||||
let channel = FlutterMethodChannel(name: channelName, binaryMessenger: registrar.messenger())
|
||||
let instance = StorageExclusionPlugin()
|
||||
registrar.addMethodCallDelegate(instance, channel: channel)
|
||||
}
|
||||
|
||||
func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
|
||||
guard call.method == "excludeFromBackup" else {
|
||||
result(FlutterMethodNotImplemented)
|
||||
return
|
||||
}
|
||||
guard
|
||||
let arguments = call.arguments as? [String: Any],
|
||||
let path = arguments["path"] as? String,
|
||||
!path.isEmpty
|
||||
else {
|
||||
result(
|
||||
FlutterError(
|
||||
code: "INVALID_ARGUMENT",
|
||||
message: "Expected a non-empty path",
|
||||
details: nil
|
||||
)
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
do {
|
||||
var url = URL(fileURLWithPath: path)
|
||||
var values = URLResourceValues()
|
||||
values.isExcludedFromBackup = true
|
||||
try url.setResourceValues(values)
|
||||
result(nil)
|
||||
} catch {
|
||||
result(
|
||||
FlutterError(
|
||||
code: "EXCLUDE_FROM_BACKUP_FAILED",
|
||||
message: "Could not exclude \(path) from backups",
|
||||
details: error.localizedDescription
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@main
|
||||
@objc class AppDelegate: FlutterAppDelegate, FlutterImplicitEngineDelegate {
|
||||
override func application(
|
||||
@@ -12,5 +60,14 @@ import UIKit
|
||||
|
||||
func didInitializeImplicitFlutterEngine(_ engineBridge: FlutterImplicitEngineBridge) {
|
||||
GeneratedPluginRegistrant.register(with: engineBridge.pluginRegistry)
|
||||
guard
|
||||
let registrar = engineBridge.pluginRegistry.registrar(
|
||||
forPlugin: StorageExclusionPlugin.pluginName
|
||||
)
|
||||
else {
|
||||
NSLog("StorageExclusionPlugin registrar unavailable")
|
||||
return
|
||||
}
|
||||
StorageExclusionPlugin.register(with: registrar)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@
|
||||
<key>NSCameraUsageDescription</key>
|
||||
<string>Workout photos</string>
|
||||
<key>NSHealthShareUsageDescription</key>
|
||||
<string>wger reads your health data to automatically import body measurements such as weight, body fat, blood pressure, heart rate and blood oxygen</string>
|
||||
<string>wger reads your Apple Health data to import measurements and activity such as weight, body fat, blood pressure, heart rate, blood oxygen, sleep, steps, distance, and active energy into your wger account</string>
|
||||
<key>UIApplicationSceneManifest</key>
|
||||
<dict>
|
||||
<key>UIApplicationSupportsMultipleScenes</key>
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:logging/logging.dart';
|
||||
@@ -40,6 +41,9 @@ import 'package:wger/powersync/sync_watchdog.dart';
|
||||
part 'powersync.g.dart';
|
||||
|
||||
final _logger = Logger('powersync');
|
||||
const _storageChannel = MethodChannel('de.wger.flutter/storage');
|
||||
const _dbFilename = 'powersync-wger.db';
|
||||
const _iosDbDirectoryName = 'de.wger.flutter.community';
|
||||
|
||||
PowerSyncDatabase? _builtInstance;
|
||||
|
||||
@@ -283,14 +287,47 @@ final syncStatus = Provider((ref) {
|
||||
});
|
||||
|
||||
Future<String> _getDatabasePath() async {
|
||||
const dbFilename = 'powersync-wger.db';
|
||||
|
||||
// getApplicationSupportDirectory is not supported on Web
|
||||
if (kIsWeb) {
|
||||
return dbFilename;
|
||||
return _dbFilename;
|
||||
}
|
||||
|
||||
final dir = await getApplicationSupportDirectory();
|
||||
return join(dir.path, dbFilename);
|
||||
if (!Platform.isIOS) {
|
||||
return join(dir.path, _dbFilename);
|
||||
}
|
||||
|
||||
final dbDir = Directory(join(dir.path, _iosDbDirectoryName));
|
||||
await dbDir.create(recursive: true);
|
||||
await _migrateLegacyIosDatabaseFiles(fromDirectory: dir, toDirectory: dbDir);
|
||||
await _excludeFromBackup(dbDir.path);
|
||||
return join(dbDir.path, _dbFilename);
|
||||
}
|
||||
|
||||
Future<void> _migrateLegacyIosDatabaseFiles({
|
||||
required Directory fromDirectory,
|
||||
required Directory toDirectory,
|
||||
}) async {
|
||||
for (final suffix in ['', '-wal', '-shm', '-journal']) {
|
||||
final from = File(join(fromDirectory.path, '$_dbFilename$suffix'));
|
||||
final to = File(join(toDirectory.path, '$_dbFilename$suffix'));
|
||||
|
||||
if (!from.existsSync() || to.existsSync()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
await from.rename(to.path);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _excludeFromBackup(String path) async {
|
||||
try {
|
||||
await _storageChannel.invokeMethod<void>('excludeFromBackup', {'path': path});
|
||||
} on MissingPluginException {
|
||||
_logger.warning('Could not exclude $path from backups: storage channel unavailable');
|
||||
} on PlatformException catch (e, s) {
|
||||
_logger.warning('Could not exclude $path from backups', e, s);
|
||||
}
|
||||
}
|
||||
|
||||
/// Deletes the on-disk PowerSync SQLite files (main DB plus WAL/SHM/journal
|
||||
|
||||
54
test/features/health/health_ios_release_prep_test.dart
Normal file
54
test/features/health/health_ios_release_prep_test.dart
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* This file is part of wger Workout Manager <https://github.com/wger-project>.
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('iOS health release prep', () {
|
||||
test('Info.plist describes the imported Health data scope', () {
|
||||
final plist = File('ios/Runner/Info.plist').readAsStringSync();
|
||||
|
||||
expect(plist, contains('<key>NSHealthShareUsageDescription</key>'));
|
||||
expect(plist, contains('Apple Health'));
|
||||
expect(plist, contains('sleep, steps, distance, and active energy'));
|
||||
expect(plist, contains('wger account'));
|
||||
});
|
||||
|
||||
test('PowerSync DB setup excludes the iOS database directory from backups', () {
|
||||
final databaseSetup = File('lib/database/powersync/powersync.dart').readAsStringSync();
|
||||
|
||||
expect(databaseSetup, contains("const _iosDbDirectoryName = 'de.wger.flutter.community';"));
|
||||
expect(databaseSetup, contains("MethodChannel('de.wger.flutter/storage')"));
|
||||
expect(databaseSetup, contains('await _excludeFromBackup(dbDir.path);'));
|
||||
expect(
|
||||
databaseSetup,
|
||||
contains('await _migrateLegacyIosDatabaseFiles(fromDirectory: dir, toDirectory: dbDir);'),
|
||||
);
|
||||
});
|
||||
|
||||
test('AppDelegate exposes the backup-exclusion channel', () {
|
||||
final appDelegate = File('ios/Runner/AppDelegate.swift').readAsStringSync();
|
||||
|
||||
expect(appDelegate, contains('de.wger.flutter/storage'));
|
||||
expect(appDelegate, contains('excludeFromBackup'));
|
||||
expect(appDelegate, contains('values.isExcludedFromBackup = true'));
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user