diff --git a/assets/linux/aohe-sane-service.png b/assets/linux/aohe-sane-service.png
new file mode 100644
index 0000000..79b2293
Binary files /dev/null and b/assets/linux/aohe-sane-service.png differ
diff --git a/pom.xml b/pom.xml
index 4a231ae..1946363 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
org.aohe
sane-service
- 0.2.6
+ 0.3.1
aohe-sane-service
@@ -145,6 +145,8 @@
true
false
linux
+ 奥诃影像扫描控件
+ 奥诃公司为影像 WEB 应用开发的 USB 扫描仪连接驱动,请搭配 WEB 产品使用。
true
true
diff --git a/src/main/java/org/aohe/Main.java b/src/main/java/org/aohe/Main.java
index c019468..e20a0a7 100644
--- a/src/main/java/org/aohe/Main.java
+++ b/src/main/java/org/aohe/Main.java
@@ -1,12 +1,12 @@
package org.aohe;
+import com.formdev.flatlaf.FlatDarculaLaf;
import lombok.extern.slf4j.Slf4j;
import org.aohe.core.sane.utils.SaneSessionUtils;
-import org.aohe.core.swing.MainWindow;
+import org.aohe.core.swing.NewWindow;
import org.aohe.core.utils.CommandUtils;
import org.aohe.core.utils.SystemUtils;
import org.aohe.core.web.SocketFactory;
-import com.formdev.flatlaf.FlatLightLaf;
import javax.swing.*;
@@ -18,13 +18,13 @@ public class Main {
try {
//设置窗口主题
//FlatLightLaf.setup();
- UIManager.setLookAndFeel(new FlatLightLaf());
+ UIManager.setLookAndFeel(new FlatDarculaLaf());
} catch (UnsupportedLookAndFeelException e) {
throw new RuntimeException(e);
}
//初始化其他资源
init();
- SwingUtilities.invokeLater(() -> new MainWindow().setVisible(true));
+ SwingUtilities.invokeLater(() -> new NewWindow().setVisible(true));
}
@@ -47,4 +47,6 @@ public class Main {
log.info("socket 服务已关闭 ");
}));
}
+
+
}
\ No newline at end of file
diff --git a/src/main/java/org/aohe/core/swing/NewWindow.java b/src/main/java/org/aohe/core/swing/NewWindow.java
new file mode 100644
index 0000000..a5a34f4
--- /dev/null
+++ b/src/main/java/org/aohe/core/swing/NewWindow.java
@@ -0,0 +1,127 @@
+package org.aohe.core.swing;
+
+import lombok.extern.slf4j.Slf4j;
+import org.aohe.core.web.SocketFactory;
+
+import javax.swing.*;
+import java.awt.*;
+
+@Slf4j
+public class NewWindow extends JFrame {
+
+ private static JTextArea logTextArea;
+
+ private static final JLabel textField = new JLabel();
+
+ public NewWindow() {
+ // 设置窗口标题
+ setTitle("扫描前端");
+
+ // 设置默认的关闭操作
+ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+
+ // 设置窗口大小
+ setSize(400, 300);
+
+ // 居中显示窗口
+ setLocationRelativeTo(null);
+
+ // 初始化UI组件
+ initializeComponents();
+ }
+
+ private void initializeComponents() {
+
+ textField.setForeground(Color.GRAY);
+ textField.setText("服务状态:启动中...");
+
+ //初始化连接服务
+ initSocket();
+
+ // 示例:添加一个按钮,点击时向文本区域添加日志信息
+ JButton stopButton = new JButton("退出");
+ stopButton.setEnabled(true);
+ stopButton.addActionListener(e -> {
+ stopButton.setEnabled(false);
+ logTextArea.append("关闭服务中...\n");
+ //开个新线程关闭,防止主UI线程卡死
+ new Thread( () ->{
+ stopSocket();
+ //关闭任务
+ sleep(1000);
+ textField.setForeground(Color.RED);
+ textField.setText("服务状态:关闭");
+ sleep(100);
+ System.exit(0);
+ } ).start();
+ });
+
+ getContentPane().add(textField, BorderLayout.NORTH);
+
+ getContentPane().add(stopButton, BorderLayout.SOUTH);
+
+ }
+
+ public void setView(String view){
+ getLogTextArea().append(view + "\n");
+ }
+
+ public void initSocket() {
+ if(SocketFactory.start()){
+ setView("socket 服务启动成功");
+ textField.setForeground(Color.GREEN);
+ textField.setText("服务状态:启动");
+ }else{
+ setView("socket 服务启动失败");
+ setView("请检查8997端口是否被占用,或是否重复打开此程序");
+ setView("应用退出中...");
+ new Thread( () -> {
+ sleep(5000);
+ System.exit(0);
+ } ).start();
+ }
+ }
+
+ public void stopSocket() {
+ try {
+ if(SocketFactory.stop()){
+ setView("服务停止成功");
+ }else{
+ setView("服务停止失败");
+ }
+ Thread.sleep(1000);
+ log.info("服务关闭");
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public JTextArea getLogTextArea(){
+ if(logTextArea == null){
+ initLogTextArea();
+ }
+ return logTextArea;
+ }
+
+ public void initLogTextArea(){
+ // 在这里添加你的组件初始化代码
+ // 创建一个JTextArea用于显示日志
+ logTextArea = new JTextArea();
+ logTextArea.setEditable(false); // 设置为不可编辑
+ logTextArea.setEnabled(false);
+
+ // 将JTextArea放入JScrollPane中以支持滚动
+ JScrollPane scrollPane = new JScrollPane(logTextArea);
+
+ // 将JScrollPane添加到窗口中
+ getContentPane().add(scrollPane, BorderLayout.CENTER);
+ }
+
+ public static void sleep(long m){
+ try {
+ Thread.sleep(m);
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
diff --git a/src/main/java/org/aohe/core/utils/CommandUtils.java b/src/main/java/org/aohe/core/utils/CommandUtils.java
index 955a6e5..616d05e 100644
--- a/src/main/java/org/aohe/core/utils/CommandUtils.java
+++ b/src/main/java/org/aohe/core/utils/CommandUtils.java
@@ -64,6 +64,7 @@ public class CommandUtils {
public static void killUsedPort(String port){
List lsofInfos = findPort(port);
for(LsofInfo lsofInfo : lsofInfos){
+ log.info(" pro kill begin {}", lsofInfo);
destroy(lsofInfo.getPid());
}
}
@@ -71,12 +72,14 @@ public class CommandUtils {
public static List findPort(String port){
String exec = StrUtil.format("lsof -i:{}",port);
String s = execForStrUtf8Sudo(exec);
+ log.info(s);
return parseCommandOutput(s);
}
public static void destroy(String pid){
String exec = StrUtil.format("kill -9 {}",pid);
- execForStrUtf8Sudo(exec);
+ String s = execForStrUtf8Sudo(exec);
+ log.info(s);
}
/**
diff --git a/src/main/java/org/aohe/core/web/SocketFactory.java b/src/main/java/org/aohe/core/web/SocketFactory.java
index 15a1b74..9dad715 100644
--- a/src/main/java/org/aohe/core/web/SocketFactory.java
+++ b/src/main/java/org/aohe/core/web/SocketFactory.java
@@ -3,6 +3,7 @@ package org.aohe.core.web;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
+import java.net.BindException;
import java.net.UnknownHostException;
/**
@@ -31,6 +32,7 @@ public class SocketFactory {
private static SocketServer getSocket() throws UnknownHostException {
log.info("Create Socket ...");
socketServer = new SocketServer(8997);
+ socketServer.setReuseAddr(true);
return socketServer;
}
@@ -40,7 +42,7 @@ public class SocketFactory {
public static boolean start() {
try {
getSocket().start();
- } catch (UnknownHostException e) {
+ } catch (Exception e){
return false;
}
log.info("socket 已启动");