Skip to content
This repository has been archived by the owner on Jul 26, 2024. It is now read-only.

Commit

Permalink
将 LittleServer 重命名为 IntegratedServer,配置文件名不变,新增两个图标,1.2.0-STABLE
Browse files Browse the repository at this point in the history
  • Loading branch information
KasumiNova committed Sep 28, 2022
1 parent 39e37bd commit 541e7c5
Show file tree
Hide file tree
Showing 18 changed files with 103 additions and 92 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

group 'github.kasuminova'
version '1.2.0-STABLE-PREVIEW_4'
version '1.2.0-STABLE'


repositories {
Expand Down
74 changes: 37 additions & 37 deletions src/main/java/github/kasuminova/balloonserver/BalloonServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import github.kasuminova.balloonserver.GUI.LayoutManager.VFlowLayout;
import github.kasuminova.balloonserver.GUI.Panels.AboutPanel;
import github.kasuminova.balloonserver.GUI.Panels.SettingsPanel;
import github.kasuminova.balloonserver.Servers.AbstractLittleServer;
import github.kasuminova.balloonserver.Servers.LegacyLittleServer;
import github.kasuminova.balloonserver.Servers.LittleServer;
import github.kasuminova.balloonserver.Servers.LittleServerInterface;
import github.kasuminova.balloonserver.Servers.AbstractIntegratedServer;
import github.kasuminova.balloonserver.Servers.LegacyIntegratedServer;
import github.kasuminova.balloonserver.Servers.IntegratedServer;
import github.kasuminova.balloonserver.Servers.IntegratedServerInterface;
import github.kasuminova.balloonserver.UpdateChecker.ApplicationVersion;
import github.kasuminova.balloonserver.UpdateChecker.Checker;
import github.kasuminova.balloonserver.Utils.FileUtil;
Expand Down Expand Up @@ -46,7 +46,7 @@ public class BalloonServer {
//设置全局主题,字体等
SetupSwing.init();
}
public static final ApplicationVersion VERSION = new ApplicationVersion("1.2.0-STABLE-PREVIEW_4");
public static final ApplicationVersion VERSION = new ApplicationVersion("1.2.0-STABLE");
/*
可执行文件名称。
如 BalloonServer-GUI-1.2.0-STABLE.jar,
Expand All @@ -72,7 +72,7 @@ public class BalloonServer {
public static final JPanel mainPanel = new JPanel(new BorderLayout());
public static final BalloonServerConfig CONFIG = new BalloonServerConfig();
//可用服务端接口列表,与 Tab 同步
public static final List<LittleServerInterface> availableCustomServerInterfaces = Collections.synchronizedList(new ArrayList<>());
public static final List<IntegratedServerInterface> availableCustomServerInterfaces = Collections.synchronizedList(new ArrayList<>());
//支持放入多个任务的 Timer
public static final Timer GLOBAL_QUERY_TIMER = new Timer(false);
private static void init() {
Expand All @@ -93,7 +93,7 @@ private static void init() {
JPanel subMainPanel = new JPanel(new BorderLayout());
subMainPanel.add(SERVER_TABBED_PANE, BorderLayout.CENTER);

TABBED_PANE.addTab("服务端列表", SERVER_LIST_ICON, subMainPanel);
TABBED_PANE.addTab("服务端实例列表", SERVER_LIST_ICON, subMainPanel);
TABBED_PANE.addTab("主程序控制面板", SETTINGS_ICON, SettingsPanel.getPanel());
TABBED_PANE.addTab("关于本程序", ABOUT_ICON, AboutPanel.createPanel());

Expand All @@ -107,7 +107,7 @@ private static void init() {
return;
}
//定义变量
LittleServerInterface serverInterface = availableCustomServerInterfaces.get(tabIndex);
IntegratedServerInterface serverInterface = availableCustomServerInterfaces.get(tabIndex);
String serverName = serverInterface.getServerName();
if (!stopLittleServer(serverInterface, serverName, tabIndex, true)) return;

Expand All @@ -119,13 +119,13 @@ private static void init() {
SERVER_TABBED_PANE.putClientProperty("JTabbedPane.scrollButtonsPlacement", "both");

Thread serverThread = new Thread(() -> {
AbstractLittleServer abstractLittleServer;
AbstractIntegratedServer abstractIntegratedServer;
//自动启动服务器检测
if (CONFIG.isAutoStartServer()) {
abstractLittleServer = new LittleServer("littleserver", true);
abstractIntegratedServer = new IntegratedServer("littleserver", true);
//自动启动服务器(仅本次)
} else if (CONFIG.isAutoStartServerOnce()) {
abstractLittleServer = new LittleServer("littleserver", true);
abstractIntegratedServer = new IntegratedServer("littleserver", true);

CONFIG.setAutoStartServerOnce(false);

Expand All @@ -136,14 +136,14 @@ private static void init() {
GLOBAL_LOGGER.warning("保存主程序配置文件失败!");
}
} else {
abstractLittleServer = new LittleServer("littleserver", false);
abstractIntegratedServer = new IntegratedServer("littleserver", false);
}
SERVER_TABBED_PANE.addTab("主服务端 (4.1.15+)", DEFAULT_SERVER_ICON, abstractLittleServer.getPanel());
availableCustomServerInterfaces.add(abstractLittleServer.getServerInterface());
SERVER_TABBED_PANE.addTab("集成服务端 (4.1.15+)", DEFAULT_SERVER_ICON, abstractIntegratedServer.getPanel());
availableCustomServerInterfaces.add(abstractIntegratedServer.getServerInterface());

abstractLittleServer = new LegacyLittleServer("littleserver_legacy", false);
availableCustomServerInterfaces.add(abstractLittleServer.getServerInterface());
SERVER_TABBED_PANE.addTab("旧版服务端 (4.x.x - 4.1.14)", DEFAULT_SERVER_ICON, abstractLittleServer.getPanel());
abstractIntegratedServer = new LegacyIntegratedServer("littleserver_legacy", false);
availableCustomServerInterfaces.add(abstractIntegratedServer.getServerInterface());
SERVER_TABBED_PANE.addTab("旧版集成服务端 (4.x.x)", DEFAULT_SERVER_ICON, abstractIntegratedServer.getPanel());
});
serverThread.start();

Expand Down Expand Up @@ -210,7 +210,7 @@ public void run() {
public static void stopAllServers(boolean inquireUser) {
//停止所有运行的实例
for (int i = 0; i < availableCustomServerInterfaces.size(); i++) {
LittleServerInterface serverInterface = availableCustomServerInterfaces.get(i);
IntegratedServerInterface serverInterface = availableCustomServerInterfaces.get(i);
stopLittleServer(serverInterface, serverInterface.getServerName(), i, inquireUser);
if (i != 0) {
SERVER_TABBED_PANE.removeTabAt(i);
Expand Down Expand Up @@ -269,7 +269,7 @@ private static void loadMenuBar() {
newMenu.setIcon(PLUS_ICON);
menuBar.add(newMenu);

JMenuItem createNewLittleServer = new JMenuItem("创建更新服务端实例 (兼容 4.1.15+ 版本客户端)", PLUS_ICON);
JMenuItem createNewLittleServer = new JMenuItem("创建集成服务端实例 (兼容 4.1.15+ 版本客户端)", PLUS_ICON);
newMenu.add(createNewLittleServer);
createNewLittleServer.addActionListener(e -> {
String serverName = JOptionPane.showInputDialog(MAIN_FRAME,"请输入服务器实例名称","创建",JOptionPane.INFORMATION_MESSAGE);
Expand All @@ -285,9 +285,9 @@ private static void loadMenuBar() {

GLOBAL_THREAD_POOL.execute(() -> {
long start = System.currentTimeMillis();
GLOBAL_LOGGER.info(String.format("正在创建新的服务器实例:%s", serverName));
GLOBAL_LOGGER.info(String.format("正在创建新的集成服务端实例:%s", serverName));

LittleServer customServer = new LittleServer(serverName, false);
IntegratedServer customServer = new IntegratedServer(serverName, false);

availableCustomServerInterfaces.add(customServer.getServerInterface());
SERVER_TABBED_PANE.addTab(serverName, CUSTOM_SERVER_ICON, customServer.getPanel());
Expand All @@ -297,10 +297,10 @@ private static void loadMenuBar() {
});
});

JMenuItem createNewLegacyLittleServer = new JMenuItem("创建旧版更新服务端实例 (兼容 4.x.x - 4.1.14 版本客户端)", PLUS_ICON);
JMenuItem createNewLegacyLittleServer = new JMenuItem("创建旧版集成服务端实例 (兼容 4.x.x 版本客户端)", PLUS_ICON);
newMenu.add(createNewLegacyLittleServer);
createNewLegacyLittleServer.addActionListener(e -> {
String serverName = JOptionPane.showInputDialog(MAIN_FRAME,"请输入服务器实例名称","创建",JOptionPane.INFORMATION_MESSAGE);
String serverName = JOptionPane.showInputDialog(MAIN_FRAME,"请输入服务端实例名称","创建",JOptionPane.INFORMATION_MESSAGE);
if (Security.stringIsUnsafe(MAIN_FRAME, serverName, new String[]{"balloonserver","littleserver","res-cache",".lscfg",".json"})) return;

if (new File(String.format("./%s.legacy.lscfg.json", serverName)).exists() || new File(String.format("./%s.lscfg.json", serverName)).exists()) {
Expand All @@ -314,9 +314,9 @@ private static void loadMenuBar() {

GLOBAL_THREAD_POOL.execute(() -> {
long start = System.currentTimeMillis();
GLOBAL_LOGGER.info(String.format("正在创建新的服务器实例:%s", serverName));
GLOBAL_LOGGER.info(String.format("正在创建新的集成服务端实例:%s", serverName));

LegacyLittleServer customServer = new LegacyLittleServer(serverName, false);
LegacyIntegratedServer customServer = new LegacyIntegratedServer(serverName, false);

availableCustomServerInterfaces.add(customServer.getServerInterface());
SERVER_TABBED_PANE.addTab(serverName, CUSTOM_SERVER_ICON, customServer.getPanel());
Expand All @@ -330,7 +330,7 @@ private static void loadMenuBar() {
loadMenu.setIcon(RESOURCE_ICON);
menuBar.add(loadMenu);

JMenuItem loadLittleServer = new JMenuItem("载入更新服务器实例", PLAY_ICON);
JMenuItem loadLittleServer = new JMenuItem("载入集成服务端实例", PLAY_ICON);
loadMenu.add(loadLittleServer);
loadLittleServer.addActionListener(e -> {
JFileChooser fileChooser = new JFileChooser(".");
Expand All @@ -348,7 +348,7 @@ private static void loadMenuBar() {
serverNames[i] = selectedFiles[i].getName().replace(".lscfg.json", "");
}

AbstractLittleServer[] customServers = new AbstractLittleServer[serverNames.length];
AbstractIntegratedServer[] customServers = new AbstractIntegratedServer[serverNames.length];
ArrayList<Thread> threadList = new ArrayList<>();
//检查是否存在非法名称或已存在的名称
for (String serverName : serverNames) {
Expand All @@ -366,12 +366,12 @@ private static void loadMenuBar() {
int panelArrayIndex = i;
Thread thread = new Thread(() -> {
long start = System.currentTimeMillis();
GLOBAL_LOGGER.info(String.format("正在载入服务器实例:%s", serverName));
AbstractLittleServer customServer;
GLOBAL_LOGGER.info(String.format("正在载入集成服务端实例:%s", serverName));
AbstractIntegratedServer customServer;
if (serverName.endsWith(".legacy")) {
customServer = new LegacyLittleServer(serverName.replace(".legacy", ""), false);
customServer = new LegacyIntegratedServer(serverName.replace(".legacy", ""), false);
} else {
customServer = new LittleServer(serverName, false);
customServer = new IntegratedServer(serverName, false);
}
customServers[panelArrayIndex] = customServer;
GLOBAL_LOGGER.info(String.format("实例载入耗时 %sms.", System.currentTimeMillis() - start));
Expand Down Expand Up @@ -399,21 +399,21 @@ private static void loadMenuBar() {
SERVER_TABBED_PANE.setSelectedIndex(SERVER_TABBED_PANE.getTabCount() - 1);
});

JMenuItem resetLittleServer = new JMenuItem("重置当前显示的服务器实例", RELOAD_ICON);
JMenuItem resetLittleServer = new JMenuItem("重置当前显示的集成服务端实例", RELOAD_ICON);
loadMenu.add(resetLittleServer);
resetLittleServer.addActionListener(e -> {
int selected = SERVER_TABBED_PANE.getSelectedIndex();
//定义变量
LittleServerInterface serverInterface = availableCustomServerInterfaces.get(selected);
IntegratedServerInterface serverInterface = availableCustomServerInterfaces.get(selected);
String serverName = serverInterface.getServerName();

if (stopLittleServer(serverInterface, serverName, selected, true)) {
GLOBAL_THREAD_POOL.execute(() -> {
LittleServer littleServer;
IntegratedServer littleServer;
if (serverName.equals("littleserver")) {
littleServer = new LittleServer("littleserver", false);
littleServer = new IntegratedServer("littleserver", false);
} else {
littleServer = new LittleServer(serverName, false);
littleServer = new IntegratedServer(serverName, false);
}
availableCustomServerInterfaces.set(selected, littleServer.getServerInterface());
SERVER_TABBED_PANE.setComponentAt(selected, littleServer.getPanel());
Expand All @@ -434,7 +434,7 @@ private static void loadMenuBar() {
* @param inquireUser 是否向用户确认关闭服务端
* @return 用户是否确认关闭了服务器
*/
private static boolean stopLittleServer(LittleServerInterface serverInterface, String serverName, int index, boolean inquireUser) {
private static boolean stopLittleServer(IntegratedServerInterface serverInterface, String serverName, int index, boolean inquireUser) {
boolean isStarted = serverInterface.isStarted().get();
//如果服务器已启动,则提示是否关闭服务器
if (isStarted) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
* @author Kasumi_Nova
*/
public class ConfigurationManager {
public static void loadLittleServerConfigFromFile(String path, LittleServerConfig oldConfig) throws IOException {
LittleServerConfig newConfig = JSON.parseObject(Files.newInputStream(Paths.get(path)), LittleServerConfig.class);
public static void loadLittleServerConfigFromFile(String path, IntegratedServerConfig oldConfig) throws IOException {
IntegratedServerConfig newConfig = JSON.parseObject(Files.newInputStream(Paths.get(path)), IntegratedServerConfig.class);

oldConfig.setConfigVersion(newConfig.getConfigVersion());
oldConfig.setIp(newConfig.getIp());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package github.kasuminova.balloonserver.Configurations;

public class LittleServerConfig extends Configuration {
public class IntegratedServerConfig extends Configuration {
private String ip = "127.0.0.1";
private int port = 8080;
private String mainDirPath = "/res";
Expand All @@ -9,7 +9,7 @@ public class LittleServerConfig extends Configuration {
private String jksSslPassword = "";
private String[] commonMode = new String[0];
private String[] onceMode = new String[0];
public LittleServerConfig() {
public IntegratedServerConfig() {
configVersion = 1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static JPanel createPanel() {
descPanel.setBorder(new EmptyBorder(10,0,0,0));
descPanel.add(new JLabel("BalloonServer 是 LittleServer 的完全图形化版本, 基于 Netty-IO 的增强实现.", JLabel.CENTER));
descPanel.add(new JLabel("提示:BalloonServer 内嵌了可视化更新规则编辑器, 你可以通过右键更新模式列表打开.", JLabel.CENTER));
descPanel.add(new JLabel("提示:关闭程序窗口并不会关闭程序, 而是会最小化到托盘.", JLabel.CENTER));
descPanel.add(new JLabel("提示:BalloonServer 支持启动多个服务端, 你可以使用窗口左上角菜单来管理多个实例.", JLabel.CENTER));
//链接
JPanel linkPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 10,5));
//仓库链接
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

import static github.kasuminova.balloonserver.BalloonServer.CONFIG;
import static github.kasuminova.balloonserver.BalloonServer.stopAllServers;
import static github.kasuminova.balloonserver.Utils.SvgIcons.STOP_ICON;
import static github.kasuminova.balloonserver.Utils.SvgIcons.TERMINAL_ICON;

/**
* 中文系统托盘弹出菜单不乱码。
Expand Down Expand Up @@ -52,7 +54,7 @@ public void firePopupMenuWillBecomeInvisible() {
jPopupMenu.setSize(100, 30);

//添加菜单选项
JMenuItem exit = new JMenuItem("退出程序");
JMenuItem exit = new JMenuItem("退出程序", STOP_ICON);
exit.addActionListener(e -> {
try {
ConfigurationManager.saveConfigurationToFile(CONFIG, "./", "balloonserver");
Expand All @@ -64,7 +66,7 @@ public void firePopupMenuWillBecomeInvisible() {
stopAllServers(true);
System.exit(0);
});
JMenuItem showMainFrame = new JMenuItem("显示窗口");
JMenuItem showMainFrame = new JMenuItem("显示窗口", TERMINAL_ICON);
showMainFrame.addActionListener(e -> {
//显示窗口
frame.setVisible(true);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package github.kasuminova.balloonserver.HTTPServer;

import com.alibaba.fastjson2.JSONObject;
import github.kasuminova.balloonserver.Configurations.LittleServerConfig;
import github.kasuminova.balloonserver.Configurations.IntegratedServerConfig;
import github.kasuminova.balloonserver.GUI.LayoutManager.VFlowLayout;
import github.kasuminova.balloonserver.Servers.LittleServerInterface;
import github.kasuminova.balloonserver.Servers.IntegratedServerInterface;
import github.kasuminova.balloonserver.Utils.FileUtil;
import github.kasuminova.balloonserver.Utils.GUILogger;
import github.kasuminova.balloonserver.Utils.HashCalculator;
Expand All @@ -29,11 +29,11 @@

public class HttpRequestHandler extends SimpleChannelInboundHandler<FullHttpRequest> {
private final String resJson;
private final LittleServerConfig config;
private final IntegratedServerConfig config;
private final GUILogger logger;
private final JPanel requestListPanel;
private final String hashAlgorithm;
public HttpRequestHandler(LittleServerInterface serverInterface) {
public HttpRequestHandler(IntegratedServerInterface serverInterface) {
this.resJson = serverInterface.getResJson();
this.config = serverInterface.getConfig();
this.logger = serverInterface.getLogger();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package github.kasuminova.balloonserver.HTTPServer;

import github.kasuminova.balloonserver.Configurations.LittleServerConfig;
import github.kasuminova.balloonserver.Servers.LittleServerInterface;
import github.kasuminova.balloonserver.Configurations.IntegratedServerConfig;
import github.kasuminova.balloonserver.Servers.IntegratedServerInterface;
import github.kasuminova.balloonserver.Utils.FileListener;
import github.kasuminova.balloonserver.Utils.FileListener.FileMonitor;
import github.kasuminova.balloonserver.Utils.GUILogger;
Expand Down Expand Up @@ -29,14 +29,14 @@ public class HttpServer {
private final GUILogger logger;
private final AtomicBoolean isGenerating;
private final AtomicBoolean isFileChanged = new AtomicBoolean(false);
private final LittleServerConfig config;
private final IntegratedServerConfig config;
private final AtomicBoolean isStarted;
private final LittleServerInterface serverInterface;
private final IntegratedServerInterface serverInterface;
/**
* 新建一个 HTTP 服务器实例
* @param serverInterface 服务器实例接口
*/
public HttpServer(LittleServerInterface serverInterface) {
public HttpServer(IntegratedServerInterface serverInterface) {
this.serverInterface = serverInterface;

this.logger = serverInterface.getLogger();
Expand Down
Loading

0 comments on commit 541e7c5

Please sign in to comment.