Skip to content

Commit

Permalink
breaking (MediaPlaybackRequiresUserAction): delete
Browse files Browse the repository at this point in the history
* As the new preference key always exists in "defaults.xml", the old preference key would never be used.
* Updated deprecation warning logic to include "has been" deprecated since it was completely removed. Most cases the warning would be removed as well but the previous releases never properly warn the user. Warning will remain for next major only as a migration step for users.
  • Loading branch information
erisu committed Feb 25, 2020
1 parent 5792c8a commit cb8f965
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,29 +75,21 @@ - (WKWebViewConfiguration*) createConfigurationFromSettings:(NSDictionary*)setti

configuration.allowsInlineMediaPlayback = [settings cordovaBoolSettingForKey:@"AllowInlineMediaPlayback" defaultValue:NO];

/*
* If the old preference key "MediaPlaybackRequiresUserAction" exists, use it or default to "YES".
* Old to New Preference Mapping
* YES = ALL
* NO = NONE
* Check if the new preference key "MediaTypesRequiringUserActionForPlayback" exists and overwrite the "MediaPlaybackRequiresUserAction" value.
*/
BOOL mediaPlaybackRequiresUserAction = [settings cordovaBoolSettingForKey:@"MediaPlaybackRequiresUserAction" defaultValue:YES];
WKAudiovisualMediaTypes mediaType = mediaPlaybackRequiresUserAction ? WKAudiovisualMediaTypeAll : WKAudiovisualMediaTypeNone;
// Set the media types that are required for user action for playback
WKAudiovisualMediaTypes mediaType = WKAudiovisualMediaTypeAll; // default

// targetMediaType will always exist, either from user's "config.xml" or default ("defaults.xml").
id targetMediaType = [settings cordovaSettingForKey:@"MediaTypesRequiringUserActionForPlayback"];
if(targetMediaType != nil) {
if ([targetMediaType isEqualToString:@"none"]) {
mediaType = WKAudiovisualMediaTypeNone;
} else if ([targetMediaType isEqualToString:@"audio"]) {
mediaType = WKAudiovisualMediaTypeAudio;
} else if ([targetMediaType isEqualToString:@"video"]) {
mediaType = WKAudiovisualMediaTypeVideo;
} else if ([targetMediaType isEqualToString:@"all"]) {
mediaType = WKAudiovisualMediaTypeAll;
} else {
NSLog(@"Invalid \"MediaTypesRequiringUserActionForPlayback\" was detected. Fallback to default value.");
}
if ([targetMediaType isEqualToString:@"none"]) {
mediaType = WKAudiovisualMediaTypeNone;
} else if ([targetMediaType isEqualToString:@"audio"]) {
mediaType = WKAudiovisualMediaTypeAudio;
} else if ([targetMediaType isEqualToString:@"video"]) {
mediaType = WKAudiovisualMediaTypeVideo;
} else if ([targetMediaType isEqualToString:@"all"]) {
mediaType = WKAudiovisualMediaTypeAll;
} else {
NSLog(@"Invalid \"MediaTypesRequiringUserActionForPlayback\" was detected. Fallback to default value of \"all\" types.");
}
configuration.mediaTypesRequiringUserActionForPlayback = mediaType;

Expand Down
33 changes: 26 additions & 7 deletions bin/templates/scripts/cordova/lib/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,21 +522,40 @@ function updateFileResources (cordovaProject, locations) {

function alertDeprecatedPreference (configParser) {
const deprecatedToNewPreferences = {
MediaPlaybackRequiresUserAction: 'MediaTypesRequiringUserActionForPlayback',
MediaPlaybackAllowsAirPlay: 'AllowsAirPlayForMediaPlayback'
MediaPlaybackRequiresUserAction: {
newPreference: 'MediaTypesRequiringUserActionForPlayback',
isDeprecated: true
},
MediaPlaybackAllowsAirPlay: {
newPreference: 'AllowsAirPlayForMediaPlayback',
isDeprecated: false
}
};

Object.keys(deprecatedToNewPreferences).forEach(oldKey => {
if (configParser.getPreference(oldKey)) {
const log = [`The preference name "${oldKey}" is being deprecated.`];

if (deprecatedToNewPreferences[oldKey]) {
log.push(`It is recommended to update this preference with "${deprecatedToNewPreferences[oldKey]}."`);
const isDeprecated = deprecatedToNewPreferences[oldKey].isDeprecated;
const verb = isDeprecated ? 'has been' : 'is being';
const newPreferenceKey = deprecatedToNewPreferences[oldKey].newPreference;

// Create the Log Message
const log = [`The preference name "${oldKey}" ${verb} deprecated.`];
if (newPreferenceKey) {
log.push(`It is recommended to replace this preference with "${newPreferenceKey}."`);
} else {
log.push(`There is no replacement for this preference.`);
}

log.push(`Please note that this preference will be removed in the near future.`);
/**
* If the preference has been deprecated, the usage of the old preference is no longer used.
* Therefore, the following line is not appended. It is added only if the old preference is still used.
* We are only keeping the top lines for deprecated items only for an additional major release when
* the pre-warning was not provided in a past major release due to a necessary quick deprecation.
* Typically caused by implementation nature or third-party requirement changes.
*/
if (!isDeprecated) {
log.push(`Please note that this preference will be removed in the near future.`);
}

events.emit('warn', log.join(' '));
}
Expand Down
4 changes: 2 additions & 2 deletions tests/CordovaLibTests/CDVWebViewEngineTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ - (void) testUpdateInfo {
NSDictionary* preferences = @{
[@"MinimumFontSize" lowercaseString] : @1.1, // default is 0.0
[@"AllowInlineMediaPlayback" lowercaseString] : @YES, // default is NO
[@"MediaTypesRequiringUserActionForPlayback" lowercaseString] : @YES, // default is NO
[@"MediaTypesRequiringUserActionForPlayback" lowercaseString] : @"all", // default is NO
[@"SuppressesIncrementalRendering" lowercaseString] : @YES, // default is NO
[@"AllowsAirPlayForMediaPlayback" lowercaseString] : @NO, // default is YES
[@"DisallowOverscroll" lowercaseString] : @YES, // so bounces is to be NO. defaults to NO
Expand Down Expand Up @@ -133,7 +133,7 @@ - (void) testConfigurationFromSettings {
NSDictionary* settings = @{
[@"MinimumFontSize" lowercaseString] : @1.1, // default is 0.0
[@"AllowInlineMediaPlayback" lowercaseString] : @YES, // default is NO
[@"MediaTypesRequiringUserActionForPlayback" lowercaseString] : @YES, // default is NO
[@"MediaTypesRequiringUserActionForPlayback" lowercaseString] : @"all", // default is NO
[@"SuppressesIncrementalRendering" lowercaseString] : @YES, // default is NO
[@"AllowsAirPlayForMediaPlayback" lowercaseString] : @NO, // default is YES
[@"DisallowOverscroll" lowercaseString] : @YES, // so bounces is to be NO. defaults to NO
Expand Down

0 comments on commit cb8f965

Please sign in to comment.