runelite-client: Add custom notification sounds

This commit is contained in:
Max Weber
2019-11-11 07:59:43 -05:00
committed by 15987632
parent 4fb8aa7349
commit 238471979c
5 changed files with 84 additions and 5 deletions

View File

@@ -267,6 +267,7 @@
<nonFilteredFileExtension>ttf</nonFilteredFileExtension>
<nonFilteredFileExtension>png</nonFilteredFileExtension>
<nonFilteredFileExtension>gif</nonFilteredFileExtension>
<nonFilteredFileExtension>wav</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
</plugin>

View File

@@ -33,6 +33,9 @@ import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.TrayIcon;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
@@ -43,6 +46,13 @@ import java.util.List;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import javax.inject.Singleton;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.ChatMessageType;
import net.runelite.api.Client;
@@ -61,6 +71,23 @@ import net.runelite.client.util.OSType;
@Slf4j
public class Notifier
{
@Getter
@RequiredArgsConstructor
public enum NativeCustomOff
{
NATIVE("Native"),
CUSTOM("Custom"),
OFF("Off");
private final String name;
@Override
public String toString()
{
return name;
}
}
// Default timeout of notification in milliseconds
private static final int DEFAULT_TIMEOUT = 10000;
private static final String DOUBLE_QUOTE = "\"";
@@ -130,9 +157,13 @@ public class Notifier
sendNotification(appName, message, type);
}
if (runeLiteConfig.enableNotificationSound())
switch (runeLiteConfig.notificationSound())
{
Toolkit.getDefaultToolkit().beep();
case NATIVE:
Toolkit.getDefaultToolkit().beep();
break;
case CUSTOM:
executorService.submit(this::playCustomSound);
}
if (runeLiteConfig.enableGameMessageNotification() && client.getGameState() == GameState.LOGGED_IN)
@@ -369,4 +400,48 @@ public class Notifier
return "normal";
}
}
private void playCustomSound()
{
Clip clip = null;
// Try to load the user sound from ~/.runelite/notification.wav
File file = new File(RuneLite.RUNELITE_DIR, "notification.wav");
if (file.exists())
{
try
{
InputStream fileStream = new BufferedInputStream(new FileInputStream(file));
try (AudioInputStream sound = AudioSystem.getAudioInputStream(fileStream))
{
clip = AudioSystem.getClip();
clip.open(sound);
}
}
catch (UnsupportedAudioFileException | IOException | LineUnavailableException e)
{
clip = null;
log.warn("Unable to play notification sound", e);
}
}
if (clip == null)
{
// Otherwise load from the classpath
InputStream fileStream = new BufferedInputStream(Notifier.class.getResourceAsStream("notification.wav"));
try (AudioInputStream sound = AudioSystem.getAudioInputStream(fileStream))
{
clip = AudioSystem.getClip();
clip.open(sound);
}
catch (UnsupportedAudioFileException | IOException | LineUnavailableException e)
{
log.warn("Unable to play builtin notification sound", e);
Toolkit.getDefaultToolkit().beep();
return;
}
}
clip.start();
}
}

View File

@@ -26,6 +26,7 @@ package net.runelite.client.config;
import java.awt.Dimension;
import net.runelite.api.Constants;
import net.runelite.client.Notifier;
import net.runelite.client.ui.ContainableFrame;
@ConfigGroup("runelite")
@@ -155,13 +156,13 @@ public interface RuneLiteConfig extends Config
@ConfigItem(
keyName = "notificationSound",
name = "Enable sound on notifications",
name = "Notification sound",
description = "Enables the playing of a beep sound when notifications are displayed",
position = 22
)
default boolean enableNotificationSound()
default Notifier.NativeCustomOff notificationSound()
{
return true;
return Notifier.NativeCustomOff.NATIVE;
}
@ConfigItem(

View File

@@ -0,0 +1,2 @@
Notification is cloud from
https://github.com/akx/Notifications