Skip to content
This repository was archived by the owner on Feb 23, 2023. It is now read-only.

Commit 25c13ae

Browse files
authored
Merge pull request #13 from plgd-dev/support-bundle
support bundle image
2 parents ea3d7ef + 29feca3 commit 25c13ae

25 files changed

Lines changed: 121 additions & 68 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ unlinked_spec.ds
9292
**/ios/Flutter/flutter_export_environment.sh
9393
**/ios/ServiceDefinitions.json
9494
**/ios/Runner/GeneratedPluginRegistrant.*
95+
**/ios/Flutter/.last_build_id
9596

9697
# macOS
9798
**/macos/Flutter/GeneratedPluginRegistrant.swift

android/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ android {
4444

4545
defaultConfig {
4646
applicationId "dev.plgd.client"
47-
minSdkVersion 16
47+
minSdkVersion 17
4848
targetSdkVersion 29
4949
versionCode flutterVersionCode.toInteger()
5050
versionName flutterVersionName

android/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@
2121
android:value="2" />
2222
</application>
2323
<uses-permission android:name="android.permission.INTERNET"/>
24+
<uses-permission android:name="android.permission.WAKE_LOCK"/>
2425
</manifest>

android/app/src/main/kotlin/dev/plgd/mobile/MainActivity.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ class MainActivity: FlutterActivity() {
3232
}
3333

3434
private fun initializeOCFClient(call: MethodCall, result: MethodChannel.Result) {
35-
if (sdkClient != null) {
36-
result.success(true)
37-
return
38-
}
39-
4035
var accessToken = call.argument<String>("accessToken");
4136
var cloudConfiguration = call.argument<String>("cloudConfiguration")
4237
_mainScope.launch {

ios/Flutter/.last_build_id

Lines changed: 0 additions & 1 deletion
This file was deleted.

ios/Runner.xcodeproj/project.pbxproj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,16 @@
219219
inputPaths = (
220220
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
221221
"${PODS_ROOT}/../Flutter/Flutter.framework",
222+
"${BUILT_PRODUCTS_DIR}/flutter_inappwebview/flutter_inappwebview.framework",
223+
"${BUILT_PRODUCTS_DIR}/package_info/package_info.framework",
222224
"${BUILT_PRODUCTS_DIR}/shared_preferences/shared_preferences.framework",
223-
"${BUILT_PRODUCTS_DIR}/webview_flutter/webview_flutter.framework",
224225
);
225226
name = "[CP] Embed Pods Frameworks";
226227
outputPaths = (
227228
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Flutter.framework",
229+
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/flutter_inappwebview.framework",
230+
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/package_info.framework",
228231
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/shared_preferences.framework",
229-
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/webview_flutter.framework",
230232
);
231233
runOnlyForDeploymentPostprocessing = 0;
232234
shellPath = /bin/sh;

ios/Runner/AppDelegate.swift

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,13 @@ import Ocfclient
2828
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
2929
}
3030

31-
let ocfClient = OcfclientOcfclient();
32-
var isInitialized = false;
31+
var ocfClient: OcfclientOcfclient!;
3332

3433
private func initializeOCFClient(args: Any?, result: FlutterResult) {
35-
if (isInitialized) {
36-
result(true)
37-
return
38-
}
39-
34+
ocfClient = OcfclientOcfclient();
4035
let args = args as! [String: String]
4136
do {
4237
try ocfClient.initialize(args["accessToken"], cloudConfiguration: args["cloudConfiguration"])
43-
isInitialized = true
4438
} catch {
4539
result(FlutterError(code: "-1", message: error.localizedDescription, details: nil))
4640
}

lib/appLocalizations.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ class AppLocalizations {
4949
return Intl.message('An error occurred during plgd client initialization.', name: 'unableToInitializeClientNotification');
5050
}
5151

52+
String get unableToAuthenticateNotification {
53+
return Intl.message('An error occurred during authentication.', name: 'unableToAuthenticateNotification');
54+
}
55+
5256
String get requestApplicationSetupNotification {
5357
return Intl.message('Please setup your application again.', name: 'requestApplicationSetupNotification');
5458
}

lib/components/deviceDetails.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class _DeviceDetailsWidgetState extends State<DeviceDetails> {
4444
padding: EdgeInsets.only(bottom: 10, left: 15, right: 15),
4545
child: _getActionButton(this.widget.device)
4646
),
47-
OCFClient.getCodeRequestWidget(context, false, _tryGetCodeInBackground, (response) => _onboard(response, context), _cancelOnboarding)
47+
OCFClient.getCodeRequestWidget(context, false, _tryGetCodeInBackground, (response) => _onboard(response, context), _cancelOnboarding, _onHttpError)
4848
]
4949
)
5050
)
@@ -140,6 +140,11 @@ class _DeviceDetailsWidgetState extends State<DeviceDetails> {
140140
Navigator.of(context).pop(true);
141141
}
142142
}
143+
144+
void _onHttpError() {
145+
_cancelOnboarding();
146+
ToastNotification.show(context, AppLocalizations.of(context).unableToAuthenticateNotification);
147+
}
143148

144149
void _cancelOnboarding() {
145150
setState(() {

lib/components/oauthHandler.dart

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,34 @@
11
import 'package:client/appConstants.dart';
2+
import 'package:client/appLocalizations.dart';
3+
import 'package:client/components/toastNotification.dart';
24
import 'package:flutter/foundation.dart';
35
import 'package:flutter/gestures.dart';
46
import 'package:flutter/material.dart';
57
import 'package:flutter_spinkit/flutter_spinkit.dart';
6-
import 'package:webview_flutter/webview_flutter.dart';
8+
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
79

810
class OAuthHandler extends StatefulWidget {
911
final String authUrl;
1012
final Function promptForCredentials;
1113
final Function(String) authCompleted;
14+
final Function errorOccured;
1215

13-
OAuthHandler({Key key, this.authUrl, this.promptForCredentials, this.authCompleted}) : super(key: key);
16+
OAuthHandler({Key key, this.authUrl, this.promptForCredentials, this.authCompleted, this.errorOccured}) : super(key: key);
1417

1518
@override
16-
_OAuthHandlerState createState() => new _OAuthHandlerState(authUrl, promptForCredentials, authCompleted);
19+
_OAuthHandlerState createState() => new _OAuthHandlerState(authUrl, promptForCredentials, authCompleted, errorOccured);
1720
}
1821

1922
class _OAuthHandlerState extends State<OAuthHandler> {
2023
final String authUrl;
2124
final Function promptForCredentials;
2225
final Function(String) authCompleted;
26+
final Function errorOccured;
2327
String authOrigin;
24-
WebViewController _controller;
28+
InAppWebViewController _controller;
2529
bool _loadingInProgress = false;
2630

27-
_OAuthHandlerState(this.authUrl, this.promptForCredentials, this.authCompleted);
31+
_OAuthHandlerState(this.authUrl, this.promptForCredentials, this.authCompleted, this.errorOccured);
2832

2933
@override
3034
initState() {
@@ -46,25 +50,37 @@ class _OAuthHandlerState extends State<OAuthHandler> {
4650
Visibility(
4751
visible: !_loadingInProgress,
4852
maintainState: true,
49-
child: WebView(
53+
child: InAppWebView(
5054
initialUrl: authUrl,
51-
userAgent: "Mozilla/5.0 Google",
55+
initialOptions: InAppWebViewGroupOptions(
56+
crossPlatform: InAppWebViewOptions(
57+
userAgent: 'Mozilla/5.0 Google'
58+
)
59+
),
5260
gestureRecognizers: Set()
5361
..add(Factory<VerticalDragGestureRecognizer>(
5462
() => VerticalDragGestureRecognizer()
5563
)
5664
),
57-
javascriptMode: JavascriptMode.unrestricted,
58-
onWebViewCreated: (WebViewController webViewController) {
59-
_controller = webViewController;
65+
onWebViewCreated: (InAppWebViewController controller) {
66+
_controller = controller;
67+
_controller.addJavaScriptHandler(handlerName:'handleOAuthResponse', callback: (args) {
68+
authCompleted(args[0]);
69+
});
70+
71+
},
72+
onLoadError: (InAppWebViewController controller, String url, int code, String message) async {
73+
errorOccured();
74+
return;
6075
},
61-
javascriptChannels: <JavascriptChannel>[
62-
_extractData(context),
63-
].toSet(),
64-
onPageFinished: (String url) {
76+
onLoadHttpError: (InAppWebViewController controller, String url, int statusCode, String description) async {
77+
errorOccured();
78+
return;
79+
},
80+
onLoadStop: (InAppWebViewController controller, String url) async {
6581
// in case redirect url is requested, expected content will be already present
6682
if (url.startsWith(authOrigin)) {
67-
_controller.evaluateJavascript("(function(){OAuth.postMessage(document.documentElement.innerText)})();");
83+
_controller.evaluateJavascript(source: "(function(){window.flutter_inappwebview.callHandler('handleOAuthResponse', document.documentElement.innerText)})();");
6884
return;
6985
}
7086

@@ -75,22 +91,18 @@ class _OAuthHandlerState extends State<OAuthHandler> {
7591
return;
7692
}
7793
},
78-
onPageStarted: (_) => { setState(() { _loadingInProgress = true; }) },
79-
gestureNavigationEnabled: true,
94+
onLoadStart: (InAppWebViewController controller, String url) {
95+
if (url.startsWith(authOrigin))
96+
setState(() { _loadingInProgress = true; });
97+
},
98+
onReceivedServerTrustAuthRequest: (InAppWebViewController controller, ServerTrustChallenge challenge) async {
99+
return ServerTrustAuthResponse(action: ServerTrustAuthResponseAction.PROCEED);
100+
}
80101
)
81102
)
82103
]
83104
);
84105
}
85106
);
86107
}
87-
88-
JavascriptChannel _extractData(BuildContext context) {
89-
return JavascriptChannel(
90-
name: 'OAuth',
91-
onMessageReceived: (JavascriptMessage message) {
92-
authCompleted(message.message);
93-
},
94-
);
95-
}
96108
}

0 commit comments

Comments
 (0)