From 7843460020c98c457d215145a9271c0e2f8e3bf5 Mon Sep 17 00:00:00 2001 From: hstyi Date: Fri, 7 Feb 2025 13:47:41 +0800 Subject: [PATCH] feat: confirmation required to exit program --- .../kotlin/app/termora/TermoraFrameManager.kt | 20 +++++++++++++++++-- src/main/resources/i18n/messages.properties | 2 ++ .../resources/i18n/messages_zh_CN.properties | 1 + .../resources/i18n/messages_zh_TW.properties | 1 + src/test/resources/sshd/Dockerfile | 2 +- 5 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/app/termora/TermoraFrameManager.kt b/src/main/kotlin/app/termora/TermoraFrameManager.kt index d6b7d0f..67ae745 100644 --- a/src/main/kotlin/app/termora/TermoraFrameManager.kt +++ b/src/main/kotlin/app/termora/TermoraFrameManager.kt @@ -4,7 +4,8 @@ import com.formdev.flatlaf.util.SystemInfo import org.slf4j.LoggerFactory import java.awt.event.WindowAdapter import java.awt.event.WindowEvent -import javax.swing.WindowConstants.DISPOSE_ON_CLOSE +import javax.swing.JOptionPane +import javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE import kotlin.system.exitProcess class TermoraFrameManager { @@ -22,7 +23,7 @@ class TermoraFrameManager { val frame = TermoraFrame() registerCloseCallback(frame) frame.title = if (SystemInfo.isLinux) null else Application.getName() - frame.defaultCloseOperation = DISPOSE_ON_CLOSE + frame.defaultCloseOperation = DO_NOTHING_ON_CLOSE frame.setSize(1280, 800) frame.setLocationRelativeTo(null) return frame @@ -43,6 +44,21 @@ class TermoraFrameManager { this@TermoraFrameManager.dispose() } } + + override fun windowClosing(e: WindowEvent) { + if (ApplicationScope.windowScopes().size == 1) { + if (OptionPane.showConfirmDialog( + window, + I18n.getString("termora.quit-confirm", Application.getName()), + optionType = JOptionPane.YES_NO_OPTION, + ) == JOptionPane.YES_OPTION + ) { + window.dispose() + } + } else { + window.dispose() + } + } }) } diff --git a/src/main/resources/i18n/messages.properties b/src/main/resources/i18n/messages.properties index 13bd480..dd7b082 100644 --- a/src/main/resources/i18n/messages.properties +++ b/src/main/resources/i18n/messages.properties @@ -11,6 +11,8 @@ termora.date-format=MM/dd/yyyy hh:mm:ss a termora.finder=Finder termora.folder=Folder termora.explorer=Explorer +termora.quit-confirm=Quit {0}? + # update termora.update.title=New version diff --git a/src/main/resources/i18n/messages_zh_CN.properties b/src/main/resources/i18n/messages_zh_CN.properties index cb25899..6d3c139 100644 --- a/src/main/resources/i18n/messages_zh_CN.properties +++ b/src/main/resources/i18n/messages_zh_CN.properties @@ -10,6 +10,7 @@ termora.date-format=yyyy-MM-dd HH:mm:ss termora.finder=访达 termora.folder=文件夹 termora.explorer=文件管理器 +termora.quit-confirm=你要退出 {0} 吗? # update termora.update.title=新版本 diff --git a/src/main/resources/i18n/messages_zh_TW.properties b/src/main/resources/i18n/messages_zh_TW.properties index 6e9b4c4..889a95f 100644 --- a/src/main/resources/i18n/messages_zh_TW.properties +++ b/src/main/resources/i18n/messages_zh_TW.properties @@ -9,6 +9,7 @@ termora.date-format=yyyy/MM/dd HH:mm:ss termora.finder=訪達 termora.folder=資料夾 termora.explorer=檔案管理器 +termora.quit-confirm=你要退出 {0} 嗎? # update termora.update.title=新版本 diff --git a/src/test/resources/sshd/Dockerfile b/src/test/resources/sshd/Dockerfile index 3c1b0a3..33bfb31 100644 --- a/src/test/resources/sshd/Dockerfile +++ b/src/test/resources/sshd/Dockerfile @@ -1,6 +1,6 @@ FROM linuxserver/openssh-server RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \ - && apk update && apk add wget gcc g++ git make zsh htop && wget https://ohse.de/uwe/releases/lrzsz-0.12.20.tar.gz \ + && apk update && apk add wget gcc g++ git make zsh htop inetutils-telnet && wget https://ohse.de/uwe/releases/lrzsz-0.12.20.tar.gz \ && tar -xf lrzsz-0.12.20.tar.gz && cd lrzsz-0.12.20 && ./configure && make && make install \ && ln -s /usr/local/bin/lrz /usr/local/bin/rz && ln -s /usr/local/bin/lsz /usr/local/bin/sz