mirror of https://github.com/zlatinb/muwire
use system tray notifications for new messages
parent
2cc474eeae
commit
1676f81091
|
@ -3,6 +3,8 @@ COLON=:
|
|||
# System tray
|
||||
EXIT=Exit
|
||||
OPEN_MUWIRE=Open MuWire
|
||||
NEW_MESSAGE=New MuWire Message
|
||||
NEW_MESSAGE_FROM=New message from {0}
|
||||
|
||||
# Startup general
|
||||
MUWIRE_WILL_EXIT=MuWire will now exit.
|
||||
|
|
|
@ -171,7 +171,7 @@ class Initialize extends AbstractLifecycleHandler {
|
|||
|
||||
|
||||
trayIcon.addActionListener(showMW)
|
||||
application.getContext().put("tray-icon", true)
|
||||
application.getContext().put("tray-icon", trayIcon)
|
||||
} catch (Exception bad) {
|
||||
log.log(Level.WARNING,"couldn't set tray icon",bad)
|
||||
}
|
||||
|
|
|
@ -208,7 +208,7 @@ class MainFrameModel {
|
|||
|
||||
uiSettings = application.context.get("ui-settings")
|
||||
|
||||
messageNotificator = new MessageNotificator(uiSettings)
|
||||
messageNotificator = new MessageNotificator(uiSettings, application.context.get("tray-icon"))
|
||||
|
||||
shared = []
|
||||
treeRoot = new DefaultMutableTreeNode()
|
||||
|
@ -866,7 +866,7 @@ class MainFrameModel {
|
|||
runInsideUIAsync {
|
||||
if (messageHeadersMap.get(Messenger.INBOX).add(new MWMessageStatus(e.message, true))) {
|
||||
messages++
|
||||
messageNotificator.newMessage()
|
||||
messageNotificator.newMessage(e.message.sender.getHumanReadableName())
|
||||
messageNotificator.messages(messages)
|
||||
if (folderIdx == Messenger.INBOX) {
|
||||
messageHeaders.clear()
|
||||
|
|
|
@ -816,7 +816,7 @@ class MainFrameView {
|
|||
mainFrame.addWindowListener(new WindowAdapter(){
|
||||
public void windowClosing(WindowEvent e) {
|
||||
chatNotificator.mainWindowDeactivated()
|
||||
if (application.getContext().get("tray-icon")) {
|
||||
if (application.getContext().get("tray-icon") != null) {
|
||||
if (settings.closeWarning) {
|
||||
runInsideUIAsync {
|
||||
Map<String, Object> args2 = new HashMap<>()
|
||||
|
|
|
@ -385,11 +385,10 @@ class OptionsView {
|
|||
label(text : trans("OPTIONS_MESSAGE_SEND_INTERVAL"), constraints : gbc(gridx: 0, gridy: 2, anchor: GridBagConstraints.LINE_START, weightx: 100))
|
||||
messageSendIntervalField = textField(text : bind{model.messageSendInterval}, constraints : gbc(gridx : 2, gridy : 2, anchor : GridBagConstraints.LINE_END))
|
||||
|
||||
// TODO: re-enable when adoptopenjdk fixes it
|
||||
// if (Taskbar.isTaskbarSupported()) {
|
||||
// label(text : trans("OPTIONS_MESSAGE_NOTIFICATIONS"), constraints : gbc(gridx: 0, gridy: 3, anchor: GridBagConstraints.LINE_START, weightx: 100))
|
||||
// messageNotificationsCheckbox = checkBox(selected : bind{model.messageNotifications}, constraints : gbc(gridx:2, gridy:3, anchor:GridBagConstraints.LINE_END))
|
||||
// }
|
||||
if (Taskbar.isTaskbarSupported() || SystemTray.isSupported()) {
|
||||
label(text : trans("OPTIONS_MESSAGE_NOTIFICATIONS"), constraints : gbc(gridx: 0, gridy: 3, anchor: GridBagConstraints.LINE_START, weightx: 100))
|
||||
messageNotificationsCheckbox = checkBox(selected : bind{model.messageNotifications}, constraints : gbc(gridx:2, gridy:3, anchor:GridBagConstraints.LINE_END))
|
||||
}
|
||||
}
|
||||
panel(constraints : gbc(gridx: 0, gridy : 2, weighty: 100))
|
||||
}
|
||||
|
|
|
@ -1,23 +1,30 @@
|
|||
package com.muwire.gui
|
||||
|
||||
import static com.muwire.gui.Translator.trans
|
||||
import java.awt.Taskbar
|
||||
import java.awt.Taskbar.Feature
|
||||
import java.awt.TrayIcon
|
||||
|
||||
class MessageNotificator {
|
||||
|
||||
private final UISettings settings
|
||||
MessageNotificator(UISettings settings) {
|
||||
private final TrayIcon trayIcon
|
||||
MessageNotificator(UISettings settings, TrayIcon trayIcon) {
|
||||
this.settings = settings
|
||||
this.trayIcon = trayIcon
|
||||
}
|
||||
|
||||
void newMessage() {
|
||||
void newMessage(String from) {
|
||||
if (!settings.messageNotifications)
|
||||
return
|
||||
if (!Taskbar.isTaskbarSupported())
|
||||
return
|
||||
def taskBar = Taskbar.getTaskbar()
|
||||
if (taskBar.isSupported(Feature.USER_ATTENTION))
|
||||
taskBar.requestUserAttention(true, false)
|
||||
if (Taskbar.isTaskbarSupported()) {
|
||||
def taskBar = Taskbar.getTaskbar()
|
||||
if (taskBar.isSupported(Feature.USER_ATTENTION))
|
||||
taskBar.requestUserAttention(true, false)
|
||||
}
|
||||
if (trayIcon != null) {
|
||||
trayIcon.displayMessage(trans("NEW_MESSAGE"), trans("NEW_MESSAGE_FROM",from), TrayIcon.MessageType.INFO)
|
||||
}
|
||||
}
|
||||
|
||||
void messages(int count) {
|
||||
|
|
Loading…
Reference in New Issue