Skip to content

Commit

Permalink
WebView fix
Browse files Browse the repository at this point in the history
  • Loading branch information
arianneorpilla committed Oct 5, 2023
1 parent 66668e7 commit 7638ccc
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 160 deletions.
2 changes: 1 addition & 1 deletion yuuna/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 33
compileSdkVersion 34
ndkVersion '21.4.7075529'

compileOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,11 @@ class BingImagesSearchEnhancement extends ImageEnhancement {

HeadlessInAppWebView webView = HeadlessInAppWebView(
initialUrlRequest: URLRequest(
url: Uri.parse(
url: WebUri(
"https://www.bing.com/images/search?q=$searchTerm')",
),
),
initialOptions: InAppWebViewGroupOptions(
android: AndroidInAppWebViewOptions(
blockNetworkImage: true,
),
),
initialSettings: InAppWebViewSettings(blockNetworkImage: true),
onLoadStop: (controller, uri) async {
Directory appDirDoc = await getApplicationSupportDirectory();
String bingImagesPath = '${appDirDoc.path}/bingImages';
Expand Down
36 changes: 12 additions & 24 deletions yuuna/lib/src/media/sources/reader_lyrics_source.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,12 @@ class ReaderLyricsSource extends ReaderMediaSource {
bool webViewBusy = true;

HeadlessInAppWebView webView = HeadlessInAppWebView(
initialOptions: InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(
userAgent: userAgent,
),
android: AndroidInAppWebViewOptions(
blockNetworkImage: true,
),
initialSettings: InAppWebViewSettings(
userAgent: userAgent,
blockNetworkImage: true,
),
initialUrlRequest: URLRequest(
url: Uri.parse(searchUrl),
url: WebUri(searchUrl),
),
onLoadStop: (controller, uri) async {
text = await controller.evaluateJavascript(source: '''
Expand Down Expand Up @@ -186,16 +182,12 @@ class ReaderLyricsSource extends ReaderMediaSource {
bool googleWebViewBusy = true;

HeadlessInAppWebView googleWebView = HeadlessInAppWebView(
initialOptions: InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(
userAgent: userAgent,
),
android: AndroidInAppWebViewOptions(
blockNetworkImage: true,
),
initialSettings: InAppWebViewSettings(
userAgent: userAgent,
blockNetworkImage: true,
),
initialUrlRequest: URLRequest(
url: Uri.parse(
url: WebUri(
'https://google.com/search?q=$artist+$title+歌詞+site:uta-net.com/song'),
),
onLoadStop: (controller, uri) async {
Expand All @@ -216,16 +208,12 @@ class ReaderLyricsSource extends ReaderMediaSource {
if (firstResultUrl != null) {
bool utanetWebViewBusy = true;
HeadlessInAppWebView utanetWebView = HeadlessInAppWebView(
initialOptions: InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(
userAgent: userAgent,
),
android: AndroidInAppWebViewOptions(
blockNetworkImage: true,
),
initialSettings: InAppWebViewSettings(
userAgent: userAgent,
blockNetworkImage: true,
),
initialUrlRequest: URLRequest(
url: Uri.parse(firstResultUrl!),
url: WebUri(firstResultUrl!),
),
onLoadStop: (controller, uri) async {
text = await controller.evaluateJavascript(source: '''
Expand Down
11 changes: 4 additions & 7 deletions yuuna/lib/src/media/sources/reader_mokuro_source.dart
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,12 @@ class ReaderMokuroSource extends ReaderMediaSource {
);

HeadlessInAppWebView webView = HeadlessInAppWebView(
initialOptions: InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(
allowFileAccessFromFileURLs: true,
allowUniversalAccessFromFileURLs: true,
),
android: AndroidInAppWebViewOptions(),
initialSettings: InAppWebViewSettings(
allowFileAccessFromFileURLs: true,
allowUniversalAccessFromFileURLs: true,
),
initialUrlRequest: URLRequest(
url: Uri.parse(
url: WebUri(
'file://$parentDirectory/${Uri.encodeComponent(directoryBasename)}/${Uri.encodeComponent(fileBasename)}'),
),
onLoadStop: (controller, url) async {
Expand Down
2 changes: 1 addition & 1 deletion yuuna/lib/src/media/sources/reader_ttu_source.dart
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ class ReaderTtuSource extends ReaderMediaSource {

HeadlessInAppWebView webView = HeadlessInAppWebView(
initialUrlRequest: URLRequest(
url: Uri.parse('http://localhost:$port/'),
url: WebUri('http://localhost:$port/'),
),
onLoadStop: (controller, url) async {
controller.evaluateJavascript(source: getHistoryJs);
Expand Down
30 changes: 11 additions & 19 deletions yuuna/lib/src/pages/implementations/browser_source_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ class _BrowserSourcePageState extends BaseSourcePageState<BrowserSourcePage> {
text: Uri.decodeFull(
_uriNotifier.value?.removeFragment().toString() ?? ''),
onBrowse: (url) {
_controller.loadUrl(urlRequest: URLRequest(url: Uri.parse(url)));
_controller.loadUrl(urlRequest: URLRequest(url: WebUri(url)));
},
),
);
Expand All @@ -328,7 +328,7 @@ class _BrowserSourcePageState extends BaseSourcePageState<BrowserSourcePage> {
/// Get the default context menu for sources that make use of embedded web
/// views.
ContextMenu get contextMenu => ContextMenu(
options: ContextMenuOptions(
settings: ContextMenuSettings(
hideDefaultSystemContextMenuItems: true,
),
menuItems: [
Expand All @@ -343,52 +343,47 @@ class _BrowserSourcePageState extends BaseSourcePageState<BrowserSourcePage> {
/// Get the default context menu for sources that make use of embedded web
/// views.
ContextMenu get emptyContextMenu => ContextMenu(
options: ContextMenuOptions(
settings: ContextMenuSettings(
hideDefaultSystemContextMenuItems: true,
),
menuItems: [],
);

ContextMenuItem searchMenuItem() {
return ContextMenuItem(
iosId: '1',
androidId: 1,
id: 1,
title: t.search,
action: searchMenuAction,
);
}

ContextMenuItem stashMenuItem() {
return ContextMenuItem(
iosId: '2',
androidId: 2,
id: 2,
title: t.stash,
action: stashMenuAction,
);
}

ContextMenuItem copyMenuItem() {
return ContextMenuItem(
iosId: '3',
androidId: 3,
id: 3,
title: t.copy,
action: copyMenuAction,
);
}

ContextMenuItem shareMenuItem() {
return ContextMenuItem(
iosId: '4',
androidId: 4,
id: 4,
title: t.share,
action: shareMenuAction,
);
}

ContextMenuItem creatorMenuItem() {
return ContextMenuItem(
iosId: '5',
androidId: 5,
id: 5,
title: t.creator,
action: creatorMenuAction,
);
Expand Down Expand Up @@ -478,13 +473,10 @@ class _BrowserSourcePageState extends BaseSourcePageState<BrowserSourcePage> {
scrollX = newX;
scrollY = newY;
},
initialOptions: InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(
userAgent: userAgent,
),
initialSettings: InAppWebViewSettings(
userAgent: userAgent,
),
initialUrlRequest:
URLRequest(url: Uri.parse(widget.item!.mediaIdentifier)),
initialUrlRequest: URLRequest(url: WebUri(widget.item!.mediaIdentifier)),
contextMenu: contextMenu,
onConsoleMessage: onConsoleMessage,
onWebViewCreated: (controller) {
Expand Down
16 changes: 2 additions & 14 deletions yuuna/lib/src/pages/implementations/creator_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -209,23 +209,11 @@ class _CreatorPageState extends BasePageState<CreatorPage> {
onWillPop: onWillPop,
child: GestureDetector(
onTap: () => FocusManager.instance.primaryFocus?.unfocus(),
child: Stack(
children: [
buildBlur(),
buildScaffold(),
],
),
child: buildScaffold(),
),
);
}

Widget buildBlur() {
return BackdropFilter(
filter: ImageFilter.blur(sigmaX: 25, sigmaY: 25),
child: Container(),
);
}

AppBar buildAppBar() {
return AppBar(
backgroundColor: Colors.transparent,
Expand Down Expand Up @@ -463,7 +451,7 @@ class _CreatorPageState extends BasePageState<CreatorPage> {

return Scaffold(
backgroundColor:
theme.colorScheme.background.withOpacity(isCardEditing ? 0.5 : 1),
theme.colorScheme.background.withOpacity(isCardEditing ? 0.96 : 1),
key: _scaffoldKey,
resizeToAvoidBottomInset: true,
appBar: showPortrait ? buildAppBar() : null,
Expand Down
33 changes: 12 additions & 21 deletions yuuna/lib/src/pages/implementations/mokuro_catalog_browse_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class _MokuroCatalogBrowsePageState
/// Get the default context menu for sources that make use of embedded web
/// views.
ContextMenu get contextMenu => ContextMenu(
options: ContextMenuOptions(
settings: ContextMenuSettings(
hideDefaultSystemContextMenuItems: true,
),
menuItems: [
Expand All @@ -198,52 +198,47 @@ class _MokuroCatalogBrowsePageState
/// Get the default context menu for sources that make use of embedded web
/// views.
ContextMenu get emptyContextMenu => ContextMenu(
options: ContextMenuOptions(
settings: ContextMenuSettings(
hideDefaultSystemContextMenuItems: true,
),
menuItems: [],
);

ContextMenuItem searchMenuItem() {
return ContextMenuItem(
iosId: '1',
androidId: 1,
id: 1,
title: t.search,
action: searchMenuAction,
);
}

ContextMenuItem stashMenuItem() {
return ContextMenuItem(
iosId: '2',
androidId: 2,
id: 2,
title: t.stash,
action: stashMenuAction,
);
}

ContextMenuItem copyMenuItem() {
return ContextMenuItem(
iosId: '3',
androidId: 3,
id: 3,
title: t.copy,
action: copyMenuAction,
);
}

ContextMenuItem shareMenuItem() {
return ContextMenuItem(
iosId: '4',
androidId: 4,
id: 4,
title: t.share,
action: shareMenuAction,
);
}

ContextMenuItem creatorMenuItem() {
return ContextMenuItem(
iosId: '5',
androidId: 5,
id: 5,
title: t.creator,
action: creatorMenuAction,
);
Expand Down Expand Up @@ -327,17 +322,13 @@ class _MokuroCatalogBrowsePageState

Widget buildBody() {
return InAppWebView(
initialOptions: InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(
verticalScrollBarEnabled: false,
horizontalScrollBarEnabled: false,
),
android: AndroidInAppWebViewOptions(
initialScale: MediaQuery.of(context).size.width ~/ 1.5,
),
initialSettings: InAppWebViewSettings(
verticalScrollBarEnabled: false,
horizontalScrollBarEnabled: false,
initialScale: MediaQuery.of(context).size.width ~/ 1.5,
),
initialUrlRequest: URLRequest(
url: Uri.parse(widget.catalog?.url ?? widget.item!.mediaIdentifier)),
url: WebUri(widget.catalog?.url ?? widget.item!.mediaIdentifier)),
contextMenu: contextMenu,
onConsoleMessage: onConsoleMessage,
onWebViewCreated: (controller) {
Expand Down
Loading

0 comments on commit 7638ccc

Please sign in to comment.