mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
windows webview
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -26,12 +26,17 @@ import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_displaymode/flutter_displaymode.dart';
|
||||
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:media_kit/media_kit.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:window_manager/window_manager.dart';
|
||||
|
||||
WebViewEnvironment? webViewEnvironment;
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
MediaKit.ensureInitialized();
|
||||
@@ -62,6 +67,17 @@ void main() async {
|
||||
]);
|
||||
}
|
||||
|
||||
if (Platform.isWindows) {
|
||||
if (await WebViewEnvironment.getAvailableVersion() != null) {
|
||||
final dir = await getApplicationSupportDirectory();
|
||||
webViewEnvironment = await WebViewEnvironment.create(
|
||||
settings: WebViewEnvironmentSettings(
|
||||
userDataFolder: path.join(dir.path, 'flutter_inappwebview'),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Request();
|
||||
Request.setCookie();
|
||||
RequestUtils.syncHistoryStatus();
|
||||
|
||||
@@ -34,6 +34,7 @@ class _MainAppState extends State<MainApp>
|
||||
with RouteAware, WidgetsBindingObserver, WindowListener, TrayListener {
|
||||
final MainController _mainController = Get.put(MainController());
|
||||
late final _setting = GStorage.setting;
|
||||
static const MethodChannel _channel = MethodChannel('window_control');
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -131,6 +132,14 @@ class _MainAppState extends State<MainApp>
|
||||
void onWindowClose() {
|
||||
if (_mainController.minimizeOnExit) {
|
||||
windowManager.hide();
|
||||
} else {
|
||||
_onClose();
|
||||
}
|
||||
}
|
||||
|
||||
void _onClose() {
|
||||
if (Platform.isWindows) {
|
||||
_channel.invokeMethod('closeWindow');
|
||||
} else {
|
||||
exit(0);
|
||||
}
|
||||
@@ -157,7 +166,7 @@ class _MainAppState extends State<MainApp>
|
||||
case 'show':
|
||||
windowManager.show();
|
||||
case 'exit':
|
||||
exit(0);
|
||||
_onClose();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:PiliPlus/http/ua_type.dart';
|
||||
import 'package:PiliPlus/main.dart';
|
||||
import 'package:PiliPlus/models/common/webview_menu_type.dart';
|
||||
import 'package:PiliPlus/utils/app_scheme.dart';
|
||||
import 'package:PiliPlus/utils/cache_manage.dart';
|
||||
@@ -60,7 +61,7 @@ class _WebviewPageState extends State<WebviewPage> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (Platform.isWindows || Platform.isLinux) {
|
||||
if (Platform.isLinux) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(),
|
||||
body: Center(
|
||||
@@ -156,6 +157,7 @@ class _WebviewPageState extends State<WebviewPage> {
|
||||
),
|
||||
body: SafeArea(
|
||||
child: InAppWebView(
|
||||
webViewEnvironment: webViewEnvironment,
|
||||
initialSettings: InAppWebViewSettings(
|
||||
clearCache: true,
|
||||
javaScriptEnabled: true,
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'dart:io' show Platform;
|
||||
import 'package:PiliPlus/grpc/grpc_req.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/http/user.dart';
|
||||
import 'package:PiliPlus/main.dart';
|
||||
import 'package:PiliPlus/models/common/dynamic/dynamics_type.dart';
|
||||
import 'package:PiliPlus/models/common/home_tab_type.dart';
|
||||
import 'package:PiliPlus/models/user/info.dart';
|
||||
@@ -27,15 +28,20 @@ import 'package:get/get.dart';
|
||||
|
||||
abstract class LoginUtils {
|
||||
static FutureOr setWebCookie([Account? account]) {
|
||||
if (Platform.isWindows || Platform.isLinux) {
|
||||
if (Platform.isLinux) {
|
||||
return null;
|
||||
}
|
||||
final cookies = (account ?? Accounts.main).cookieJar.toList();
|
||||
final webManager = web.CookieManager.instance();
|
||||
final webManager = web.CookieManager.instance(
|
||||
webViewEnvironment: webViewEnvironment,
|
||||
);
|
||||
final isWindows = Platform.isWindows;
|
||||
return Future.wait(
|
||||
cookies.map(
|
||||
(cookie) => webManager.setCookie(
|
||||
url: web.WebUri(cookie.domain ?? ''),
|
||||
url: web.WebUri(
|
||||
'${isWindows ? 'https://' : ''} ${cookie.domain}',
|
||||
),
|
||||
name: cookie.name,
|
||||
value: cookie.value,
|
||||
path: cookie.path ?? '/',
|
||||
@@ -117,7 +123,7 @@ abstract class LoginUtils {
|
||||
GrpcReq.updateHeaders(null);
|
||||
|
||||
await Future.wait([
|
||||
if (!Platform.isWindows) web.CookieManager.instance().deleteAllCookies(),
|
||||
if (!Platform.isLinux) web.CookieManager.instance().deleteAllCookies(),
|
||||
GStorage.userInfo.delete('userInfoCache'),
|
||||
]);
|
||||
|
||||
|
||||
25
pubspec.lock
25
pubspec.lock
@@ -638,11 +638,10 @@ packages:
|
||||
flutter_inappwebview:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
path: flutter_inappwebview
|
||||
ref: "version_6.1.5"
|
||||
resolved-ref: bef2e3cb123ad4f6533a6371594ea3e21f36eeb2
|
||||
url: "https://github.com/bggRGjQaUbCoE/flutter_inappwebview.git"
|
||||
source: git
|
||||
name: flutter_inappwebview
|
||||
sha256: "80092d13d3e29b6227e25b67973c67c7210bd5e35c4b747ca908e31eb71a46d5"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "6.1.5"
|
||||
flutter_inappwebview_android:
|
||||
dependency: transitive
|
||||
@@ -684,6 +683,22 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.3.0+1"
|
||||
flutter_inappwebview_web:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_inappwebview_web
|
||||
sha256: "55f89c83b0a0d3b7893306b3bb545ba4770a4df018204917148ebb42dc14a598"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.1.2"
|
||||
flutter_inappwebview_windows:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_inappwebview_windows
|
||||
sha256: "8b4d3a46078a2cdc636c4a3d10d10f2a16882f6be607962dbfff8874d1642055"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.6.0"
|
||||
flutter_launcher_icons:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
|
||||
@@ -75,12 +75,7 @@ dependencies:
|
||||
# webview_cookie_manager: ^2.0.6
|
||||
# 浏览器
|
||||
# webview_flutter: ^4.10.0
|
||||
# flutter_inappwebview: ^6.1.5
|
||||
flutter_inappwebview:
|
||||
git:
|
||||
url: https://github.com/bggRGjQaUbCoE/flutter_inappwebview.git
|
||||
path: flutter_inappwebview
|
||||
ref: version_6.1.5
|
||||
flutter_inappwebview: ^6.1.5
|
||||
# 解决sliver滑动不同步
|
||||
# extended_nested_scroll_view: ^6.2.1
|
||||
extended_nested_scroll_view:
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
|
||||
#include "flutter/generated_plugin_registrant.h"
|
||||
|
||||
#include <flutter/method_channel.h>
|
||||
#include <flutter/standard_method_codec.h>
|
||||
|
||||
FlutterWindow::FlutterWindow(const flutter::DartProject& project)
|
||||
: project_(project) {}
|
||||
|
||||
@@ -25,6 +28,25 @@ bool FlutterWindow::OnCreate() {
|
||||
return false;
|
||||
}
|
||||
RegisterPlugins(flutter_controller_->engine());
|
||||
|
||||
// flutter_inappwebview
|
||||
// 6.2.0-beta.2+ https://github.com/pichillilorenzo/flutter_inappwebview/issues/2482
|
||||
// 6.1.5 https://github.com/pichillilorenzo/flutter_inappwebview/issues/2512#issuecomment-3031039587
|
||||
flutter::MethodChannel<> channel(
|
||||
flutter_controller_->engine()->messenger(), "window_control",
|
||||
&flutter::StandardMethodCodec::GetInstance());
|
||||
channel.SetMethodCallHandler(
|
||||
[](const flutter::MethodCall<>& call,
|
||||
std::unique_ptr<flutter::MethodResult<>> result) {
|
||||
if (call.method_name().compare("closeWindow") == 0) {
|
||||
HANDLE hProcess = GetCurrentProcess();
|
||||
TerminateProcess(hProcess, 0);
|
||||
result->Success();
|
||||
} else {
|
||||
result->NotImplemented();
|
||||
}
|
||||
});
|
||||
|
||||
SetChildContent(flutter_controller_->view()->GetNativeWindow());
|
||||
|
||||
flutter_controller_->engine()->SetNextFrameCallback([&]() {
|
||||
|
||||
Reference in New Issue
Block a user