Unverified Commit 902b0124 authored by Callum Moffat's avatar Callum Moffat Committed by GitHub

Add `UIApplicationSupportsIndirectInputEvents` migration (#106889)

parent 2987d9e1
......@@ -26,7 +26,7 @@ import 'application_package.dart';
import 'code_signing.dart';
import 'iproxy.dart';
import 'migrations/deployment_target_migration.dart';
import 'migrations/minimum_frame_duration_migration.dart';
import 'migrations/host_app_info_plist_migration.dart';
import 'migrations/project_base_configuration_migration.dart';
import 'migrations/project_build_location_migration.dart';
import 'migrations/project_object_version_migration.dart';
......@@ -125,7 +125,7 @@ Future<XcodeBuildResult> buildXcodeProject({
ProjectBuildLocationMigration(app.project, globals.logger),
DeploymentTargetMigration(app.project, globals.logger),
ProjectObjectVersionMigration(app.project, globals.logger),
MinimumFrameDurationMigration(app.project, globals.logger),
HostAppInfoPlistMigration(app.project, globals.logger),
];
final ProjectMigration migration = ProjectMigration(migrators);
......
......@@ -7,10 +7,11 @@ import '../../base/project_migrator.dart';
import '../../xcode_project.dart';
const String _kDisableMinimumFrameDurationKey = 'CADisableMinimumFrameDurationOnPhone';
const String _kIndirectInputEventsKey = 'UIApplicationSupportsIndirectInputEvents';
/// Add "CADisableMinimumFrameDurationOnPhone: true" to the Info.plist.
class MinimumFrameDurationMigration extends ProjectMigrator {
MinimumFrameDurationMigration(
/// Update Info.plist.
class HostAppInfoPlistMigration extends ProjectMigrator {
HostAppInfoPlistMigration(
IosProject project,
super.logger,
) : _infoPlist = project.defaultHostInfoPlist;
......@@ -20,7 +21,7 @@ class MinimumFrameDurationMigration extends ProjectMigrator {
@override
bool migrate() {
if (!_infoPlist.existsSync()) {
logger.printTrace('Info.plist not found, skipping minimum frame duration migration.');
logger.printTrace('Info.plist not found, skipping host app Info.plist migration.');
return true;
}
......@@ -30,22 +31,37 @@ class MinimumFrameDurationMigration extends ProjectMigrator {
@override
String migrateFileContents(String fileContents) {
if (fileContents.contains(_kDisableMinimumFrameDurationKey)) {
// No migration needed if the key already exits.
return fileContents;
}
logger.printTrace('Adding $_kDisableMinimumFrameDurationKey to Info.plist');
const String plistEnd = '''
String newContents = fileContents;
if (!newContents.contains(_kDisableMinimumFrameDurationKey)) {
logger.printTrace('Adding $_kDisableMinimumFrameDurationKey to Info.plist');
const String plistEnd = '''
</dict>
</plist>
''';
const String plistWithKey = '''
const String plistWithKey = '''
<key>$_kDisableMinimumFrameDurationKey</key>
<true/>
</dict>
</plist>
''';
newContents = newContents.replaceAll(plistEnd, plistWithKey);
}
if (!newContents.contains(_kIndirectInputEventsKey)) {
logger.printTrace('Adding $_kIndirectInputEventsKey to Info.plist');
const String plistEnd = '''
</dict>
</plist>
''';
const String plistWithKey = '''
<key>$_kIndirectInputEventsKey</key>
<true/>
</dict>
</plist>
''';
newContents = newContents.replaceAll(plistEnd, plistWithKey);
}
return fileContents.replaceAll(plistEnd, plistWithKey);
return newContents;
}
}
......@@ -7,7 +7,7 @@ import 'package:file/memory.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/project_migrator.dart';
import 'package:flutter_tools/src/ios/migrations/deployment_target_migration.dart';
import 'package:flutter_tools/src/ios/migrations/minimum_frame_duration_migration.dart';
import 'package:flutter_tools/src/ios/migrations/host_app_info_plist_migration.dart';
import 'package:flutter_tools/src/ios/migrations/project_base_configuration_migration.dart';
import 'package:flutter_tools/src/ios/migrations/project_build_location_migration.dart';
import 'package:flutter_tools/src/ios/migrations/project_object_version_migration.dart';
......@@ -738,7 +738,7 @@ platform :ios, '11.0'
});
});
group('add CADisableMinimumFrameDurationOnPhone key to info.plist migration', () {
group('update info.plist migration', () {
late MemoryFileSystem memoryFileSystem;
late BufferLogger testLogger;
late FakeIosProject project;
......@@ -753,14 +753,14 @@ platform :ios, '11.0'
});
testWithoutContext('skipped if files are missing', () {
final MinimumFrameDurationMigration iosProjectMigration = MinimumFrameDurationMigration(
final HostAppInfoPlistMigration iosProjectMigration = HostAppInfoPlistMigration(
project,
testLogger,
);
expect(iosProjectMigration.migrate(), isTrue);
expect(infoPlistFile.existsSync(), isFalse);
expect(testLogger.traceText, contains('Info.plist not found, skipping minimum frame duration migration.'));
expect(testLogger.traceText, contains('Info.plist not found, skipping host app Info.plist migration.'));
expect(testLogger.statusText, isEmpty);
});
......@@ -772,12 +772,14 @@ platform :ios, '11.0'
<dict>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
</dict>
</plist>
''';
infoPlistFile.writeAsStringSync(infoPlistFileContent);
final MinimumFrameDurationMigration iosProjectMigration = MinimumFrameDurationMigration(
final HostAppInfoPlistMigration iosProjectMigration = HostAppInfoPlistMigration(
project,
testLogger,
);
......@@ -788,7 +790,7 @@ platform :ios, '11.0'
expect(testLogger.statusText, isEmpty);
});
testWithoutContext('info.plist is migrated to use CADisableMinimumFrameDurationOnPhone', () {
testWithoutContext('info.plist is migrated', () {
const String infoPlistFileContent = '''
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
......@@ -799,7 +801,7 @@ platform :ios, '11.0'
''';
infoPlistFile.writeAsStringSync(infoPlistFileContent);
final MinimumFrameDurationMigration iosProjectMigration = MinimumFrameDurationMigration(
final HostAppInfoPlistMigration iosProjectMigration = HostAppInfoPlistMigration(
project,
testLogger,
);
......@@ -811,12 +813,15 @@ platform :ios, '11.0'
<dict>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
</dict>
</plist>
'''));
});
});
});
}
class FakeIosProject extends Fake implements IosProject {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment