Skip to content

Commit

Permalink
fix: webview2 cache data path
Browse files Browse the repository at this point in the history
  • Loading branch information
Anxcye committed Dec 26, 2024
1 parent 6d7d1c1 commit 215989d
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 20 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,20 @@
* Feat(Android): Display TTS control buttons in the notification screen
* Feat(Android): Import books through system sharing
* Feat(Windows): Drag to import books
* Feat(Windows): Webview2 check and prompt
* Fix: Fixed garbled text when importing txt files
* Fix: Optimized import efficiency
* Fix(Windows):Fixed crash issue when opening books on some Windows devices

* 新增:读者添加批注
* 新增:书籍搜索
* 新增(Android):在通知栏中显示 TTS 控制按钮
* 新增(Android):通过系统分享导入书籍
* 新增(Windows):拖拽导入书籍
* 新增(Windows):Webview2 检查和提示
* 修复:txt 文件导入时乱码问题(添加了 GBK 解码)
* 修复:大幅优化导入效率
* 修复(Windows):部分Windows 端打开书时闪退问题

## 1.2.2 2024-12-02
🚀 Support txt files now!
Expand Down
4 changes: 3 additions & 1 deletion lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@
"webview_unsupported_version": "Unsupported Webview Version",
"webview_unsupported_message": "Your Webview version may be not supported. Current version is {version}, required minimum version is {minVersion}, please update your Webview",
"webview_update": "How to update",
"webview_cancel": "I know"
"webview_cancel": "I know",
"webview2_not_installed": "Failed to find an installed WebView2 Runtime or non-stable Microsoft Edge installation.",
"webview2_install": "Go to download"

}
5 changes: 4 additions & 1 deletion lib/l10n/app_zh.arb
Original file line number Diff line number Diff line change
Expand Up @@ -206,5 +206,8 @@
"webview_unsupported_version": "不支持的 Webview 版本",
"webview_unsupported_message": "Webview 版本可能不支持。当前版本为 {version}, 所需的最低版本是 {minVersion},请更新您的 Webview",
"webview_update": "如何更新",
"webview_cancel": "我知道了"
"webview_cancel": "我知道了",

"webview2_not_installed": "未能找到已安装的WebView2运行时或非稳定版的Microsoft Edge安装。",
"webview2_install": "去安装"
}
2 changes: 2 additions & 0 deletions lib/page/book_player/epub_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:anx_reader/models/reading_rules.dart';
import 'package:anx_reader/models/search_result_model.dart';
import 'package:anx_reader/models/toc_item.dart';
import 'package:anx_reader/page/book_player/image_viewer.dart';
import 'package:anx_reader/page/home_page.dart';
import 'package:anx_reader/page/reading_page.dart';
import 'package:anx_reader/providers/book_list.dart';
import 'package:anx_reader/service/book_player/book_player_server.dart';
Expand Down Expand Up @@ -599,6 +600,7 @@ class EpubPlayerState extends ConsumerState<EpubPlayer>
),
SizedBox.expand(
child: InAppWebView(
webViewEnvironment: webViewEnvironment,
initialUrlRequest: URLRequest(url: WebUri(indexHtmlPath)),
initialSettings: initialSettings,
contextMenu: contextMenu,
Expand Down
37 changes: 37 additions & 0 deletions lib/page/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,21 @@ import 'package:anx_reader/page/home_page/settings_page.dart';
import 'package:anx_reader/page/home_page/statistics_page.dart';
import 'package:anx_reader/service/book.dart';
import 'package:anx_reader/utils/check_update.dart';
import 'package:anx_reader/utils/get_path/cache_path.dart';
import 'package:anx_reader/utils/load_default_font.dart';
import 'package:anx_reader/utils/log/common.dart';
import 'package:anx_reader/utils/webdav/common.dart';
import 'package:anx_reader/config/shared_preference_provider.dart';
import 'package:anx_reader/utils/toast/common.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:receive_sharing_intent/receive_sharing_intent.dart';
import 'package:url_launcher/url_launcher.dart';

WebViewEnvironment? webViewEnvironment;

class HomePage extends ConsumerStatefulWidget {
const HomePage({super.key});
Expand Down Expand Up @@ -47,6 +54,36 @@ class _HomePageState extends ConsumerState<HomePage> {
}
loadDefaultFont();

if (!kIsWeb && defaultTargetPlatform == TargetPlatform.windows) {
final availableVersion = await WebViewEnvironment.getAvailableVersion();
AnxLog.info('WebView2 version: $availableVersion');

if (availableVersion == null) {
SmartDialog.show(
builder: (context) => AlertDialog(
title: const Icon(Icons.error),
content: Text(L10n.of(context).webview2_not_installed),
actions: [
TextButton(
onPressed: () => {
launchUrl(
Uri.parse(
'https://developer.microsoft.com/en-us/microsoft-edge/webview2'),
mode: LaunchMode.externalApplication)
},
child: Text(L10n.of(context).webview2_install),
),
],
),
);
} else {
webViewEnvironment = await WebViewEnvironment.create(
settings: WebViewEnvironmentSettings(
userDataFolder: (await getAnxCacheDir()).path),
);
}
}

if (Platform.isAndroid || Platform.isIOS) {
// receive sharing intent
Future<void> handleShare(List<SharedMediaFile> value) async {
Expand Down
28 changes: 14 additions & 14 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -536,18 +536,18 @@ packages:
dependency: "direct main"
description:
name: flutter_inappwebview
sha256: "9f023eaa11c91330344aca4c45cd537aba9ccd92ef74b41cd9e112a862530a4f"
sha256: "80092d13d3e29b6227e25b67973c67c7210bd5e35c4b747ca908e31eb71a46d5"
url: "https://pub.dev"
source: hosted
version: "6.1.2"
version: "6.1.5"
flutter_inappwebview_android:
dependency: transitive
description:
name: flutter_inappwebview_android
sha256: "6b24fbbaa69168da2d2ab4ddb2d65677468e2a0a0d593d629558537f710786dc"
sha256: "62557c15a5c2db5d195cb3892aab74fcaec266d7b86d59a6f0027abd672cddba"
url: "https://pub.dev"
source: hosted
version: "1.1.0+4"
version: "1.1.3"
flutter_inappwebview_internal_annotations:
dependency: transitive
description:
Expand All @@ -560,42 +560,42 @@ packages:
dependency: transitive
description:
name: flutter_inappwebview_ios
sha256: "571b0bfdb963548fcb945b9abe357352b4a523c249b4f9816fc5a83e2a71d9ec"
sha256: "5818cf9b26cf0cbb0f62ff50772217d41ea8d3d9cc00279c45f8aabaa1b4025d"
url: "https://pub.dev"
source: hosted
version: "1.1.0+3"
version: "1.1.2"
flutter_inappwebview_macos:
dependency: transitive
description:
name: flutter_inappwebview_macos
sha256: e5e7f09dabd7b5b2ef15b00c07ed4da4a45bd597db0c4221702485665b6628b7
sha256: c1fbb86af1a3738e3541364d7d1866315ffb0468a1a77e34198c9be571287da1
url: "https://pub.dev"
source: hosted
version: "1.1.0+3"
version: "1.1.2"
flutter_inappwebview_platform_interface:
dependency: transitive
description:
name: flutter_inappwebview_platform_interface
sha256: da6c7bf193beba655bdfcd825b6c7f7b51da4944e1eb76bf9faddf685ca15fa2
sha256: cf5323e194096b6ede7a1ca808c3e0a078e4b33cc3f6338977d75b4024ba2500
url: "https://pub.dev"
source: hosted
version: "1.1.1"
version: "1.3.0+1"
flutter_inappwebview_web:
dependency: transitive
description:
name: flutter_inappwebview_web
sha256: ee1389bfec8c9ef07ba4be48a117207c9392dbdbf366330aa26d69f67a826978
sha256: "55f89c83b0a0d3b7893306b3bb545ba4770a4df018204917148ebb42dc14a598"
url: "https://pub.dev"
source: hosted
version: "1.1.0+2"
version: "1.1.2"
flutter_inappwebview_windows:
dependency: transitive
description:
name: flutter_inappwebview_windows
sha256: "3ad92e93bafc2984f90f627783c3f5fc705842fb8d4f7213f92bb9027c6eac94"
sha256: "8b4d3a46078a2cdc636c4a3d10d10f2a16882f6be607962dbfff8874d1642055"
url: "https://pub.dev"
source: hosted
version: "0.3.0+1"
version: "0.6.0"
flutter_lints:
dependency: "direct dev"
description:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dependencies:
html: ^0.15.4
flutter_html: ^3.0.0-beta.2
archive: ^3.4.10
flutter_inappwebview: ^6.1.0+1
flutter_inappwebview: ^6.1.5
shelf: ^1.4.1
fl_chart: ^0.67.0
flutter_rating_bar: ^4.0.1
Expand Down
6 changes: 3 additions & 3 deletions scripts/build_windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ New-Item -ItemType Directory -Force -Path "D:\inno-result"
7z a -tzip "D:\inno-result\app.zip" "D:\inno\*"

# copy dll
Copy-Item "scripts\windows\x64\msvcp140.dll" "build\windows\x64\runner\Release\"
Copy-Item "scripts\windows\x64\vcruntime140.dll" "build\windows\x64\runner\Release\"
Copy-Item "scripts\windows\x64\vcruntime140_1.dll" "build\windows\x64\runner\Release\"
# Copy-Item "scripts\windows\x64\msvcp140.dll" "build\windows\x64\runner\Release\"
# Copy-Item "scripts\windows\x64\vcruntime140.dll" "build\windows\x64\runner\Release\"
# Copy-Item "scripts\windows\x64\vcruntime140_1.dll" "build\windows\x64\runner\Release\"

# copy language file
Copy-Item "scripts\ChineseSimplified.isl" "$innoSetupDir\Languages\"
Expand Down
2 changes: 2 additions & 0 deletions scripts/compile_windows_setup-inno.iss
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ WizardStyle=modern
; SignTool=MySignTool
ArchitecturesInstallIn64BitMode=x64compatible
ArchitecturesAllowed=x64compatible
PrivilegesRequired=admin


[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
Expand Down
Binary file modified scripts/windows/x64/msvcp140.dll
Binary file not shown.
Binary file modified scripts/windows/x64/vcruntime140.dll
Binary file not shown.
Binary file modified scripts/windows/x64/vcruntime140_1.dll
Binary file not shown.

0 comments on commit 215989d

Please sign in to comment.