Compare commits
8 Commits
Author | SHA1 | Date |
---|---|---|
|
38ee383033 | |
|
afea000336 | |
|
84fe5afc62 | |
|
23063b0d9c | |
|
b29961b0bf | |
|
b0701543b1 | |
|
c192fcf954 | |
|
bd95bbb11b |
12
pom.xml
12
pom.xml
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
<groupId>org.aohe</groupId>
|
<groupId>org.aohe</groupId>
|
||||||
<artifactId>sane-service</artifactId>
|
<artifactId>sane-service</artifactId>
|
||||||
<version>0.3.1</version>
|
<version>0.3.4</version>
|
||||||
|
|
||||||
<name>aohe-sane-service</name>
|
<name>aohe-sane-service</name>
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.java-websocket</groupId>
|
<groupId>org.java-websocket</groupId>
|
||||||
<artifactId>Java-WebSocket</artifactId>
|
<artifactId>Java-WebSocket</artifactId>
|
||||||
<version>1.5.3</version>
|
<version>1.5.6</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.formdev</groupId>
|
<groupId>com.formdev</groupId>
|
||||||
|
@ -71,6 +71,12 @@
|
||||||
<version>3.4.1</version>
|
<version>3.4.1</version>
|
||||||
<classifier>no-natives</classifier>
|
<classifier>no-natives</classifier>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.github.sanyarnd</groupId>
|
||||||
|
<artifactId>app-locker</artifactId>
|
||||||
|
<version>1.2.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- <dependency>-->
|
<!-- <dependency>-->
|
||||||
<!-- <groupId>com.formdev</groupId>-->
|
<!-- <groupId>com.formdev</groupId>-->
|
||||||
<!-- <artifactId>flatlaf</artifactId>-->
|
<!-- <artifactId>flatlaf</artifactId>-->
|
||||||
|
@ -148,7 +154,7 @@
|
||||||
<displayName>奥诃影像扫描控件</displayName>
|
<displayName>奥诃影像扫描控件</displayName>
|
||||||
<description>奥诃公司为影像 WEB 应用开发的 USB 扫描仪连接驱动,请搭配 WEB 产品使用。</description>
|
<description>奥诃公司为影像 WEB 应用开发的 USB 扫描仪连接驱动,请搭配 WEB 产品使用。</description>
|
||||||
<linuxConfig>
|
<linuxConfig>
|
||||||
<generateAppImage>true</generateAppImage>
|
<!-- <generateAppImage>true</generateAppImage>-->
|
||||||
<generateDeb>true</generateDeb>
|
<generateDeb>true</generateDeb>
|
||||||
<generateRpm>true</generateRpm>
|
<generateRpm>true</generateRpm>
|
||||||
<wrapJar>true</wrapJar>
|
<wrapJar>true</wrapJar>
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package org.aohe;
|
package org.aohe;
|
||||||
|
|
||||||
import com.formdev.flatlaf.FlatDarculaLaf;
|
import com.formdev.flatlaf.FlatDarculaLaf;
|
||||||
|
import io.github.sanyarnd.applocker.AppLocker;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.aohe.core.sane.utils.SaneSessionUtils;
|
import org.aohe.core.sane.utils.SaneSessionUtils;
|
||||||
import org.aohe.core.swing.NewWindow;
|
import org.aohe.core.swing.NewWindow;
|
||||||
|
@ -9,18 +10,30 @@ import org.aohe.core.utils.SystemUtils;
|
||||||
import org.aohe.core.web.SocketFactory;
|
import org.aohe.core.web.SocketFactory;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class Main {
|
public class Main {
|
||||||
|
|
||||||
|
private static final String JAVA_IO_TMPDIR = System.getProperty("java.io.tmpdir");
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
log.info(" 当前系统类型: {}", SystemUtils.getOsName());
|
log.info(" 当前系统类型: {}", SystemUtils.getOsName());
|
||||||
|
AppLocker locker = AppLocker.create("aoheSaneServiceLock").setPath( Path.of(JAVA_IO_TMPDIR) ).build();
|
||||||
try {
|
try {
|
||||||
|
//启动锁,只允许启动一个
|
||||||
|
locker.lock();
|
||||||
|
|
||||||
//设置窗口主题
|
//设置窗口主题
|
||||||
//FlatLightLaf.setup();
|
//FlatLightLaf.setup();
|
||||||
UIManager.setLookAndFeel(new FlatDarculaLaf());
|
UIManager.setLookAndFeel(new FlatDarculaLaf());
|
||||||
} catch (UnsupportedLookAndFeelException e) {
|
} catch (UnsupportedLookAndFeelException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
log.error("应用已经启动,当前进程退出。",ex);
|
||||||
|
|
||||||
|
System.exit(0);
|
||||||
}
|
}
|
||||||
//初始化其他资源
|
//初始化其他资源
|
||||||
init();
|
init();
|
||||||
|
|
|
@ -142,13 +142,13 @@ public class SaneSessionUtils {
|
||||||
try {
|
try {
|
||||||
saneDevice.open();
|
saneDevice.open();
|
||||||
BufferedImage bufferedImage = saneDevice.acquireImage();
|
BufferedImage bufferedImage = saneDevice.acquireImage();
|
||||||
File file = FileUtil.createTempFile("sane","png",true);
|
File file = FileUtil.createTempFile("sane-",".png",true);
|
||||||
ImageIO.write(bufferedImage, "png", file);
|
ImageIO.write(bufferedImage, "png", file);
|
||||||
return file;
|
return file;
|
||||||
} catch (IOException | SaneException e) {
|
} catch (IOException | SaneException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}finally {
|
}finally {
|
||||||
if(saneDevice != null){
|
if(saneDevice != null && saneDevice.isOpen()){
|
||||||
saneDevice.close();
|
saneDevice.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,6 +66,12 @@ public class NewWindow extends JFrame {
|
||||||
getLogTextArea().append(view + "\n");
|
getLogTextArea().append(view + "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setStaticView(String view){
|
||||||
|
if(logTextArea != null){
|
||||||
|
logTextArea.append(view + "\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void initSocket() {
|
public void initSocket() {
|
||||||
if(SocketFactory.start()){
|
if(SocketFactory.start()){
|
||||||
setView("socket 服务启动成功");
|
setView("socket 服务启动成功");
|
||||||
|
|
|
@ -3,7 +3,6 @@ package org.aohe.core.web;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import java.net.BindException;
|
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -12,12 +11,6 @@ import java.net.UnknownHostException;
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class SocketFactory {
|
public class SocketFactory {
|
||||||
|
|
||||||
/**
|
|
||||||
* -- GETTER --
|
|
||||||
* get 方法
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Getter
|
@Getter
|
||||||
private static SocketServer socketServer;
|
private static SocketServer socketServer;
|
||||||
|
|
||||||
|
@ -45,6 +38,7 @@ public class SocketFactory {
|
||||||
} catch (Exception e){
|
} catch (Exception e){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
log.info("socket ReuseAddr status {}", socketServer.isReuseAddr());
|
||||||
log.info("socket 已启动");
|
log.info("socket 已启动");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import org.aohe.core.result.R;
|
||||||
import org.aohe.core.sane.SaneOperational;
|
import org.aohe.core.sane.SaneOperational;
|
||||||
|
|
||||||
import org.aohe.core.sane.utils.SaneSessionUtils;
|
import org.aohe.core.sane.utils.SaneSessionUtils;
|
||||||
|
import org.aohe.core.swing.NewWindow;
|
||||||
import org.aohe.core.utils.SystemUtils;
|
import org.aohe.core.utils.SystemUtils;
|
||||||
import org.java_websocket.WebSocket;
|
import org.java_websocket.WebSocket;
|
||||||
import org.java_websocket.handshake.ClientHandshake;
|
import org.java_websocket.handshake.ClientHandshake;
|
||||||
|
@ -65,6 +66,14 @@ public class SocketServer extends WebSocketServer {
|
||||||
// websocket
|
// websocket
|
||||||
log.error( "System error ", ex );
|
log.error( "System error ", ex );
|
||||||
}
|
}
|
||||||
|
if(ex instanceof java.net.BindException){
|
||||||
|
//无法绑定接口
|
||||||
|
NewWindow.setStaticView("端口绑定失败,请检查端口占用,程序退出中...");
|
||||||
|
new Thread( ()->{
|
||||||
|
NewWindow.sleep(3000);
|
||||||
|
System.exit(0);
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<configuration>
|
<configuration>
|
||||||
<!-- 日志存放路径 -->
|
<!-- 日志存放路径 -->
|
||||||
<property name="log.path" value="${HOME}/Logs/ScanService"/>
|
<property name="log.path" value="${HOME}/logs/ScanService"/>
|
||||||
<!-- 日志输出格式 -->
|
<!-- 日志输出格式 -->
|
||||||
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue