mirror of
https://github.com/wgh136/pixes.git
synced 2025-09-27 04:57:23 +00:00
system proxy & build_windows script
This commit is contained in:
@@ -1,5 +1,29 @@
|
|||||||
package com.github.wgh136.pixes
|
package com.github.wgh136.pixes
|
||||||
|
|
||||||
import io.flutter.embedding.android.FlutterActivity
|
import io.flutter.embedding.android.FlutterActivity
|
||||||
|
import io.flutter.plugins.GeneratedPluginRegistrant
|
||||||
|
import io.flutter.plugin.common.MethodChannel
|
||||||
|
import io.flutter.embedding.engine.FlutterEngine
|
||||||
|
|
||||||
class MainActivity: FlutterActivity()
|
class MainActivity: FlutterActivity() {
|
||||||
|
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
|
||||||
|
GeneratedPluginRegistrant.registerWith(flutterEngine)
|
||||||
|
//获取http代理
|
||||||
|
MethodChannel(
|
||||||
|
flutterEngine.dartExecutor.binaryMessenger,
|
||||||
|
"pixes/proxy"
|
||||||
|
).setMethodCallHandler { _, res ->
|
||||||
|
res.success(getProxy())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getProxy(): String{
|
||||||
|
val host = System.getProperty("http.proxyHost")
|
||||||
|
val port = System.getProperty("http.proxyPort")
|
||||||
|
return if(host!=null&&port!=null){
|
||||||
|
"$host:$port"
|
||||||
|
}else{
|
||||||
|
"No Proxy"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
28
build_windows.py
Normal file
28
build_windows.py
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import subprocess
|
||||||
|
import os
|
||||||
|
|
||||||
|
fontUse = '''
|
||||||
|
fonts:
|
||||||
|
- family: font
|
||||||
|
fonts:
|
||||||
|
- asset: assets/SourceHanSansSC-Regular.otf
|
||||||
|
'''
|
||||||
|
|
||||||
|
file = open('pubspec.yaml', 'r')
|
||||||
|
content = file.read()
|
||||||
|
file.close()
|
||||||
|
file = open('pubspec.yaml', 'a')
|
||||||
|
file.write(fontUse)
|
||||||
|
file.close()
|
||||||
|
|
||||||
|
subprocess.run(["flutter", "build", "windows"], shell=True)
|
||||||
|
|
||||||
|
file = open('pubspec.yaml', 'w')
|
||||||
|
file.write(content)
|
||||||
|
|
||||||
|
if os.path.exists("build/app-windows.zip"):
|
||||||
|
os.remove("build/app-windows.zip")
|
||||||
|
|
||||||
|
# 压缩build/windows/x64/runner/Release, 生成app-windows.zip, 使用tar命令
|
||||||
|
subprocess.run(["tar", "-a", "-c", "-f", "build/app-windows.zip", "-C", "build/windows/x64/runner/Release", "."]
|
||||||
|
, shell=True)
|
@@ -7,6 +7,19 @@ import Flutter
|
|||||||
_ application: UIApplication,
|
_ application: UIApplication,
|
||||||
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
|
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
|
||||||
) -> Bool {
|
) -> Bool {
|
||||||
|
let methodChannel = FlutterMethodChannel(name: "pixes/proxy", binaryMessenger: controller.binaryMessenger)
|
||||||
|
methodChannel.setMethodCallHandler { [weak self] (call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in
|
||||||
|
if let proxySettings = CFNetworkCopySystemProxySettings()?.takeUnretainedValue() as NSDictionary?,
|
||||||
|
let dict = proxySettings.object(forKey: kCFNetworkProxiesHTTPProxy) as? NSDictionary,
|
||||||
|
let host = dict.object(forKey: kCFNetworkProxiesHTTPProxy) as? String,
|
||||||
|
let port = dict.object(forKey: kCFNetworkProxiesHTTPPort) as? Int {
|
||||||
|
let proxyConfig = "\(host):\(port)"
|
||||||
|
result(proxyConfig)
|
||||||
|
} else {
|
||||||
|
result("")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
GeneratedPluginRegistrant.register(with: self)
|
GeneratedPluginRegistrant.register(with: self)
|
||||||
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
|
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
|
||||||
}
|
}
|
||||||
|
@@ -2,7 +2,10 @@ import 'dart:io';
|
|||||||
|
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'package:dio/io.dart';
|
import 'package:dio/io.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:pixes/foundation/app.dart';
|
||||||
import 'package:pixes/foundation/log.dart';
|
import 'package:pixes/foundation/log.dart';
|
||||||
|
import 'package:pixes/utils/ext.dart';
|
||||||
|
|
||||||
export 'package:dio/dio.dart';
|
export 'package:dio/dio.dart';
|
||||||
|
|
||||||
@@ -121,13 +124,34 @@ class AppDio extends DioForNative {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setSystemProxy() {
|
void setSystemProxy() {
|
||||||
HttpOverrides.global = _ProxyHttpOverrides();
|
HttpOverrides.global = _ProxyHttpOverrides()
|
||||||
|
..findProxy(Uri());
|
||||||
}
|
}
|
||||||
|
|
||||||
class _ProxyHttpOverrides extends HttpOverrides {
|
class _ProxyHttpOverrides extends HttpOverrides {
|
||||||
|
String proxy = "DIRECT";
|
||||||
|
|
||||||
String findProxy(Uri uri) {
|
String findProxy(Uri uri) {
|
||||||
// TODO: proxy
|
if(!App.isLinux) {
|
||||||
return "DIRECT";
|
var channel = const MethodChannel("pixes/proxy");
|
||||||
|
channel.invokeMethod("getProxy").then((value) {
|
||||||
|
if(value == "No proxy"){
|
||||||
|
proxy = "DIRECT";
|
||||||
|
} else {
|
||||||
|
if(proxy.contains("https")){
|
||||||
|
var proxies = value.split(";");
|
||||||
|
for (String proxy in proxies) {
|
||||||
|
proxy = proxy.removeAllBlank;
|
||||||
|
if (proxy.startsWith('https=')) {
|
||||||
|
value = proxy.substring(6);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
proxy = "PROXY $value";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return proxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
import Cocoa
|
import Cocoa
|
||||||
import FlutterMacOS
|
import FlutterMacOS
|
||||||
|
import IOKit.ps
|
||||||
|
|
||||||
class MainFlutterWindow: NSWindow {
|
class MainFlutterWindow: NSWindow {
|
||||||
override func awakeFromNib() {
|
override func awakeFromNib() {
|
||||||
@@ -8,6 +9,22 @@ class MainFlutterWindow: NSWindow {
|
|||||||
self.contentViewController = flutterViewController
|
self.contentViewController = flutterViewController
|
||||||
self.setFrame(windowFrame, display: true)
|
self.setFrame(windowFrame, display: true)
|
||||||
|
|
||||||
|
let proxyChannel = FlutterMethodChannel(
|
||||||
|
name: "pixes/proxy",
|
||||||
|
binaryMessenger: flutterViewController.engine.binaryMessenger)
|
||||||
|
proxyChannel.setMethodCallHandler { (call, result) in
|
||||||
|
// 获取代理设置
|
||||||
|
if let proxySettings = CFNetworkCopySystemProxySettings()?.takeUnretainedValue() as NSDictionary?,
|
||||||
|
let dict = proxySettings.object(forKey: kCFNetworkProxiesHTTPProxy) as? NSDictionary,
|
||||||
|
let host = dict.object(forKey: kCFNetworkProxiesHTTPProxy) as? String,
|
||||||
|
let port = dict.object(forKey: kCFNetworkProxiesHTTPPort) as? Int {
|
||||||
|
let proxyConfig = "\(host):\(port)"
|
||||||
|
result(proxyConfig)
|
||||||
|
} else {
|
||||||
|
result("No proxy")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
RegisterGeneratedPlugins(registry: flutterViewController)
|
RegisterGeneratedPlugins(registry: flutterViewController)
|
||||||
|
|
||||||
super.awakeFromNib()
|
super.awakeFromNib()
|
||||||
|
@@ -4,5 +4,11 @@
|
|||||||
<dict>
|
<dict>
|
||||||
<key>com.apple.security.app-sandbox</key>
|
<key>com.apple.security.app-sandbox</key>
|
||||||
<true/>
|
<true/>
|
||||||
|
<key>com.apple.security.files.user-selected.read-write</key>
|
||||||
|
<true/>
|
||||||
|
<key>com.apple.security.network.client</key>
|
||||||
|
<true/>
|
||||||
|
<key>com.apple.security.network.server</key>
|
||||||
|
<true/>
|
||||||
</dict>
|
</dict>
|
||||||
</plist>
|
</plist>
|
||||||
|
Reference in New Issue
Block a user