Skip to content

Commit 085931c

Browse files
committed
Release build working but only without flutter_inappwebview dependency
1 parent 8566f7a commit 085931c

File tree

6 files changed

+143
-141
lines changed

6 files changed

+143
-141
lines changed

android/app/build.gradle

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,15 @@ android {
6060

6161
buildTypes {
6262
release {
63+
// shrinkResources false
64+
// minifyEnabled false
65+
6366
signingConfig signingConfigs.debug
67+
68+
6469
// signingConfig signingConfigs.release
6570
}
6671
}
67-
namespace 'is.mideind.embla'
6872
}
6973

7074
flutter {

lib/jsexec.dart

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -19,52 +19,52 @@
1919
// Singleton wrapper class around a headless web view
2020
// used to execute JS code payload from the server.
2121

22-
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
22+
// import 'package:flutter_inappwebview/flutter_inappwebview.dart';
2323

24-
import './common.dart';
24+
// import './common.dart';
2525

26-
const kJSExecErrorMessage = "Villa kom upp við keyrslu á JavaScript kóða.";
27-
const kJSExecDefaultWebViewURL = "about:blank";
26+
// const kJSExecErrorMessage = "Villa kom upp við keyrslu á JavaScript kóða.";
27+
// const kJSExecDefaultWebViewURL = "about:blank";
2828

29-
/// Wrapper class to execute JavaScript code in a headless web view.
30-
class JSExecutor {
31-
static final JSExecutor _instance = JSExecutor._constructor();
32-
static late HeadlessInAppWebView headlessWebView;
29+
// /// Wrapper class to execute JavaScript code in a headless web view.
30+
// class JSExecutor {
31+
// static final JSExecutor _instance = JSExecutor._constructor();
32+
// static late HeadlessInAppWebView headlessWebView;
3333

34-
// Singleton pattern
35-
factory JSExecutor() {
36-
return _instance;
37-
}
34+
// // Singleton pattern
35+
// factory JSExecutor() {
36+
// return _instance;
37+
// }
3838

39-
// Constructor, only called once, when singleton is instantiated
40-
JSExecutor._constructor() {
41-
headlessWebView = HeadlessInAppWebView(
42-
initialUrlRequest: URLRequest(url: Uri.parse(kJSExecDefaultWebViewURL)),
43-
initialOptions: InAppWebViewGroupOptions(
44-
crossPlatform: InAppWebViewOptions(),
45-
),
46-
onWebViewCreated: (controller) {},
47-
onConsoleMessage: (controller, consoleMessage) {
48-
dlog("JavaScript Console Message: ${consoleMessage.message}");
49-
},
50-
);
51-
}
39+
// // Constructor, only called once, when singleton is instantiated
40+
// JSExecutor._constructor() {
41+
// headlessWebView = HeadlessInAppWebView(
42+
// initialUrlRequest: URLRequest(url: Uri.parse(kJSExecDefaultWebViewURL)),
43+
// initialOptions: InAppWebViewGroupOptions(
44+
// crossPlatform: InAppWebViewOptions(),
45+
// ),
46+
// onWebViewCreated: (controller) {},
47+
// onConsoleMessage: (controller, consoleMessage) {
48+
// dlog("JavaScript Console Message: ${consoleMessage.message}");
49+
// },
50+
// );
51+
// }
5252

53-
/// Run JavaScript code in a headless web view. Return async eval result as string.
54-
Future<String> run(String jsCode) async {
55-
await headlessWebView.dispose();
56-
await headlessWebView.run();
57-
try {
58-
final CallAsyncJavaScriptResult? result =
59-
await headlessWebView.webViewController.callAsyncJavaScript(functionBody: jsCode);
60-
if (result != null && result.error == null && result.value != null) {
61-
return result.value.toString();
62-
} else {
63-
dlog("Error running JavaScript in HeadlessInAppWebView: ${result?.error}");
64-
}
65-
} on Exception catch (e) {
66-
dlog("Error running JavaScript in HeadlessInAppWebView: $e");
67-
}
68-
return kJSExecErrorMessage;
69-
}
70-
}
53+
// /// Run JavaScript code in a headless web view. Return async eval result as string.
54+
// Future<String> run(String jsCode) async {
55+
// await headlessWebView.dispose();
56+
// await headlessWebView.run();
57+
// try {
58+
// final CallAsyncJavaScriptResult? result =
59+
// await headlessWebView.webViewController.callAsyncJavaScript(functionBody: jsCode);
60+
// if (result != null && result.error == null && result.value != null) {
61+
// return result.value.toString();
62+
// } else {
63+
// dlog("Error running JavaScript in HeadlessInAppWebView: ${result?.error}");
64+
// }
65+
// } on Exception catch (e) {
66+
// dlog("Error running JavaScript in HeadlessInAppWebView: $e");
67+
// }
68+
// return kJSExecErrorMessage;
69+
// }
70+
// }

lib/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ void main() async {
8585

8686
// Init/preload these to prevent any lag after launching app
8787
await preloadAnimationFrames();
88-
await preloadHTMLDocuments();
88+
//await preloadHTMLDocuments();
8989
await EmblaSession.prepare();
9090

9191
// Initialize singleton, loading hotword-related assets into memory

lib/session.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import './common.dart';
4040
import './hotword.dart' show HotwordDetector;
4141
import './menu.dart' show MenuRoute;
4242
import './prefs.dart' show Prefs;
43-
import './jsexec.dart' show JSExecutor;
43+
// import './jsexec.dart' show JSExecutor;
4444
import './theme.dart';
4545
import './button.dart';
4646
import './loc.dart' show LocationTracker;
@@ -367,7 +367,7 @@ class SessionRouteState extends State<SessionRoute> with SingleTickerProviderSta
367367
// Execute Javascript payload
368368
else if (resp['command'] != null && resp['command'] != '') {
369369
// Evaluate JS
370-
String s = await JSExecutor().run(resp['command']);
370+
String s = ""; //await JSExecutor().run(resp['command']);
371371
msg(s);
372372
// Request speech synthesis of result, play audio and terminate session
373373
// TODO: The API URL should really be handled by EmblaCore

lib/web.dart

Lines changed: 91 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import 'package:flutter/foundation.dart';
2222
import 'package:flutter/material.dart';
2323
import 'package:flutter/services.dart' show rootBundle;
2424

25-
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
25+
// import 'package:flutter_inappwebview/flutter_inappwebview.dart';
2626
import 'package:url_launcher/url_launcher.dart' show launchUrl, LaunchMode;
2727

2828
import './theme.dart' show standardAppBar;
@@ -32,20 +32,20 @@ const String kDocsDir = 'docs';
3232
const String kLoadingHTMLFilePath = "$kDocsDir/loading.html";
3333
const String kLoadingDarkHTMLFilePath = "$kDocsDir/loading_dark.html";
3434

35-
late InAppWebViewInitialData loadingHTMLData;
36-
late InAppWebViewInitialData loadingDarkHTMLData;
37-
38-
/// Preloads the "loading" HTML documents to prevent any initial
39-
/// lag when showing loading indicator for documentation pages.
40-
Future<void> preloadHTMLDocuments() async {
41-
dlog("Preloading HTML loading documents");
42-
loadingHTMLData =
43-
InAppWebViewInitialData(data: await rootBundle.loadString(kLoadingHTMLFilePath));
44-
loadingHTMLData.baseUrl = Uri.parse("file:///");
45-
loadingDarkHTMLData =
46-
InAppWebViewInitialData(data: await rootBundle.loadString(kLoadingDarkHTMLFilePath));
47-
loadingDarkHTMLData.baseUrl = Uri.parse("file:///");
48-
}
35+
// late InAppWebViewInitialData loadingHTMLData;
36+
// late InAppWebViewInitialData loadingDarkHTMLData;
37+
38+
// /// Preloads the "loading" HTML documents to prevent any initial
39+
// /// lag when showing loading indicator for documentation pages.
40+
// Future<void> preloadHTMLDocuments() async {
41+
// dlog("Preloading HTML loading documents");
42+
// loadingHTMLData =
43+
// InAppWebViewInitialData(data: await rootBundle.loadString(kLoadingHTMLFilePath));
44+
// loadingHTMLData.baseUrl = Uri.parse("file:///");
45+
// loadingDarkHTMLData =
46+
// InAppWebViewInitialData(data: await rootBundle.loadString(kLoadingDarkHTMLFilePath));
47+
// loadingDarkHTMLData.baseUrl = Uri.parse("file:///");
48+
// }
4949

5050
/// Standard web view route used for displaying HTML documentation files.
5151
class WebViewRoute extends StatefulWidget {
@@ -70,86 +70,84 @@ class WebViewRouteState extends State<WebViewRoute> {
7070
return "$url?dark=1";
7171
}
7272

73-
/// Fall back to local HTML document if error comes
74-
/// up when fetching document from remote server.
75-
void errHandler(InAppWebViewController controller, Uri? url, int errCode, String desc) async {
76-
dlog("Page load error for $url: $errCode, $desc");
77-
final String path = _fallbackAssetForURL(url.toString());
78-
dlog("Falling back to local asset $path");
79-
setState(() {
80-
controller.loadFile(assetFilePath: path);
81-
});
82-
}
83-
84-
/// Handle clicks on links in HTML documentation.
85-
/// These links should be opened in an external browser to
86-
/// avoid screwing with the navigation stack of the app.
87-
Future<NavigationActionPolicy> urlClickHandler(
88-
InAppWebViewController controller, NavigationAction action) async {
89-
final URLRequest req = action.request;
90-
final String urlStr = req.url.toString();
91-
final String fallbackFilename = _fallbackAssetForURL(urlStr);
92-
93-
if (urlStr.startsWith(widget.initialURL) == false &&
94-
urlStr.endsWith(fallbackFilename) == false) {
95-
// It's not a local URL, so open it in an external browser
96-
dlog("Opening external URL: ${req.url}");
97-
await launchUrl(req.url!, mode: LaunchMode.externalApplication);
98-
return NavigationActionPolicy.CANCEL;
99-
}
100-
101-
return NavigationActionPolicy.ALLOW;
102-
}
103-
104-
/// Create web view that initially presents a "loading" document with
105-
/// a progress indicator. Then immediately fetch the actual remote document.
106-
/// Falls back to loading a local bundled HTML document with the same name
107-
/// on network error. This ensures that at least *some* version of the
108-
/// document can be viewed even when the device is offline.
109-
InAppWebView _buildWebView(BuildContext context) {
110-
final darkMode = (MediaQuery.platformBrightnessOf(context) == Brightness.dark);
111-
final loadingURL = darkMode ? kLoadingDarkHTMLFilePath : kLoadingHTMLFilePath;
112-
final finalURL = darkMode ? _darkURLForURL(widget.initialURL) : widget.initialURL;
113-
final initialData = darkMode ? loadingDarkHTMLData : loadingHTMLData;
114-
115-
final webViewOpts = InAppWebViewGroupOptions(
116-
crossPlatform: InAppWebViewOptions(
117-
clearCache: kDebugMode,
118-
useShouldOverrideUrlLoading: true,
119-
transparentBackground: true,
120-
));
121-
122-
// Create and configure web view
123-
return InAppWebView(
124-
initialData: initialData,
125-
initialUrlRequest: URLRequest(url: Uri.parse(finalURL)),
126-
initialOptions: webViewOpts,
127-
onLoadStart: (InAppWebViewController controller, Uri? uri) {
128-
dlog("Loading URL ${uri.toString()}");
129-
},
130-
onLoadStop: (InAppWebViewController controller, Uri? uri) async {
131-
final String urlStr = uri.toString();
132-
if (urlStr.endsWith(loadingURL) || urlStr == 'about:blank' || urlStr == 'file:///') {
133-
// Loading of initial "loading" document is complete.
134-
// Now load the actual remote document.
135-
setState(() {
136-
controller.loadUrl(urlRequest: URLRequest(url: Uri.parse(finalURL)));
137-
});
138-
}
139-
},
140-
onLoadError: errHandler,
141-
onLoadHttpError: errHandler,
142-
shouldOverrideUrlLoading: urlClickHandler,
143-
onConsoleMessage: (InAppWebViewController controller, ConsoleMessage msg) {
144-
dlog("Web View Console message: ${msg.message}");
145-
});
146-
}
73+
// /// Fall back to local HTML document if error comes
74+
// /// up when fetching document from remote server.
75+
// void errHandler(InAppWebViewController controller, Uri? url, int errCode, String desc) async {
76+
// dlog("Page load error for $url: $errCode, $desc");
77+
// final String path = _fallbackAssetForURL(url.toString());
78+
// dlog("Falling back to local asset $path");
79+
// setState(() {
80+
// controller.loadFile(assetFilePath: path);
81+
// });
82+
// }
83+
84+
// /// Handle clicks on links in HTML documentation.
85+
// /// These links should be opened in an external browser to
86+
// /// avoid screwing with the navigation stack of the app.
87+
// Future<NavigationActionPolicy> urlClickHandler(
88+
// InAppWebViewController controller, NavigationAction action) async {
89+
// final URLRequest req = action.request;
90+
// final String urlStr = req.url.toString();
91+
// final String fallbackFilename = _fallbackAssetForURL(urlStr);
92+
93+
// if (urlStr.startsWith(widget.initialURL) == false &&
94+
// urlStr.endsWith(fallbackFilename) == false) {
95+
// // It's not a local URL, so open it in an external browser
96+
// dlog("Opening external URL: ${req.url}");
97+
// await launchUrl(req.url!, mode: LaunchMode.externalApplication);
98+
// return NavigationActionPolicy.CANCEL;
99+
// }
100+
101+
// return NavigationActionPolicy.ALLOW;
102+
// }
103+
104+
// /// Create web view that initially presents a "loading" document with
105+
// /// a progress indicator. Then immediately fetch the actual remote document.
106+
// /// Falls back to loading a local bundled HTML document with the same name
107+
// /// on network error. This ensures that at least *some* version of the
108+
// /// document can be viewed even when the device is offline.
109+
// InAppWebView _buildWebView(BuildContext context) {
110+
// final darkMode = (MediaQuery.platformBrightnessOf(context) == Brightness.dark);
111+
// final loadingURL = darkMode ? kLoadingDarkHTMLFilePath : kLoadingHTMLFilePath;
112+
// final finalURL = darkMode ? _darkURLForURL(widget.initialURL) : widget.initialURL;
113+
// final initialData = darkMode ? loadingDarkHTMLData : loadingHTMLData;
114+
115+
// final webViewOpts = InAppWebViewGroupOptions(
116+
// crossPlatform: InAppWebViewOptions(
117+
// clearCache: kDebugMode,
118+
// useShouldOverrideUrlLoading: true,
119+
// transparentBackground: true,
120+
// ));
121+
122+
// // Create and configure web view
123+
// return InAppWebView(
124+
// initialData: initialData,
125+
// initialUrlRequest: URLRequest(url: Uri.parse(finalURL)),
126+
// initialOptions: webViewOpts,
127+
// onLoadStart: (InAppWebViewController controller, Uri? uri) {
128+
// dlog("Loading URL ${uri.toString()}");
129+
// },
130+
// onLoadStop: (InAppWebViewController controller, Uri? uri) async {
131+
// final String urlStr = uri.toString();
132+
// if (urlStr.endsWith(loadingURL) || urlStr == 'about:blank' || urlStr == 'file:///') {
133+
// // Loading of initial "loading" document is complete.
134+
// // Now load the actual remote document.
135+
// setState(() {
136+
// controller.loadUrl(urlRequest: URLRequest(url: Uri.parse(finalURL)));
137+
// });
138+
// }
139+
// },
140+
// onLoadError: errHandler,
141+
// onLoadHttpError: errHandler,
142+
// shouldOverrideUrlLoading: urlClickHandler,
143+
// onConsoleMessage: (InAppWebViewController controller, ConsoleMessage msg) {
144+
// dlog("Web View Console message: ${msg.message}");
145+
// });
146+
// }
147147

148148
@override
149149
Widget build(BuildContext context) {
150-
return Scaffold(
151-
appBar: standardAppBar,
152-
body: _buildWebView(context),
153-
);
150+
return Scaffold(appBar: standardAppBar, body: standardAppBar //buildWebView(context),
151+
);
154152
}
155153
}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ dependencies:
2424
url: https://github.com/tommysolsen/platform_device_id.git
2525
path: platform_device_id
2626
connectivity_plus: '>=5.0.2'
27-
flutter_inappwebview: '^5.7.2+3'
27+
# flutter_inappwebview: '^5.8.0'
2828
path_provider: '^2.1.2'
2929
wakelock_plus: '>=1.1.1'
3030
permission_handler: ^11.3.1

0 commit comments

Comments
 (0)