Fixed User Script remove methods, Fixed macOS available checks for XCode 14.1
This commit is contained in:
parent
34236b0742
commit
d39b1ef374
|
@ -1,3 +1,8 @@
|
|||
## 6.0.0-beta.14
|
||||
|
||||
- Fixed User Script remove methods
|
||||
- Fixed macOS available checks for XCode 14.1
|
||||
|
||||
## 6.0.0-beta.13
|
||||
|
||||
- Added `ContentBlockerActionType.BLOCK_COOKIES` and `ContentBlockerActionType.IGNORE_PREVIOUS_RULES` for iOS and macOS platforms
|
||||
|
|
|
@ -276,7 +276,7 @@ extension WKUserContentController {
|
|||
|
||||
var userScriptsUpdated: [WKUserScript] = []
|
||||
for script in userScripts {
|
||||
if !userScripts.contains(script) {
|
||||
if !scriptsToRemove.contains(script) {
|
||||
userScriptsUpdated.append(script)
|
||||
}
|
||||
}
|
||||
|
@ -296,6 +296,7 @@ extension WKUserContentController {
|
|||
for script in allUserOnlyScripts {
|
||||
if let scriptName = script.groupName, scriptName == groupName {
|
||||
scriptsToRemove.append(script)
|
||||
userOnlyScripts[script.injectionTime]!.remove(script)
|
||||
}
|
||||
}
|
||||
removeUserScripts(scriptsToRemove: scriptsToRemove, shouldAddPreviousScripts: shouldAddPreviousScripts)
|
||||
|
@ -307,6 +308,7 @@ extension WKUserContentController {
|
|||
for script in allPluginScripts {
|
||||
if let scriptName = script.groupName, scriptName == groupName {
|
||||
scriptsToRemove.append(script)
|
||||
pluginScripts[script.injectionTime]!.remove(script)
|
||||
}
|
||||
}
|
||||
removeUserScripts(scriptsToRemove: scriptsToRemove, shouldAddPreviousScripts: shouldAddPreviousScripts)
|
||||
|
|
|
@ -56,7 +56,10 @@ class InAppWebViewController {
|
|||
static MethodChannel _staticChannel = IN_APP_WEBVIEW_STATIC_CHANNEL;
|
||||
Map<String, JavaScriptHandlerCallback> javaScriptHandlersMap =
|
||||
HashMap<String, JavaScriptHandlerCallback>();
|
||||
List<UserScript> _userScripts = [];
|
||||
final Map<UserScriptInjectionTime, List<UserScript>> _userScripts = {
|
||||
UserScriptInjectionTime.AT_DOCUMENT_START: <UserScript>[],
|
||||
UserScriptInjectionTime.AT_DOCUMENT_END: <UserScript>[]
|
||||
};
|
||||
Set<String> _webMessageListenerObjNames = Set();
|
||||
Map<String, ScriptHtmlTagAttributes> _injectedScriptsFromURL = {};
|
||||
|
||||
|
@ -88,8 +91,23 @@ class InAppWebViewController {
|
|||
}
|
||||
});
|
||||
this._webview = webview;
|
||||
this._userScripts =
|
||||
List<UserScript>.from(webview.initialUserScripts ?? <UserScript>[]);
|
||||
|
||||
final initialUserScripts = webview.initialUserScripts;
|
||||
if (initialUserScripts != null) {
|
||||
for (final userScript in initialUserScripts) {
|
||||
if (userScript.injectionTime ==
|
||||
UserScriptInjectionTime.AT_DOCUMENT_START) {
|
||||
this
|
||||
._userScripts[UserScriptInjectionTime.AT_DOCUMENT_START]
|
||||
?.add(userScript);
|
||||
} else {
|
||||
this
|
||||
._userScripts[UserScriptInjectionTime.AT_DOCUMENT_END]
|
||||
?.add(userScript);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this._init();
|
||||
}
|
||||
|
||||
|
@ -99,8 +117,21 @@ class InAppWebViewController {
|
|||
UnmodifiableListView<UserScript>? initialUserScripts) {
|
||||
this._channel = channel;
|
||||
this._inAppBrowser = inAppBrowser;
|
||||
this._userScripts =
|
||||
List<UserScript>.from(initialUserScripts ?? <UserScript>[]);
|
||||
|
||||
if (initialUserScripts != null) {
|
||||
for (final userScript in initialUserScripts) {
|
||||
if (userScript.injectionTime ==
|
||||
UserScriptInjectionTime.AT_DOCUMENT_START) {
|
||||
this
|
||||
._userScripts[UserScriptInjectionTime.AT_DOCUMENT_START]
|
||||
?.add(userScript);
|
||||
} else {
|
||||
this
|
||||
._userScripts[UserScriptInjectionTime.AT_DOCUMENT_END]
|
||||
?.add(userScript);
|
||||
}
|
||||
}
|
||||
}
|
||||
this._init();
|
||||
}
|
||||
|
||||
|
@ -2793,8 +2824,9 @@ class InAppWebViewController {
|
|||
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent('userScript', () => userScript.toMap());
|
||||
if (!_userScripts.contains(userScript)) {
|
||||
_userScripts.add(userScript);
|
||||
if (!(_userScripts[userScript.injectionTime]?.contains(userScript) ??
|
||||
false)) {
|
||||
_userScripts[userScript.injectionTime]?.add(userScript);
|
||||
await _channel.invokeMethod('addUserScript', args);
|
||||
}
|
||||
}
|
||||
|
@ -2834,12 +2866,12 @@ class InAppWebViewController {
|
|||
assert(_webview?.windowId == null ||
|
||||
defaultTargetPlatform != TargetPlatform.iOS);
|
||||
|
||||
var index = _userScripts.indexOf(userScript);
|
||||
if (index == -1) {
|
||||
var index = _userScripts[userScript.injectionTime]?.indexOf(userScript);
|
||||
if (index == null || index == -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
_userScripts.remove(userScript);
|
||||
_userScripts[userScript.injectionTime]?.remove(userScript);
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent('userScript', () => userScript.toMap());
|
||||
args.putIfAbsent('index', () => index);
|
||||
|
@ -2863,6 +2895,22 @@ class InAppWebViewController {
|
|||
assert(_webview?.windowId == null ||
|
||||
defaultTargetPlatform != TargetPlatform.iOS);
|
||||
|
||||
final List<UserScript> userScriptsAtDocumentStart = List.from(
|
||||
_userScripts[UserScriptInjectionTime.AT_DOCUMENT_START] ?? []);
|
||||
for (final userScript in userScriptsAtDocumentStart) {
|
||||
if (userScript.groupName == groupName) {
|
||||
_userScripts[userScript.injectionTime]?.remove(userScript);
|
||||
}
|
||||
}
|
||||
|
||||
final List<UserScript> userScriptsAtDocumentEnd =
|
||||
List.from(_userScripts[UserScriptInjectionTime.AT_DOCUMENT_END] ?? []);
|
||||
for (final userScript in userScriptsAtDocumentEnd) {
|
||||
if (userScript.groupName == groupName) {
|
||||
_userScripts[userScript.injectionTime]?.remove(userScript);
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent('groupName', () => groupName);
|
||||
await _channel.invokeMethod('removeUserScriptsByGroupName', args);
|
||||
|
@ -2884,8 +2932,8 @@ class InAppWebViewController {
|
|||
assert(_webview?.windowId == null ||
|
||||
defaultTargetPlatform != TargetPlatform.iOS);
|
||||
|
||||
for (var i = 0; i < userScripts.length; i++) {
|
||||
await removeUserScript(userScript: userScripts[i]);
|
||||
for (final userScript in userScripts) {
|
||||
await removeUserScript(userScript: userScript);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2903,7 +2951,9 @@ class InAppWebViewController {
|
|||
assert(_webview?.windowId == null ||
|
||||
defaultTargetPlatform != TargetPlatform.iOS);
|
||||
|
||||
_userScripts.clear();
|
||||
_userScripts[UserScriptInjectionTime.AT_DOCUMENT_START]?.clear();
|
||||
_userScripts[UserScriptInjectionTime.AT_DOCUMENT_END]?.clear();
|
||||
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
await _channel.invokeMethod('removeAllUserScripts', args);
|
||||
}
|
||||
|
|
|
@ -1174,7 +1174,7 @@ class InAppWebViewSettings_ {
|
|||
///
|
||||
///**NOTE for iOS**: available on iOS 15.4+.
|
||||
///
|
||||
///**NOTE for MacOS**: available on MacOS 12.0+.
|
||||
///**NOTE for MacOS**: available on MacOS 12.3+.
|
||||
///
|
||||
///**Supported Platforms/Implementations**:
|
||||
///- iOS
|
||||
|
@ -1199,7 +1199,7 @@ class InAppWebViewSettings_ {
|
|||
///
|
||||
///**NOTE for iOS**: available on iOS 15.4+.
|
||||
///
|
||||
///**NOTE for MacOS**: available on MacOS 12.0+.
|
||||
///**NOTE for MacOS**: available on MacOS 12.3+.
|
||||
///
|
||||
///**Supported Platforms/Implementations**:
|
||||
///- iOS
|
||||
|
|
|
@ -1130,7 +1130,7 @@ class InAppWebViewSettings {
|
|||
///
|
||||
///**NOTE for iOS**: available on iOS 15.4+.
|
||||
///
|
||||
///**NOTE for MacOS**: available on MacOS 12.0+.
|
||||
///**NOTE for MacOS**: available on MacOS 12.3+.
|
||||
///
|
||||
///**Supported Platforms/Implementations**:
|
||||
///- iOS
|
||||
|
@ -1155,7 +1155,7 @@ class InAppWebViewSettings {
|
|||
///
|
||||
///**NOTE for iOS**: available on iOS 15.4+.
|
||||
///
|
||||
///**NOTE for MacOS**: available on MacOS 12.0+.
|
||||
///**NOTE for MacOS**: available on MacOS 12.3+.
|
||||
///
|
||||
///**Supported Platforms/Implementations**:
|
||||
///- iOS
|
||||
|
|
|
@ -27,7 +27,7 @@ class UserScript_ {
|
|||
///Specify true to inject the script only into the main frame, or false to inject it into all frames.
|
||||
///The default value is `true`.
|
||||
///
|
||||
///**NOTE**: available only on iOS.
|
||||
///**NOTE**: available only on iOS and MacOS.
|
||||
bool forMainFrameOnly;
|
||||
|
||||
///A set of matching rules for the allowed origins.
|
||||
|
|
|
@ -25,7 +25,7 @@ class UserScript {
|
|||
///Specify true to inject the script only into the main frame, or false to inject it into all frames.
|
||||
///The default value is `true`.
|
||||
///
|
||||
///**NOTE**: available only on iOS.
|
||||
///**NOTE**: available only on iOS and MacOS.
|
||||
bool forMainFrameOnly;
|
||||
|
||||
///A set of matching rules for the allowed origins.
|
||||
|
|
|
@ -175,7 +175,7 @@ public class InAppWebView: WKWebView, WKUIDelegate,
|
|||
configuration.preferences.isTextInteractionEnabled = settings.isTextInteractionEnabled
|
||||
}
|
||||
|
||||
if #available(macOS 12.0, *) {
|
||||
if #available(macOS 12.3, *) {
|
||||
configuration.preferences.isSiteSpecificQuirksModeEnabled = settings.isSiteSpecificQuirksModeEnabled
|
||||
configuration.preferences.isElementFullscreenEnabled = settings.isElementFullscreenEnabled
|
||||
}
|
||||
|
@ -725,7 +725,7 @@ public class InAppWebView: WKWebView, WKUIDelegate,
|
|||
self.underPageBackgroundColor = NSColor(hexString: underPageBackgroundColor)
|
||||
}
|
||||
}
|
||||
if #available(macOS 12.0, *) {
|
||||
if #available(macOS 12.3, *) {
|
||||
if newSettingsMap["isSiteSpecificQuirksModeEnabled"] != nil, settings?.isSiteSpecificQuirksModeEnabled != newSettings.isSiteSpecificQuirksModeEnabled {
|
||||
configuration.preferences.isSiteSpecificQuirksModeEnabled = newSettings.isSiteSpecificQuirksModeEnabled
|
||||
}
|
||||
|
|
|
@ -100,6 +100,8 @@ public class InAppWebViewSettings: ISettings<InAppWebView> {
|
|||
}
|
||||
if #available(macOS 12.0, *) {
|
||||
realSettings["underPageBackgroundColor"] = webView.underPageBackgroundColor.hexString
|
||||
}
|
||||
if #available(macOS 12.3, *) {
|
||||
realSettings["isSiteSpecificQuirksModeEnabled"] = configuration.preferences.isSiteSpecificQuirksModeEnabled
|
||||
realSettings["isElementFullscreenEnabled"] = configuration.preferences.isElementFullscreenEnabled
|
||||
}
|
||||
|
|
|
@ -595,7 +595,7 @@ public class WebViewChannelDelegate : ChannelDelegate {
|
|||
break
|
||||
case .isInFullscreen:
|
||||
if let webView = webView {
|
||||
if #available(macOS 12.0, *) {
|
||||
if #available(macOS 13.0, *) {
|
||||
result(webView.fullscreenState == .inFullscreen)
|
||||
} else {
|
||||
result(webView.inFullscreen)
|
||||
|
|
|
@ -276,7 +276,7 @@ extension WKUserContentController {
|
|||
|
||||
var userScriptsUpdated: [WKUserScript] = []
|
||||
for script in userScripts {
|
||||
if !userScripts.contains(script) {
|
||||
if !scriptsToRemove.contains(script) {
|
||||
userScriptsUpdated.append(script)
|
||||
}
|
||||
}
|
||||
|
@ -296,6 +296,7 @@ extension WKUserContentController {
|
|||
for script in allUserOnlyScripts {
|
||||
if let scriptName = script.groupName, scriptName == groupName {
|
||||
scriptsToRemove.append(script)
|
||||
userOnlyScripts[script.injectionTime]!.remove(script)
|
||||
}
|
||||
}
|
||||
removeUserScripts(scriptsToRemove: scriptsToRemove, shouldAddPreviousScripts: shouldAddPreviousScripts)
|
||||
|
@ -307,6 +308,7 @@ extension WKUserContentController {
|
|||
for script in allPluginScripts {
|
||||
if let scriptName = script.groupName, scriptName == groupName {
|
||||
scriptsToRemove.append(script)
|
||||
pluginScripts[script.injectionTime]!.remove(script)
|
||||
}
|
||||
}
|
||||
removeUserScripts(scriptsToRemove: scriptsToRemove, shouldAddPreviousScripts: shouldAddPreviousScripts)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
name: flutter_inappwebview
|
||||
description: A Flutter plugin that allows you to add an inline webview, to use an headless webview, and to open an in-app browser window.
|
||||
version: 6.0.0-beta.13
|
||||
version: 6.0.0-beta.14
|
||||
homepage: https://inappwebview.dev/
|
||||
repository: https://github.com/pichillilorenzo/flutter_inappwebview
|
||||
issue_tracker: https://github.com/pichillilorenzo/flutter_inappwebview/issues
|
||||
|
|
Loading…
Reference in New Issue