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