Added InAppBrowser.onMainWindowWillClose event, Added WindowType.WINDOW for InAppWebViewSettings.windowType, fix #1738, Fixed InAppWebViewController.callAsyncJavaScript Android-issue when the last line of the functionBody parameter includes a code comment

This commit is contained in:
Lorenzo Pichilli 2023-12-17 22:58:09 +01:00
parent 63c2f7f65c
commit 4c72bbfc0e
38 changed files with 137 additions and 51 deletions

View File

@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2022 Lorenzo Pichilli
Copyright 2023 Lorenzo Pichilli
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.

View File

@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2022 Lorenzo Pichilli
Copyright 2023 Lorenzo Pichilli
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.

View File

@ -1,3 +1,15 @@
## 6.0.0-rc.1
- Updated minimum platform interface and implementation versions
- Added `InAppBrowser.onMainWindowWillClose` event
- Added `WindowType.WINDOW` for `InAppWebViewSettings.windowType`
- Fixed "Cloudflare Turnstile failure" [#1738](https://github.com/pichillilorenzo/flutter_inappwebview/issues/1738)
- Fixed `InAppWebViewController.callAsyncJavaScript` Android-issue when the last line of the `functionBody` parameter includes a code comment
### BREAKING CHANGES
- Default value of `InAppWebViewSettings.windowType` is `WindowType.WINDOW`
## 6.0.0-beta.32
- Updated minimum platform interface and implementation versions
@ -17,7 +29,7 @@
- Fixed "onClosed not considering back navigation or up button / close button in ChromeSafariBrowser when using noHistory: true" [#1882](https://github.com/pichillilorenzo/flutter_inappwebview/issues/1882)
- Merged "Fixed error in InterceptAjaxRequestJS 'Failed to set responseType property'" [#1904](https://github.com/pichillilorenzo/flutter_inappwebview/pull/1904) (thanks to [EArminjon](https://github.com/EArminjon))
### BREAKING CHANGE
### BREAKING CHANGES
- Due to Flutter platform channels async nature, using `useShouldInterceptAjaxRequest: true` would break sync ajax requests, so that the `XMLHttpRequest.send()` will not wait for the response. To fix this issue, the default value of `InAppWebViewSettings.interceptOnlyAsyncAjaxRequests` is `true`. To intercept also sync ajax requests, this value should be `false`.

View File

@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2022 Lorenzo Pichilli
Copyright 2023 Lorenzo Pichilli
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.

View File

@ -26,7 +26,9 @@ void onReceivedIcon() {
pageLoaded.complete();
},
onReceivedIcon: (controller, icon) {
onReceivedIconCompleter.complete(icon);
if (!onReceivedIconCompleter.isCompleted) {
onReceivedIconCompleter.complete(icon);
}
},
),
),

View File

@ -61,6 +61,10 @@ class MyInAppBrowser extends InAppBrowser {
print("\n\nOverride ${navigationAction.request.url}\n\n");
return NavigationActionPolicy.ALLOW;
}
void onMainWindowWillClose() {
close();
}
}
class InAppBrowserExampleScreen extends StatefulWidget {

View File

@ -116,7 +116,7 @@ class _InAppWebViewExampleScreenState extends State<InAppWebViewExampleScreen> {
InAppWebView(
key: webViewKey,
initialUrlRequest:
URLRequest(url: WebUri('https://flutter.dev')),
URLRequest(url: WebUri('https://google.com')),
// initialUrlRequest:
// URLRequest(url: WebUri(Uri.base.toString().replaceFirst("/#/", "/") + 'page.html')),
// initialFile: "assets/index.html",

View File

@ -538,4 +538,7 @@ class InAppBrowser implements PlatformInAppBrowserEvents {
NavigationAction navigationAction) {
return null;
}
@override
void onMainWindowWillClose() {}
}

View File

@ -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.32
version: 6.0.0-rc.1
homepage: https://inappwebview.dev/
repository: https://github.com/pichillilorenzo/flutter_inappwebview
issue_tracker: https://github.com/pichillilorenzo/flutter_inappwebview/issues
@ -18,11 +18,11 @@ environment:
dependencies:
flutter:
sdk: flutter
flutter_inappwebview_platform_interface: ^1.0.6
flutter_inappwebview_android: ^1.0.8
flutter_inappwebview_ios: ^1.0.9
flutter_inappwebview_macos: ^1.0.7
flutter_inappwebview_web: ^1.0.4
flutter_inappwebview_platform_interface: ^1.0.7
flutter_inappwebview_android: ^1.0.9
flutter_inappwebview_ios: ^1.0.10
flutter_inappwebview_macos: ^1.0.8
flutter_inappwebview_web: ^1.0.5
dev_dependencies:
flutter_test:

View File

@ -1,3 +1,9 @@
## 1.0.9
- Updated `flutter_inappwebview_platform_interface` version dependency to `^1.0.7`
- Fixed "Cloudflare Turnstile failure" [#1738](https://github.com/pichillilorenzo/flutter_inappwebview/issues/1738)
- Fixed `InAppWebViewController.callAsyncJavaScript` issue when the last line of the `functionBody` parameter includes a code comment
## 1.0.8
- Implemented `InAppWebViewSettings.interceptOnlyAsyncAjaxRequests`

View File

@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2022 Lorenzo Pichilli
Copyright 2023 Lorenzo Pichilli
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.

View File

@ -15,6 +15,15 @@ public class ConsoleLogJS {
);
public static final String CONSOLE_LOG_JS_SOURCE = "(function(console) {" +
" function _buildMessage(args) {" +
" var message = '';" +
" for (var i in args) {" +
" try {" +
" message += message === '' ? args[i] : ' ' + args[i];" +
" } catch(ignored) {}" +
" }" +
" return message;" +
" }" +
" var oldLogs = {" +
" 'log': console.log," +
" 'debug': console.debug," +
@ -25,16 +34,7 @@ public class ConsoleLogJS {
" for (var k in oldLogs) {" +
" (function(oldLog) {" +
" console[oldLog] = function() {" +
" var message = '';" +
" for (var i in arguments) {" +
" if (message == '') {" +
" message += arguments[i];" +
" }" +
" else {" +
" message += ' ' + arguments[i];" +
" }" +
" }" +
" oldLogs[oldLog].call(console, message);" +
" oldLogs[oldLog].call(console, _buildMessage(arguments));" +
" }" +
" })(k);" +
" }" +

View File

@ -18,7 +18,7 @@ public class PluginScriptsUtil {
public static final String CALL_ASYNC_JAVA_SCRIPT_WRAPPER_JS_SOURCE = "(function(obj) {" +
" (async function(" + VAR_FUNCTION_ARGUMENT_NAMES + ") {" +
" " + VAR_FUNCTION_BODY +
" \n" + VAR_FUNCTION_BODY + "\n" +
" })(" + VAR_FUNCTION_ARGUMENT_VALUES + ").then(function(value) {" +
" window." + JavaScriptBridgeJS.JAVASCRIPT_BRIDGE_NAME + ".callHandler('callAsyncJavaScript', {'value': value, 'error': null, 'resultUuid': '" + VAR_RESULT_UUID + "'});" +
" }).catch(function(error) {" +

View File

@ -1,6 +1,6 @@
name: flutter_inappwebview_android
description: Android implementation of the flutter_inappwebview plugin.
version: 1.0.8
version: 1.0.9
homepage: https://inappwebview.dev/
repository: https://github.com/pichillilorenzo/flutter_inappwebview/tree/master/flutter_inappwebview_android
issue_tracker: https://github.com/pichillilorenzo/flutter_inappwebview/issues
@ -18,7 +18,7 @@ environment:
dependencies:
flutter:
sdk: flutter
flutter_inappwebview_platform_interface: ^1.0.6
flutter_inappwebview_platform_interface: ^1.0.7
dev_dependencies:
flutter_test:

View File

@ -1,3 +1,7 @@
## 1.0.10
- Updated `flutter_inappwebview_platform_interface` version dependency to `^1.0.7`
## 1.0.9
- Implemented `InAppWebViewSettings.interceptOnlyAsyncAjaxRequests`

View File

@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2022 Lorenzo Pichilli
Copyright 2023 Lorenzo Pichilli
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.

View File

@ -1,6 +1,6 @@
name: flutter_inappwebview_ios
description: iOS implementation of the flutter_inappwebview plugin.
version: 1.0.9
version: 1.0.10
homepage: https://inappwebview.dev/
repository: https://github.com/pichillilorenzo/flutter_inappwebview/tree/master/flutter_inappwebview_ios
issue_tracker: https://github.com/pichillilorenzo/flutter_inappwebview/issues
@ -18,7 +18,7 @@ environment:
dependencies:
flutter:
sdk: flutter
flutter_inappwebview_platform_interface: ^1.0.6
flutter_inappwebview_platform_interface: ^1.0.7
dev_dependencies:
flutter_test:

View File

@ -1,3 +1,8 @@
## 1.0.8
- Updated `flutter_inappwebview_platform_interface` version dependency to `^1.0.7`
- Implemented `InAppBrowser.onMainWindowWillClose` event
## 1.0.7
- Implemented `InAppWebViewSettings.interceptOnlyAsyncAjaxRequests`
@ -29,7 +34,7 @@
## 1.0.1
- Added `PlatformPrintJobController.onComplete` setter
- Updated `flutter_inappwebview_platform_interface` version dependency to `1.0.2`
- Updated `flutter_inappwebview_platform_interface` version dependency to `^1.0.2`
## 1.0.0

View File

@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2022 Lorenzo Pichilli
Copyright 2023 Lorenzo Pichilli
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.

View File

@ -122,6 +122,10 @@ class MacOSInAppBrowser extends PlatformInAppBrowser with ChannelController {
}
}
break;
case "onMainWindowWillClose":
_debugLog(call.method, call.arguments);
eventHandler?.onMainWindowWillClose();
break;
case "onExit":
_debugLog(call.method, call.arguments);
_isOpened = false;

View File

@ -25,6 +25,11 @@ public class InAppBrowserChannelDelegate : ChannelDelegate {
channel?.invokeMethod("onMenuItemClicked", arguments: arguments)
}
public func onMainWindowWillClose() {
let arguments: [String: Any?] = [:]
channel?.invokeMethod("onMainWindowWillClose", arguments: arguments)
}
public func onExit() {
let arguments: [String: Any?] = [:]
channel?.invokeMethod("onExit", arguments: arguments)

View File

@ -86,8 +86,10 @@ public class InAppBrowserManager: ChannelDelegate {
if #available(macOS 10.12, *), browserSettings.windowType == .tabbed {
NSApplication.shared.mainWindow?.addTabbedWindow(window, ordered: .above)
} else {
} else if browserSettings.windowType == .child {
NSApplication.shared.mainWindow?.addChildWindow(window, ordered: .above)
} else {
window.windowController?.showWindow(self)
}
if browserSettings.hidden {

View File

@ -16,7 +16,7 @@ public class InAppBrowserSettings: ISettings<InAppBrowserWebViewController> {
var hideUrlBar = false
var hideProgressBar = false
var toolbarTopFixedTitle: String?
var windowType = InAppBrowserWindowType.child
var windowType = InAppBrowserWindowType.window
var windowAlphaValue = 1.0
var _windowStyleMask: NSNumber?
var windowStyleMask: NSWindow.StyleMask? {

View File

@ -62,7 +62,7 @@ public class InAppBrowserWindow : NSWindow, NSWindowDelegate, NSToolbarDelegate,
delegate = self
NotificationCenter.default.addObserver(self,
selector: #selector(onMainWindowClose(_:)),
selector: #selector(onMainWindowWillClose(_:)),
name: NSWindow.willCloseNotification,
object: NSApplication.shared.mainWindow)
@ -348,13 +348,17 @@ public class InAppBrowserWindow : NSWindow, NSWindowDelegate, NSToolbarDelegate,
dispose()
}
@objc func onMainWindowClose(_ notification: Notification) {
close()
@objc func onMainWindowWillClose(_ notification: Notification) {
if let webViewController = contentViewController as? InAppBrowserWebViewController {
webViewController.channelDelegate?.onMainWindowWillClose()
}
}
public func dispose() {
delegate = nil
NotificationCenter.default.removeObserver(self,
name: NSWindow.willCloseNotification,
object: NSApplication.shared.mainWindow)
if let webViewController = contentViewController as? InAppBrowserWebViewController {
webViewController.dispose()
}

View File

@ -8,6 +8,7 @@
import Foundation
public enum InAppBrowserWindowType: String {
case window = "WINDOW"
case child = "CHILD"
case tabbed = "TABBED"
}

View File

@ -1,6 +1,6 @@
name: flutter_inappwebview_macos
description: macOS implementation of the flutter_inappwebview plugin.
version: 1.0.7
version: 1.0.8
homepage: https://inappwebview.dev/
repository: https://github.com/pichillilorenzo/flutter_inappwebview/tree/master/flutter_inappwebview_macos
issue_tracker: https://github.com/pichillilorenzo/flutter_inappwebview/issues
@ -18,7 +18,7 @@ environment:
dependencies:
flutter:
sdk: flutter
flutter_inappwebview_platform_interface: ^1.0.6
flutter_inappwebview_platform_interface: ^1.0.7
dev_dependencies:
flutter_test:

View File

@ -1,3 +1,8 @@
## 1.0.7
- Added `InAppBrowser.onMainWindowWillClose` event
- Added `WindowType.WINDOW` for `InAppWebViewSettings.windowType`
## 1.0.6
- Added `InAppWebViewSettings.interceptOnlyAsyncAjaxRequests` [#1905](https://github.com/pichillilorenzo/flutter_inappwebview/issues/1905)

View File

@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2022 Lorenzo Pichilli
Copyright 2023 Lorenzo Pichilli
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.

View File

@ -254,7 +254,7 @@ class InAppBrowserSettings_
ModalTransitionStyle_? transitionStyle;
///How the browser window should be added to the main window.
///The default value is [WindowType.CHILD].
///The default value is [WindowType.WINDOW].
///
///**Officially Supported Platforms/Implementations**:
///- MacOS

View File

@ -195,7 +195,7 @@ class InAppBrowserSettings
WindowTitlebarSeparatorStyle? windowTitlebarSeparatorStyle;
///How the browser window should be added to the main window.
///The default value is [WindowType.CHILD].
///The default value is [WindowType.WINDOW].
///
///**Officially Supported Platforms/Implementations**:
///- MacOS

View File

@ -497,6 +497,12 @@ abstract class PlatformInAppBrowserEvents {
///- MacOS
void onExit() {}
///Event fired when the main window is about to close.
///
///**Officially Supported Platforms/Implementations**:
///- MacOS
void onMainWindowWillClose() {}
///Event fired when the [PlatformInAppBrowser] starts to load an [url].
///
///**Officially Supported Platforms/Implementations**:

View File

@ -74,7 +74,7 @@ class DefaultInAppLocalhostServer extends PlatformInAppLocalhostServer {
}
this._started = true;
var completer = Completer();
final completer = Completer();
runZonedGuarded(() {
HttpServer.bind('127.0.0.1', _port, shared: _shared).then((server) {
@ -108,7 +108,7 @@ class DefaultInAppLocalhostServer extends PlatformInAppLocalhostServer {
var contentType = ContentType('text', 'html', charset: 'utf-8');
if (!request.requestedUri.path.endsWith('/') &&
request.requestedUri.pathSegments.isNotEmpty) {
var mimeType = MimeTypeResolver.lookup(request.requestedUri.path);
final mimeType = MimeTypeResolver.lookup(request.requestedUri.path);
if (mimeType != null) {
contentType = _getContentTypeFromMimeType(mimeType);
}

View File

@ -11,6 +11,10 @@ class WindowType_ {
const WindowType_._internal(this._value);
///Adds the new browser window as a separate new window from the main window.
@EnumSupportedPlatforms(platforms: [EnumMacOSPlatform(value: 'WINDOW')])
static const WINDOW = const WindowType_._internal('WINDOW');
///Adds the new browser window as a child window of the main window.
@EnumSupportedPlatforms(platforms: [EnumMacOSPlatform(value: 'CHILD')])
static const CHILD = const WindowType_._internal('CHILD');

View File

@ -44,10 +44,25 @@ class WindowType {
return null;
});
///Adds the new browser window as a separate new window from the main window.
///
///**Officially Supported Platforms/Implementations**:
///- MacOS
static final WINDOW = WindowType._internalMultiPlatform('WINDOW', () {
switch (defaultTargetPlatform) {
case TargetPlatform.macOS:
return 'WINDOW';
default:
break;
}
return null;
});
///Set of all values of [WindowType].
static final Set<WindowType> values = [
WindowType.CHILD,
WindowType.TABBED,
WindowType.WINDOW,
].toSet();
///Gets a possible [WindowType] instance from [String] value.

View File

@ -1,6 +1,6 @@
name: flutter_inappwebview_platform_interface
description: A common platform interface for the flutter_inappwebview plugin.
version: 1.0.6
version: 1.0.7
homepage: https://inappwebview.dev/
repository: https://github.com/pichillilorenzo/flutter_inappwebview/tree/master/flutter_inappwebview_platform_interface
issue_tracker: https://github.com/pichillilorenzo/flutter_inappwebview/issues

View File

@ -1,6 +1,10 @@
## 1.0.5
- Updated `flutter_inappwebview_platform_interface` version dependency to `^1.0.7`
## 1.0.4
- Updated `flutter_inappwebview_platform_interface` version dependency to `1.0.6`
- Updated `flutter_inappwebview_platform_interface` version dependency to `^1.0.6`
- Updated `CookieManager` methods return value
## 1.0.3
@ -10,11 +14,11 @@
## 1.0.2
- Updated `flutter_inappwebview_platform_interface` version dependency to `1.0.5`
- Updated `flutter_inappwebview_platform_interface` version dependency to `^1.0.5`
## 1.0.1
- Updated `flutter_inappwebview_platform_interface` version dependency to `1.0.2`
- Updated `flutter_inappwebview_platform_interface` version dependency to `^1.0.2`
## 1.0.0

View File

@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2022 Lorenzo Pichilli
Copyright 2023 Lorenzo Pichilli
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.

View File

@ -1,6 +1,6 @@
name: flutter_inappwebview_web
description: Web implementation of the flutter_inappwebview plugin.
version: 1.0.4
version: 1.0.5
homepage: https://inappwebview.dev/
repository: https://github.com/pichillilorenzo/flutter_inappwebview/tree/master/flutter_inappwebview_web
issue_tracker: https://github.com/pichillilorenzo/flutter_inappwebview/issues
@ -21,7 +21,7 @@ dependencies:
flutter_web_plugins:
sdk: flutter
js: ^0.6.4
flutter_inappwebview_platform_interface: ^1.0.6
flutter_inappwebview_platform_interface: ^1.0.7
dev_dependencies:
flutter_test: