|
1 | 1 | import 'dart:async'; |
2 | 2 | import 'package:kazumi/pages/webview/webview_controller.dart'; |
3 | 3 | 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'; |
4 | 7 | import 'package:desktop_webview_window/desktop_webview_window.dart'; |
5 | 8 |
|
6 | 9 | class WebviewLinuxItemControllerImpel extends WebviewItemController<Webview> { |
7 | 10 | bool bridgeInited = false; |
8 | 11 |
|
9 | 12 | @override |
10 | 13 | Future<void> init() async { |
| 14 | + final proxyConfig = _getProxyConfiguration(); |
11 | 15 | 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 | + ), |
26 | 34 | ); |
27 | 35 | bridgeInited = false; |
28 | 36 | initEventController.add(true); |
29 | 37 | } |
30 | 38 |
|
| 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 | + |
31 | 59 | Future<void> initBridge(bool useNativePlayer, bool useLegacyParser) async { |
32 | 60 | await initJSBridge(useNativePlayer, useLegacyParser); |
33 | 61 | bridgeInited = true; |
|
0 commit comments