Skip to content

Commit

Permalink
修复无客户端时的判断软件是否重复弹窗bug问题
Browse files Browse the repository at this point in the history
  • Loading branch information
WuYi5451 committed Oct 1, 2024
1 parent cd17128 commit 5601062
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/main/java/yalong/site/LeagueClientHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ public static void main(String[] args) {
MainFrame.showFrame();
HotKeyService.start();
clientStarter.listenGameStatus();
} catch (RepeatProcessException ignored) {
msg = "工具已打开请查看任务栏或系统托盘";
} catch (NoProcessException ignored) {
msg = "请先启动游戏";
} catch (ConnectException ignored) {
msg = "游戏客户端连接失败";
} catch (RepeatProcessException ignored) {
msg = "工具已打开请查看任务栏或系统托盘";
} catch (Exception e) {
msg = e.getMessage();
log.error(msg, e);
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/yalong/site/frame/MainFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public class MainFrame extends JFrame {
//用于创建后台托盘
private static TrayIcon trayIcon;
private static SystemTray tray;

//用于检测软件是否重复打开
private static RandomAccessFile RAF;
private static boolean lockFlag;
final static String LOCK_FILE = "lol-helper.lock";
static {
SaveFrameConfig.load();
Expand Down Expand Up @@ -195,10 +195,13 @@ private static void restoreFromTray() {
}

/**
* 查看文件是否右锁 用于判断软件是否重复打开
* 查看文件是否有锁 用于判断软件是否重复打开
*/
public static void checkFileLock() {
try {
if (lockFlag) {
return;
}
File file = new File(LOCK_FILE);
// 打开文件通道
RAF = new RandomAccessFile(file, "rw");
Expand All @@ -208,7 +211,10 @@ public static void checkFileLock() {
lock = channel.tryLock();
if (lock == null) {
RAF.close();
lockFlag = false;
throw new RepeatProcessException();
} else {
lockFlag = true;
}
} catch (IOException e) {
throw new RuntimeException(e);
Expand Down

0 comments on commit 5601062

Please sign in to comment.