forked from firka/flutter
Add UIApplicationSupportsIndirectInputEvents migration (#106889)
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import '../../base/file_system.dart';
|
||||
import '../../base/project_migrator.dart';
|
||||
import '../../xcode_project.dart';
|
||||
|
||||
const String _kDisableMinimumFrameDurationKey = 'CADisableMinimumFrameDurationOnPhone';
|
||||
const String _kIndirectInputEventsKey = 'UIApplicationSupportsIndirectInputEvents';
|
||||
|
||||
/// Update Info.plist.
|
||||
class HostAppInfoPlistMigration extends ProjectMigrator {
|
||||
HostAppInfoPlistMigration(
|
||||
IosProject project,
|
||||
super.logger,
|
||||
) : _infoPlist = project.defaultHostInfoPlist;
|
||||
|
||||
final File _infoPlist;
|
||||
|
||||
@override
|
||||
bool migrate() {
|
||||
if (!_infoPlist.existsSync()) {
|
||||
logger.printTrace('Info.plist not found, skipping host app Info.plist migration.');
|
||||
return true;
|
||||
}
|
||||
|
||||
processFileLines(_infoPlist);
|
||||
return true;
|
||||
}
|
||||
|
||||
@override
|
||||
String migrateFileContents(String fileContents) {
|
||||
String newContents = fileContents;
|
||||
if (!newContents.contains(_kDisableMinimumFrameDurationKey)) {
|
||||
logger.printTrace('Adding $_kDisableMinimumFrameDurationKey to Info.plist');
|
||||
const String plistEnd = '''
|
||||
</dict>
|
||||
</plist>
|
||||
''';
|
||||
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 newContents;
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import '../../base/file_system.dart';
|
||||
import '../../base/project_migrator.dart';
|
||||
import '../../xcode_project.dart';
|
||||
|
||||
const String _kDisableMinimumFrameDurationKey = 'CADisableMinimumFrameDurationOnPhone';
|
||||
|
||||
/// Add "CADisableMinimumFrameDurationOnPhone: true" to the Info.plist.
|
||||
class MinimumFrameDurationMigration extends ProjectMigrator {
|
||||
MinimumFrameDurationMigration(
|
||||
IosProject project,
|
||||
super.logger,
|
||||
) : _infoPlist = project.defaultHostInfoPlist;
|
||||
|
||||
final File _infoPlist;
|
||||
|
||||
@override
|
||||
bool migrate() {
|
||||
if (!_infoPlist.existsSync()) {
|
||||
logger.printTrace('Info.plist not found, skipping minimum frame duration migration.');
|
||||
return true;
|
||||
}
|
||||
|
||||
processFileLines(_infoPlist);
|
||||
return true;
|
||||
}
|
||||
|
||||
@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 = '''
|
||||
</dict>
|
||||
</plist>
|
||||
''';
|
||||
const String plistWithKey = '''
|
||||
<key>$_kDisableMinimumFrameDurationKey</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
||||
''';
|
||||
|
||||
return fileContents.replaceAll(plistEnd, plistWithKey);
|
||||
}
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user