mirror of
https://github.com/TermoraDev/termora.git
synced 2026-01-16 02:12:58 +08:00
fix: windows tray icon size
This commit is contained in:
@@ -24,12 +24,13 @@ import java.awt.*
|
|||||||
import java.awt.desktop.AppReopenedEvent
|
import java.awt.desktop.AppReopenedEvent
|
||||||
import java.awt.desktop.AppReopenedListener
|
import java.awt.desktop.AppReopenedListener
|
||||||
import java.awt.desktop.SystemEventListener
|
import java.awt.desktop.SystemEventListener
|
||||||
import java.awt.event.ActionEvent
|
import java.awt.event.*
|
||||||
import java.awt.event.WindowEvent
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.concurrent.CountDownLatch
|
import java.util.concurrent.CountDownLatch
|
||||||
import javax.imageio.ImageIO
|
import javax.imageio.ImageIO
|
||||||
import javax.swing.*
|
import javax.swing.*
|
||||||
|
import javax.swing.event.PopupMenuEvent
|
||||||
|
import javax.swing.event.PopupMenuListener
|
||||||
import kotlin.system.exitProcess
|
import kotlin.system.exitProcess
|
||||||
|
|
||||||
class ApplicationRunner {
|
class ApplicationRunner {
|
||||||
@@ -112,16 +113,63 @@ class ApplicationRunner {
|
|||||||
if (!SystemInfo.isWindows || !SystemTray.isSupported()) return
|
if (!SystemInfo.isWindows || !SystemTray.isSupported()) return
|
||||||
|
|
||||||
val tray = SystemTray.getSystemTray()
|
val tray = SystemTray.getSystemTray()
|
||||||
val image = ImageIO.read(TermoraFrame::class.java.getResourceAsStream("/icons/termora_16x16.png"))
|
val image = ImageIO.read(TermoraFrame::class.java.getResourceAsStream("/icons/termora_32x32.png"))
|
||||||
val trayIcon = TrayIcon(image)
|
val trayIcon = TrayIcon(image)
|
||||||
val popupMenu = PopupMenu()
|
val dialog = JDialog()
|
||||||
trayIcon.popupMenu = popupMenu
|
val trayPopup = JPopupMenu()
|
||||||
|
|
||||||
|
dialog.isUndecorated = true
|
||||||
|
dialog.isModal = false
|
||||||
|
dialog.size = Dimension(0, 0)
|
||||||
|
|
||||||
|
trayIcon.isImageAutoSize = true
|
||||||
trayIcon.toolTip = Application.getName()
|
trayIcon.toolTip = Application.getName()
|
||||||
|
|
||||||
// PopupMenu 不支持中文
|
trayPopup.add(I18n.getString("termora.exit")).addActionListener { quitHandler() }
|
||||||
val exitMenu = MenuItem("Exit")
|
trayPopup.addPopupMenuListener(object : PopupMenuListener {
|
||||||
exitMenu.addActionListener { SwingUtilities.invokeLater { quitHandler() } }
|
override fun popupMenuWillBecomeVisible(e: PopupMenuEvent?) {
|
||||||
popupMenu.add(exitMenu)
|
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun popupMenuWillBecomeInvisible(e: PopupMenuEvent?) {
|
||||||
|
SwingUtilities.invokeLater {
|
||||||
|
if (dialog.isVisible) {
|
||||||
|
dialog.isVisible = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun popupMenuCanceled(e: PopupMenuEvent?) {
|
||||||
|
popupMenuWillBecomeInvisible(e)
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
trayIcon.addMouseListener(object : MouseAdapter() {
|
||||||
|
override fun mouseReleased(e: MouseEvent) {
|
||||||
|
maybeShowPopup(e)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun mousePressed(e: MouseEvent) {
|
||||||
|
maybeShowPopup(e)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun maybeShowPopup(e: MouseEvent) {
|
||||||
|
if (e.isPopupTrigger) {
|
||||||
|
val mouseLocation = MouseInfo.getPointerInfo().location
|
||||||
|
trayPopup.setLocation(mouseLocation.x, mouseLocation.y)
|
||||||
|
trayPopup.setInvoker(dialog)
|
||||||
|
dialog.isVisible = true
|
||||||
|
trayPopup.isVisible = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
dialog.addWindowFocusListener(object : WindowAdapter() {
|
||||||
|
override fun windowLostFocus(e: WindowEvent) {
|
||||||
|
dialog.isVisible = false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// double click
|
// double click
|
||||||
trayIcon.addActionListener(object : AbstractAction() {
|
trayIcon.addActionListener(object : AbstractAction() {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
termora.title=Termora
|
termora.title=Termora
|
||||||
termora.confirm=OK
|
termora.confirm=OK
|
||||||
|
termora.exit=退出
|
||||||
termora.cancel=Cancel
|
termora.cancel=Cancel
|
||||||
termora.copy=Copy
|
termora.copy=Copy
|
||||||
termora.apply=Apply
|
termora.apply=Apply
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
termora.title=Termora
|
termora.title=Termora
|
||||||
termora.confirm=Ок
|
termora.confirm=Ок
|
||||||
|
termora.exit=покидать
|
||||||
termora.cancel=Отмена
|
termora.cancel=Отмена
|
||||||
termora.copy=Копировать
|
termora.copy=Копировать
|
||||||
termora.apply=Применить
|
termora.apply=Применить
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
termora.confirm=确认
|
termora.confirm=确认
|
||||||
|
termora.exit=退出
|
||||||
termora.cancel=取消
|
termora.cancel=取消
|
||||||
termora.copy=复制
|
termora.copy=复制
|
||||||
termora.apply=应用
|
termora.apply=应用
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
termora.confirm=確定
|
termora.confirm=確定
|
||||||
|
termora.exit=Exit
|
||||||
termora.cancel=取消
|
termora.cancel=取消
|
||||||
termora.apply=应用
|
termora.apply=应用
|
||||||
termora.save=儲存
|
termora.save=儲存
|
||||||
|
|||||||
Reference in New Issue
Block a user