Skip to content

Commit

Permalink
Merge pull request #36 from Morph21/issue-29-_FEATURE_REQUEST_Notific…
Browse files Browse the repository at this point in the history
…ation_custom_sound

FIX #29 Issue 29  feature request notification custom sound
  • Loading branch information
Morph21 authored Oct 31, 2020
2 parents e4c1f48 + e7c8eeb commit 507b78e
Show file tree
Hide file tree
Showing 16 changed files with 116 additions and 110 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,5 @@ logs/

*dependency-reduced-pom.xml

release_files/MercuryTrad*
release_files/MercuryTrad*
release_files/resources/
15 changes: 14 additions & 1 deletion app-core/src/main/java/com/mercury/platform/core/ChatHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import com.mercury.platform.shared.store.MercuryStoreCore;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.platform.DesktopWindow;
import com.sun.jna.platform.WindowUtils;
import com.sun.jna.platform.win32.User32;
import com.sun.jna.platform.win32.WinDef;
import com.sun.jna.platform.win32.WinUser;
Expand All @@ -20,6 +22,7 @@
import java.awt.event.KeyEvent;
import java.io.IOException;


public class ChatHelper implements AsSubscriber {
private Robot robot;
private static boolean clipboardMessageOn = true;
Expand All @@ -34,7 +37,7 @@ public ChatHelper() {
}

private void executeClipboardMessage() {
if (clipboardMessageOn) {
if (clipboardMessageOn && isGameOpen()) {
this.gameToFront();
MercuryStoreCore.blockHotkeySubject.onNext(true);
robot.keyRelease(KeyEvent.VK_ALT);
Expand Down Expand Up @@ -209,6 +212,16 @@ private void gameToFront() {
}, null);
}

private boolean isGameOpen() {
WinDef.HWND poeWindowClass = WindowUtils.getAllWindows(false).stream().filter(window -> {
char[] className = new char[512];
User32.INSTANCE.GetClassName(window.getHWND(), className, 512);
return Native.toString(className).equals("POEWindowClass");
}).map(DesktopWindow::getHWND).findFirst().orElse(null);

return poeWindowClass != null;
}

@Override
public void subscribe() {
MercuryStoreCore.chatCommandSubject.subscribe(this::executeMessage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.FloatControl;
import javax.sound.sampled.*;
import java.io.File;
import java.io.IOException;
import java.net.URL;

public class SoundNotifier {
private final Logger logger = LogManager.getLogger(SoundNotifier.class);
Expand All @@ -30,18 +30,31 @@ public SoundNotifier() {
private void play(String wavPath, float db) {
if (!dnd && db > -40) {
ClassLoader classLoader = getClass().getClassLoader();
try (AudioInputStream stream = AudioSystem.getAudioInputStream(classLoader.getResource(wavPath))) {
Clip clip = AudioSystem.getClip();
clip.open(stream);
if (db != 0.0) {
FloatControl gainControl =
(FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
gainControl.setValue(db);
File file = new File("./resources/" + wavPath);
if (file.exists()) {
try (AudioInputStream stream = AudioSystem.getAudioInputStream(file)) {
play(stream, db);
} catch (IOException | UnsupportedAudioFileException | LineUnavailableException e) {
logger.error("Cannot start playing wav file: ", e);
}
} else {
try (AudioInputStream stream = AudioSystem.getAudioInputStream(classLoader.getResource(wavPath))) {
play(stream, db);
} catch (IOException | UnsupportedAudioFileException | LineUnavailableException e) {
logger.error("Cannot start playing wav file: ", e);
}
clip.start();
} catch (Exception e) {
logger.error("Cannot start playing wav file: ", e);
}
}
}

private void play(AudioInputStream stream, float db) throws LineUnavailableException, IOException {
Clip clip = AudioSystem.getClip();
clip.open(stream);
if (db != 0.0) {
FloatControl gainControl =
(FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
gainControl.setValue(db);
}
clip.start();
}
}
Original file line number Diff line number Diff line change
@@ -1,66 +1,49 @@
package com.mercury.platform.shared.hotkey;

import com.mercury.platform.shared.config.Configuration;
import com.mercury.platform.shared.config.descriptor.NotificationSettingsDescriptor;
import com.mercury.platform.shared.store.MercuryStoreCore;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import javax.swing.*;
import java.awt.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;

public class ClipboardListener {
private final static Logger logger = LogManager.getLogger(ClipboardListener.class);
public static boolean enabled;
private static ClipboardListener instance = null;
private static String lastData;

private ClipboardListener() {
NotificationSettingsDescriptor config = Configuration.get().notificationConfiguration().get();
enabled = config.isWhisperHelperEnable();
new Timer(200, e -> {
Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
DataFlavor df = DataFlavor.stringFlavor;
if (c.isDataFlavorAvailable(df)) {
if (enabled) {
try {
String message = c.getData(df).toString();
if (!message.equals(lastData)) {
lastData = message;
if (message.toLowerCase().contains("@") &&
(message.toLowerCase().contains("hi, i would like") ||
message.toLowerCase().contains("hi, i'd like") ||
message.toLowerCase().contains("i'd like") ||
(message.toLowerCase().contains("wtb") && message.toLowerCase().contains("(stash")))) {

System.out.println("ClipBoard UPDATED: " + message);
MercuryStoreCore.chatClipboardSubject.onNext(true);
Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
DataFlavor df = DataFlavor.stringFlavor;
if (c.isDataFlavorAvailable(df)) {
String message = c.getData(df).toString();
if (!message.equals(lastData)) {
lastData = message;
if (message.toLowerCase().contains("@") &&
(message.toLowerCase().contains("hi, i would like") ||
message.toLowerCase().contains("hi, i'd like") ||
message.toLowerCase().contains("i'd like") ||
(message.toLowerCase().contains("wtb") && message.toLowerCase().contains("(stash")))) {

MercuryStoreCore.chatClipboardSubject.onNext(true);
}
}
}
} catch (Exception ex) {
System.err.println(ex);
logger.error(ex);
}
}
}).start();


// Toolkit.getDefaultToolkit().getSystemClipboard().addFlavorListener(e -> {
// Clipboard systemClipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
// try {
// if (systemClipboard.getContents(this) != null && systemClipboard.getContents(this).isDataFlavorSupported(DataFlavor.stringFlavor)) {
// Object transferData = systemClipboard.getContents(this).getTransferData(DataFlavor.stringFlavor);
// if (transferData instanceof String) {
// String message = (String) transferData;
//
// if (message.to
// LowerCase().contains("@") &&
// (message.toLowerCase().contains("hi, i would like") ||
// message.toLowerCase().contains("hi, i'd like") ||
// message.toLowerCase().contains("i'd like") ||
// (message.toLowerCase().contains("wtb") && message.toLowerCase().contains("(stash")))) {
//
// System.out.println("ClipBoard UPDATED: " + message);
// MercuryStoreCore.chatClipboardSubject.onNext(true);
// }
// }
// }
// } catch (Exception ex) {
// ex.printStackTrace();
// }
// });
}

public static void createListener() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
package com.mercury.platform.shared.wh;

import com.mercury.platform.shared.config.Configuration;
import com.mercury.platform.shared.config.descriptor.NotificationSettingsDescriptor;
import com.mercury.platform.shared.store.MercuryStoreCore;

import javax.swing.*;

public class WhisperHelperHandler {
public WhisperHelperHandler() {
MercuryStoreCore.hotKeyReleaseSubject.subscribe(hotKeyDescriptor -> {
NotificationSettingsDescriptor config = Configuration.get().notificationConfiguration().get();
if (config.isWhisperHelperEnable() && config.getWhisperHelperHotKey().equals(hotKeyDescriptor)) {
Timer timer = new Timer(500, action -> {
MercuryStoreCore.tradeWhisperSubject.onNext(true);
});
timer.setRepeats(false);
timer.start();
}
// NotificationSettingsDescriptor config = Configuration.get().notificationConfiguration().get();
// if (config.isWhisperHelperEnable() && config.getWhisperHelperHotKey().equals(hotKeyDescriptor)) {
// Timer timer = new Timer(500, action -> {
// MercuryStoreCore.tradeWhisperSubject.onNext(true);
// });
// timer.setRepeats(false);
// timer.start();
// }
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public void mouseExited(MouseEvent e) {
try {
BufferedImage buttonIcon = ImageIO.read(getClass().getClassLoader().getResource(iconPath));
icon = Scalr.resize(buttonIcon, (int) (scale * iconSize));
} catch (IOException e) {
} catch (Exception e) {
e.printStackTrace();
}
if (icon != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.mercury.platform.shared.config.descriptor.NotificationSettingsDescriptor;
import com.mercury.platform.shared.entity.message.FlowDirections;
import com.mercury.platform.shared.IconConst;
import com.mercury.platform.shared.hotkey.ClipboardListener;
import com.mercury.platform.ui.components.fields.font.FontStyle;
import com.mercury.platform.ui.misc.AppThemeColor;

Expand Down Expand Up @@ -129,22 +130,21 @@ public void focusLost(FocusEvent e) {
private JPanel getWhisperHelperPanel() {
JPanel root = this.componentsFactory.getJPanel(new BorderLayout(), AppThemeColor.ADR_BG);

JPanel parametersPanel = this.componentsFactory.getJPanel(new GridLayout(2, 2), AppThemeColor.ADR_BG);
JPanel parametersPanel = this.componentsFactory.getJPanel(new GridLayout(1, 2), AppThemeColor.ADR_BG);
JCheckBox enableCheckbox = this.componentsFactory.getCheckBox(this.generalSnapshot.isWhisperHelperEnable());
enableCheckbox.addActionListener(action -> this.generalSnapshot.setWhisperHelperEnable(enableCheckbox.isSelected()));
enableCheckbox.addActionListener(action -> {
this.generalSnapshot.setWhisperHelperEnable(enableCheckbox.isSelected());
ClipboardListener.enabled = enableCheckbox.isSelected();
});
parametersPanel.add(this.componentsFactory.getTextLabel("Enabled:", FontStyle.REGULAR, 16));
parametersPanel.add(enableCheckbox);
parametersPanel.add(this.componentsFactory.getTextLabel("Hotkey:", FontStyle.REGULAR, 16));
HotKeyPanel hotKeyPanel = new HotKeyPanel(this.generalSnapshot.getWhisperHelperHotKey());
this.whHotkeyGroup.registerHotkey(hotKeyPanel);
parametersPanel.add(hotKeyPanel);

JPanel showcasePanel = this.componentsFactory.getJPanel(new BorderLayout(), AppThemeColor.ADR_BG);
showcasePanel.add(this.componentsFactory.getTextLabel("When you release hotkey button clipboard content will be transferred to chat.", FontStyle.REGULAR, 16), BorderLayout.PAGE_START);
showcasePanel.add(this.componentsFactory.getTextLabel("When you copy a text which is in format of trade message it will be automatically pasted into chat window in PoE", FontStyle.REGULAR, 16), BorderLayout.PAGE_START);
JLabel img = new JLabel();
img.setIcon(this.componentsFactory.getImage("app/whisper-helper.png"));
showcasePanel.add(this.componentsFactory.wrapToSlide(img, AppThemeColor.ADR_BG, 4, 4, 4, 4), BorderLayout.CENTER);
showcasePanel.add(this.componentsFactory.getTextLabel("Example: press hotkey button => click on 'Whisper' button => release hotkey button.", FontStyle.REGULAR, 16), BorderLayout.PAGE_END);
showcasePanel.add(this.componentsFactory.getTextLabel("Example: click on 'Whisper' button, message will be copied to your clipboard => MT will paste it into chat in PoE.", FontStyle.REGULAR, 16), BorderLayout.PAGE_END);
root.add(parametersPanel, BorderLayout.PAGE_START);
root.add(showcasePanel, BorderLayout.CENTER);
root.setVisible(false);
Expand Down
Binary file added app-ui/src/main/resources/currency/p.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions app-ui/src/main/resources/notes/patch/patch-notes-new.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
[
{
"version": "1.1.5",
"fix": [
{
"changed": "Fixed part of keyboard not working when using Portuguese (Brazil) language"
}
]
},
{
"version": "1.1.4",
"fix": [
Expand Down
45 changes: 13 additions & 32 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -147,53 +147,34 @@
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.mercury.platform.AppMain</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>make-assembly</id> <!-- Added to combine all MT jars into a single package -->
<phase>package</phase>
<goals>
<goal>single</goal>
<goal>shade</goal>
</goals>
<configuration>
<finalName>MercuryTrade</finalName>
</configuration>
</execution>
</executions>
</plugin>
<!-- <plugin>-->
<!-- <groupId>org.apache.maven.plugins</groupId>-->
<!-- <artifactId>maven-jar-plugin</artifactId>-->
<!-- <version>3.2.0</version>-->
<!-- <configuration>-->
<!-- <archive>-->
<!-- <manifest>-->
<!-- <addClasspath>true</addClasspath>-->
<!-- <mainClass>com.mercury.platform.AppMain</mainClass>-->
<!-- </manifest>-->
<!-- </archive>-->
<!-- </configuration>-->
<!-- </plugin>-->
<!-- <plugin>-->
<!-- <groupId>org.apache.maven.plugins</groupId>-->
<!-- <artifactId>maven-shade-plugin</artifactId>-->
<!-- <version>3.2.0</version>-->
<!-- <executions>-->
<!-- <execution>-->
<!-- <phase>package</phase>-->
<!-- <goals>-->
<!-- <goal>shade</goal>-->
<!-- </goals>-->
<!-- </execution>-->
<!-- </executions>-->
<!-- </plugin>-->
</plugins>
</build>
</project>
11 changes: 11 additions & 0 deletions resources/app/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Here you can put your own sound files to change existing ones.

Simply put a sound file inside sounds folder and name it like the one which is used in MT.


The list of files which MT uses has names:
button-pressed.wav
chat-filter.wav
icq-message.wav
notification.wav
patch_tone.wav
Binary file added resources/app/button-pressed.wav
Binary file not shown.
Binary file added resources/app/chat-filter.wav
Binary file not shown.
Binary file added resources/app/icq-message.wav
Binary file not shown.
Binary file added resources/app/notification.wav
Binary file not shown.
Binary file added resources/app/patch_tone.wav
Binary file not shown.

0 comments on commit 507b78e

Please sign in to comment.