Skip to content

Commit 0778b59

Browse files
committed
feat: add Linux WebView proxy support
- Add proxy configuration to Linux WebView controller - Use local linux_webview_window with HTTP proxy patch
1 parent 5d9cb11 commit 0778b59

File tree

3 files changed

+46
-22
lines changed

3 files changed

+46
-22
lines changed

lib/pages/webview/webview_controller_impel/webview_linux_controller_impel.dart

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,61 @@
11
import 'dart:async';
22
import 'package:kazumi/pages/webview/webview_controller.dart';
33
import 'package:kazumi/utils/utils.dart';
4+
import 'package:kazumi/utils/storage.dart';
5+
import 'package:kazumi/utils/proxy_utils.dart';
6+
import 'package:kazumi/utils/logger.dart';
47
import 'package:desktop_webview_window/desktop_webview_window.dart';
58

69
class WebviewLinuxItemControllerImpel extends WebviewItemController<Webview> {
710
bool bridgeInited = false;
811

912
@override
1013
Future<void> init() async {
14+
final proxyConfig = _getProxyConfiguration();
1115
webviewController ??= await WebviewWindow.create(
12-
configuration: const CreateConfiguration(headless: true, userScripts: [
13-
UserScript(
14-
source: blobScript,
15-
injectionTime: UserScriptInjectionTime.documentStart,
16-
forAllFrames: true),
17-
UserScript(
18-
source: iframeScript,
19-
injectionTime: UserScriptInjectionTime.documentEnd,
20-
forAllFrames: true),
21-
UserScript(
22-
source: videoScript,
23-
injectionTime: UserScriptInjectionTime.documentEnd,
24-
forAllFrames: true)
25-
]),
16+
configuration: CreateConfiguration(
17+
headless: true,
18+
proxy: proxyConfig,
19+
userScripts: const [
20+
UserScript(
21+
source: blobScript,
22+
injectionTime: UserScriptInjectionTime.documentStart,
23+
forAllFrames: true),
24+
UserScript(
25+
source: iframeScript,
26+
injectionTime: UserScriptInjectionTime.documentEnd,
27+
forAllFrames: true),
28+
UserScript(
29+
source: videoScript,
30+
injectionTime: UserScriptInjectionTime.documentEnd,
31+
forAllFrames: true)
32+
],
33+
),
2634
);
2735
bridgeInited = false;
2836
initEventController.add(true);
2937
}
3038

39+
ProxyConfiguration? _getProxyConfiguration() {
40+
final setting = GStorage.setting;
41+
final bool proxyEnable =
42+
setting.get(SettingBoxKey.proxyEnable, defaultValue: false);
43+
if (!proxyEnable) {
44+
return null;
45+
}
46+
47+
final String proxyUrl =
48+
setting.get(SettingBoxKey.proxyUrl, defaultValue: '');
49+
final parsed = ProxyUtils.parseProxyUrl(proxyUrl);
50+
if (parsed == null) {
51+
return null;
52+
}
53+
54+
final (host, port) = parsed;
55+
KazumiLogger().i('WebView: 代理设置成功 $host:$port');
56+
return ProxyConfiguration(host: host, port: port);
57+
}
58+
3159
Future<void> initBridge(bool useNativePlayer, bool useLegacyParser) async {
3260
await initJSBridge(useNativePlayer, useLegacyParser);
3361
bridgeInited = true;

pubspec.lock

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -316,11 +316,9 @@ packages:
316316
desktop_webview_window:
317317
dependency: "direct main"
318318
description:
319-
path: "."
320-
ref: b107a03068b8c4249cec4a3b159d56f1326103c5
321-
resolved-ref: b107a03068b8c4249cec4a3b159d56f1326103c5
322-
url: "https://github.com/Predidit/linux_webview_window.git"
323-
source: git
319+
path: "../linux_webview_window"
320+
relative: true
321+
source: path
324322
version: "0.2.4"
325323
device_info_plus:
326324
dependency: "direct main"

pubspec.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,7 @@ dependencies:
9696
url: https://github.com/Predidit/flutter-webview-windows.git
9797
ref: 4399f68beab25d51b277e37e3949f9fb2d6d8304
9898
desktop_webview_window:
99-
git:
100-
url: https://github.com/Predidit/linux_webview_window.git
101-
ref: b107a03068b8c4249cec4a3b159d56f1326103c5
99+
path: ../linux_webview_window
102100
media_kit:
103101
git:
104102
url: https://github.com/Predidit/media-kit.git

0 commit comments

Comments
 (0)