package org.aohe; import com.formdev.flatlaf.FlatDarculaLaf; import io.github.sanyarnd.applocker.AppLocker; import lombok.extern.slf4j.Slf4j; import org.aohe.core.sane.utils.SaneSessionUtils; 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 javax.swing.*; import java.nio.file.Path; @Slf4j public class Main { private static final String JAVA_IO_TMPDIR = System.getProperty("java.io.tmpdir"); public static void main(String[] args) { log.info(" 当前系统类型: {}", SystemUtils.getOsName()); AppLocker locker = AppLocker.create("aoheSaneServiceLock").setPath( Path.of(JAVA_IO_TMPDIR) ).build(); try { //启动锁,只允许启动一个 locker.lock(); //设置窗口主题 //FlatLightLaf.setup(); UIManager.setLookAndFeel(new FlatDarculaLaf()); } catch (UnsupportedLookAndFeelException e) { throw new RuntimeException(e); } catch (Exception ex) { log.error("应用已经启动,当前进程退出。",ex); System.exit(0); } //初始化其他资源 init(); SwingUtilities.invokeLater(() -> new NewWindow().setVisible(true)); } public static void init(){ log.info("程序初始化开始..."); CommandUtils.initSanedSocket(); stopGracefully(); log.info("Hook注册成功..."); } public static void stopGracefully() { log.info("优雅退出Hook注册"); //优雅退出,在程序停止时,销毁关键资源占用 Runtime.getRuntime().addShutdownHook(new Thread(() -> { log.info("开始资源释放"); //释放sane资源 SaneSessionUtils.resource(); SocketFactory.stop(); log.info("socket 服务已关闭 "); })); } }