Skip to content

Commit

Permalink
Added InAppBrowser.onMainWindowWillClose event, Added WindowType.WIND…
Browse files Browse the repository at this point in the history
…OW for InAppWebViewSettings.windowType, fix #1738, Fixed InAppWebViewController.callAsyncJavaScript Android-issue when the last line of the functionBody parameter includes a code comment
  • Loading branch information
pichillilorenzo committed Dec 17, 2023
1 parent 63c2f7f commit 4c72bbf
Show file tree
Hide file tree
Showing 38 changed files with 137 additions and 51 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 13 additions & 1 deletion flutter_inappwebview/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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`.

Expand Down
2 changes: 1 addition & 1 deletion flutter_inappwebview/LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ void onReceivedIcon() {
pageLoaded.complete();
},
onReceivedIcon: (controller, icon) {
onReceivedIconCompleter.complete(icon);
if (!onReceivedIconCompleter.isCompleted) {
onReceivedIconCompleter.complete(icon);
}
},
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,4 +538,7 @@ class InAppBrowser implements PlatformInAppBrowserEvents {
NavigationAction navigationAction) {
return null;
}

@override
void onMainWindowWillClose() {}
}
12 changes: 6 additions & 6 deletions flutter_inappwebview/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions flutter_inappwebview_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
2 changes: 1 addition & 1 deletion flutter_inappwebview_android/LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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," +
Expand All @@ -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);" +
" }" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {" +
Expand Down
4 changes: 2 additions & 2 deletions flutter_inappwebview_android/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions flutter_inappwebview_ios/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.0.10

- Updated `flutter_inappwebview_platform_interface` version dependency to `^1.0.7`

## 1.0.9

- Implemented `InAppWebViewSettings.interceptOnlyAsyncAjaxRequests`
Expand Down
2 changes: 1 addition & 1 deletion flutter_inappwebview_ios/LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions flutter_inappwebview_ios/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand Down
7 changes: 6 additions & 1 deletion flutter_inappwebview_macos/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion flutter_inappwebview_macos/LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import Foundation

public enum InAppBrowserWindowType: String {
case window = "WINDOW"
case child = "CHILD"
case tabbed = "TABBED"
}
4 changes: 2 additions & 2 deletions flutter_inappwebview_macos/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions flutter_inappwebview_platform_interface/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion flutter_inappwebview_platform_interface/LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4c72bbf

Please sign in to comment.