Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/abc123lzf/flyingsocks int…
Browse files Browse the repository at this point in the history
…o v3.0

� Conflicts:
�	client/src/main/java/com/lzf/flyingsocks/client/proxy/http/HttpProxyConfig.java
  • Loading branch information
abc123lzf committed Jun 5, 2021
2 parents af2e767 + 26815e4 commit 4da8a60
Show file tree
Hide file tree
Showing 20 changed files with 220 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ public interface ClientOperator {
*/
void updateHttpProxyConfig(boolean open, int port, boolean auth, String username, String password);

/**
* 打开Windows系统代理
*/
void setupWindowsSystemProxy(boolean open);


/**
* @return 系统代理模式
*/
Expand Down
18 changes: 10 additions & 8 deletions client/src/main/java/com/lzf/flyingsocks/client/GlobalConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,16 @@ public class GlobalConfig extends AbstractConfig {
*/
@Override
protected void initInternal() throws ConfigInitializationException {
String location;

if (configManager.isWindows()) {
location = configManager.getSystemProperties("config.location.windows");
} else if (configManager.isMacOS()) {
location = configManager.getSystemProperties("config.location.mac");
} else {
location = configManager.getSystemProperties("config.location.linux");
String location = configManager.getSystemProperties("config.location");

if (location == null) {
if (configManager.isWindows()) {
location = configManager.getSystemProperties("config.location.windows");
} else if (configManager.isMacOS()) {
location = configManager.getSystemProperties("config.location.mac");
} else {
location = configManager.getSystemProperties("config.location.linux");
}
}

location = StringSubstitutor.replaceSystemProperties(location);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/
package com.lzf.flyingsocks.client;

import com.lzf.flyingsocks.Component;
import com.lzf.flyingsocks.ComponentException;
import com.lzf.flyingsocks.ConfigEvent;
import com.lzf.flyingsocks.ConfigEventListener;
Expand Down Expand Up @@ -98,7 +99,12 @@ protected void stopInternal() {
*/
@Override
protected void restartInternal() {
throw new ComponentException("can not restart client");
throw new ComponentException("Could not restart client");
}

@Override
protected void handleException(Component<?> component, Exception exception) {
exitWithNotify(1, "exitmsg.component_failure", component.getName(), exception.getMessage());
}

@Override
Expand Down Expand Up @@ -287,6 +293,15 @@ public void updateHttpProxyConfig(boolean open, int port, boolean auth, String u
}
}

@Override
public void setupWindowsSystemProxy(boolean open) {
ConfigManager<?> manager = getConfigManager();
HttpProxyConfig cfg = manager.getConfig(HttpProxyConfig.NAME, HttpProxyConfig.class);
if (cfg != null) {
cfg.enableWindowsSystemProxy(open);
}
}

@Override
public long queryProxyServerUploadThroughput(Node node) {
ProxyComponent pc = getComponentByName(ProxyComponent.NAME, ProxyComponent.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYAreaRenderer;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.RangeType;
import org.jfree.data.time.DynamicTimeSeriesCollection;
import org.jfree.data.time.Second;
Expand All @@ -36,6 +37,7 @@

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.Paint;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
Expand Down Expand Up @@ -79,8 +81,8 @@ public DynamicTimeSeriesChart(String title, String xAxisName, String yAxisName,
dataset.setTimeBase(new Second(DateUtils.addSeconds(new Date(), -interval)));
dataset.addSeries(new float[0], 0, "");

JFreeChart chart = ChartFactory.createTimeSeriesChart(title, xAxisName, yAxisName, dataset, false, false, false);

JFreeChart chart = ChartFactory.createTimeSeriesChart("", xAxisName, yAxisName, dataset, false, false, false);
chart.setTitle(new TextTitle(title, new Font("黑体", Font.PLAIN, 18)));
if (style == STYLE_BLUE) {
initialChartStyle(chart, Color.white, new Color(17, 125, 187),
new Color(217, 234, 244),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@
*/
public class HttpProxySettingModule extends AbstractModule<SWTViewComponent> {

public static final String NAME = HttpProxySettingModule.class.getSimpleName();

private final ClientOperator operator;

private final Shell shell;

HttpProxySettingModule(SWTViewComponent component) {
super(Objects.requireNonNull(component), "HttpProxySettingModule");
super(Objects.requireNonNull(component), NAME);
this.operator = component.getParentComponent();

Image icon;
Expand Down Expand Up @@ -177,7 +179,6 @@ private void initial() {
authCloseRadio.setSelection(true);
}


addButtonSelectionListener(cancelBtn, e -> {
if (operator.isHttpProxyOpen()) {
openRadio.setSelection(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
*/
final class MainScreenModule extends AbstractModule<SWTViewComponent> {

public static final String NAME = MainScreenModule.class.getSimpleName();

private static final DateTimeFormatter STATUS_TEXT_TIME_FORMAT = DateTimeFormatter.ofPattern("HH:mm:ss.SSS");

/**
Expand Down Expand Up @@ -118,7 +120,7 @@ final class MainScreenModule extends AbstractModule<SWTViewComponent> {


MainScreenModule(SWTViewComponent component) {
super(Objects.requireNonNull(component), "Main-Screen");
super(Objects.requireNonNull(component), NAME);
this.display = component.getDisplay();
this.operator = getComponent().getParentComponent();

Expand All @@ -127,13 +129,14 @@ final class MainScreenModule extends AbstractModule<SWTViewComponent> {
this.shell = shell;

this.statusTextArea = initStatusTextArea(shell);
this.uploadChart = new DynamicTimeSeriesChart("UPLOAD", "", "MB/s", 60, DynamicTimeSeriesChart.STYLE_PURPLE);
this.downloadChart = new DynamicTimeSeriesChart("DOWNLOAD", "", "MB/s", 60, DynamicTimeSeriesChart.STYLE_BLUE);
this.uploadChart = new DynamicTimeSeriesChart("上传", "", "MB/s", 60, DynamicTimeSeriesChart.STYLE_PURPLE);
this.downloadChart = new DynamicTimeSeriesChart("下载", "", "MB/s", 60, DynamicTimeSeriesChart.STYLE_BLUE);

this.uploadChartCanvas = initChartCanvas(this.uploadChart, 10, 270, CHART_WIDTH, CHART_HEIGHT);
this.downloadChartCanvas = initChartCanvas(this.downloadChart, 355, 270, CHART_WIDTH, CHART_HEIGHT);

this.serverList = initServerChooseList(shell);
appendStatusText("swtui.main.status.not_connect");
adaptDPI(shell);
setVisiable(false);
submitChartUpdateTask();
Expand Down Expand Up @@ -225,7 +228,6 @@ public void focusLost(FocusEvent e) {
}
});
this.connBtn = conn;
appendStatusText("swtui.main.status.not_connect");
changeConnBtn(false);
update();
operator.registerProxyServerConfigListener(Config.UPDATE_EVENT, this::update, false);
Expand Down Expand Up @@ -290,7 +292,7 @@ public void focusLost(FocusEvent e) {
}
}));
} else {
showMessageBox(shell, "提示", "请选择一个有效的服务器", SWT.ICON_INFORMATION | SWT.OK);
showMessageBox(shell, "swtui.main.notice.title", "swtui.main.notice.server_not_select", SWT.ICON_INFORMATION | SWT.OK);
}
}
});
Expand Down Expand Up @@ -321,10 +323,10 @@ private void update() {

private void changeConnBtn(boolean disconnect) {
if (disconnect) {
connBtn.setText("断开连接");
connBtn.setText(i18n("swtui.main.button.disconnect"));
this.disconnect = true;
} else {
connBtn.setText("连接");
connBtn.setText(i18n("swtui.main.button.connect"));
this.disconnect = false;
}
}
Expand All @@ -345,8 +347,24 @@ void setVisiable(boolean visible) {


private void appendStatusText(String text) {
StringBuilder sb = new StringBuilder(35);

LocalTime time = LocalTime.now();
String str = "【" + STATUS_TEXT_TIME_FORMAT.format(time) + "】" + i18n(text) + Text.DELIMITER;
sb.append('<').append(STATUS_TEXT_TIME_FORMAT.format(time)).append('>');

Node selectNode = serverList.selectNode();
sb.append('[');
if (selectNode == null) {
sb.append("NONE");
} else {
sb.append(selectNode.getHost()).append(':').append(selectNode.getPort());
}
sb.append("] ");

sb.append(i18n(text));
sb.append(Text.DELIMITER);

String str = sb.toString();
if (statusTextArea.getLineCount() > 5000) {
statusTextArea.setText(str);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,6 @@ public class SWTViewComponent extends AbstractComponent<Client> {

private final Display display;

/**
* Socks代理设置页面
*/
private SocksSettingModule socksSettingModule;

/**
* 服务器设置页面
*/
private ServerSettingModule serverSettingModule;

/**
* 主界面
*/
private MainScreenModule mainScreenModule;

/**
* HTTP代理设置页面
*/
private HttpProxySettingModule httpProxySettingModule;


public SWTViewComponent(Client parent) {
super("SWTViewComponent", Objects.requireNonNull(parent));

Expand All @@ -80,10 +59,10 @@ public SWTViewComponent(Client parent) {
protected void initInternal() {
try {
addModule(new TrayModule(this));
addModule(this.serverSettingModule = new ServerSettingModule(this));
addModule(this.socksSettingModule = new SocksSettingModule(this));
addModule(this.mainScreenModule = new MainScreenModule(this));
addModule(this.httpProxySettingModule = new HttpProxySettingModule(this));
addModule(new ServerSettingModule(this));
addModule(new SocksSettingModule(this));
addModule(new MainScreenModule(this));
addModule(new HttpProxySettingModule(this));
} catch (Throwable t) {
log.error("SWT Thread occur a error", t);
Client.exitWithNotify(1, "exitmsg.swt_view.init_failure", t.getMessage());
Expand Down Expand Up @@ -114,19 +93,19 @@ Display getDisplay() {
}

void openSocksSettingUI() {
socksSettingModule.setVisiable(true);
getModuleByName(SocksSettingModule.NAME, SocksSettingModule.class).setVisiable(true);
}

void openServerSettingUI() {
serverSettingModule.setVisiable(true);
getModuleByName(ServerSettingModule.NAME, ServerSettingModule.class).setVisiable(true);
}

void openMainScreenUI() {
mainScreenModule.setVisiable(true);
getModuleByName(MainScreenModule.NAME, MainScreenModule.class).setVisiable(true);
}

void openHttpProxySettingUI() {
httpProxySettingModule.setVisiable(true);
getModuleByName(HttpProxySettingModule.NAME, HttpProxySettingModule.class).setVisiable(true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
*/
final class ServerSettingModule extends AbstractModule<SWTViewComponent> {

public static final String NAME = ServerSettingModule.class.getSimpleName();

private static final Logger log = LoggerFactory.getLogger("ServerSettingUI");

private final Display display;
Expand All @@ -71,7 +73,7 @@ final class ServerSettingModule extends AbstractModule<SWTViewComponent> {
private final ServerSettingForm serverSettingForm;

ServerSettingModule(SWTViewComponent component) {
super(Objects.requireNonNull(component));
super(Objects.requireNonNull(component), NAME);
this.display = component.getDisplay();
this.operator = component.getParentComponent();

Expand Down Expand Up @@ -375,6 +377,9 @@ void setEncrypt(EncryptType type) {
case SSL:
encrypt.select(1);
break;
case SSL_CA:
encrypt.select(2);
break;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@
*/
final class SocksSettingModule extends AbstractModule<SWTViewComponent> {

public static final String NAME = SocksSettingModule.class.getSimpleName();

private final ClientOperator operator;

private final Shell shell;

SocksSettingModule(SWTViewComponent component) {
super(Objects.requireNonNull(component));
super(Objects.requireNonNull(component), NAME);
this.operator = component.getParentComponent();

Image icon;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.lzf.flyingsocks.client.ClientOperator;
import com.lzf.flyingsocks.client.gui.ResourceManager;

import com.lzf.flyingsocks.client.proxy.http.HttpProxyConfig;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
Expand Down Expand Up @@ -81,6 +82,10 @@ private void initial() {
//PAC设置菜单
initialPacMenu(shell, menu);

if (supportWindowsSystemProxy()) {
initialWindowsSystemProxyMenu(shell, menu);
}

createMenuItem(menu, "swtui.tray.item.server_config_ui", e -> belongComponent.openServerSettingUI());
createMenuSeparator(menu);
createMenuItem(menu, "swtui.tray.item.socks5_config_ui", e -> belongComponent.openSocksSettingUI());
Expand Down Expand Up @@ -182,4 +187,45 @@ private void initialAboutMenu(Shell shell, Menu main) {
createCascadeMenuItem(about, "swtui.tray.item.help.open_issue", e -> operator.openBrowser(ISSUE_PAGE));
}


private void initialWindowsSystemProxyMenu(Shell shell, Menu main) {
MenuItem mi = new MenuItem(main, SWT.CASCADE);
mi.setText(i18n("swtui.tray.item.wsp_proxy"));
Menu menu = new Menu(shell, SWT.DROP_DOWN);
mi.setMenu(menu);

MenuItem open = new MenuItem(menu, SWT.CASCADE ^ SWT.CHECK);
MenuItem close = new MenuItem(menu, SWT.CASCADE ^ SWT.CHECK);
open.setText(i18n("swtui.http.form.button.wsp_open"));
close.setText(i18n("swtui.http.form.button.wsp_close"));

HttpProxyConfig cfg = operator.getHttpProxyConfig();
if (cfg.isEnableWindowsSystemProxy()) {
open.setSelection(true);
} else {
close.setSelection(true);
}

addMenuItemSelectionListener(open, e -> {
open.setSelection(true);
close.setSelection(false);
operator.setupWindowsSystemProxy(true);
});

addMenuItemSelectionListener(close, e -> {
open.setSelection(false);
close.setSelection(true);
operator.setupWindowsSystemProxy(false);
});
}


private boolean supportWindowsSystemProxy() {
HttpProxyConfig cfg = operator.getHttpProxyConfig();
if (cfg == null) {
return false;
}
return cfg.supportWindowsSystemProxy();
}

}
Loading

0 comments on commit 4da8a60

Please sign in to comment.