Move the notification options to Notifier
- Move enabling of tray notifications to RuneLiteConfig - Move request when focused notification option to RuneLiteConfig and use it in notifier - Move request window focus to RuneLiteConfig and use it in notifier - Change Notifier to use Guice for creation Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
@@ -26,39 +26,40 @@ package net.runelite.client;
|
||||
|
||||
import com.google.common.escape.Escaper;
|
||||
import com.google.common.escape.Escapers;
|
||||
import com.google.inject.Inject;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.TrayIcon;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.inject.Provider;
|
||||
import javax.inject.Singleton;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.runelite.client.config.RuneLiteConfig;
|
||||
import net.runelite.client.util.OSType;
|
||||
import net.runelite.client.ui.ClientUI;
|
||||
|
||||
@Singleton
|
||||
@Slf4j
|
||||
public class Notifier
|
||||
{
|
||||
|
||||
// Default timeout of notification in milliseconds
|
||||
private static final int DEFAULT_TIMEOUT = 10000;
|
||||
private static final String DOUBLE_QUOTE = "\"";
|
||||
private static final Escaper SHELL_ESCAPE;
|
||||
|
||||
static
|
||||
{
|
||||
final Escapers.Builder builder = Escapers.builder();
|
||||
builder.addEscape('"', "'");
|
||||
SHELL_ESCAPE = builder.build();
|
||||
}
|
||||
private static final Escaper SHELL_ESCAPE = Escapers.builder()
|
||||
.addEscape('"', "'")
|
||||
.build();
|
||||
|
||||
private final String appName;
|
||||
private final TrayIcon trayIcon;
|
||||
private final RuneLiteConfig runeLiteConfig;
|
||||
private final Provider<ClientUI> clientUI;
|
||||
|
||||
Notifier(final String appName, final TrayIcon trayIcon, final RuneLiteConfig runeliteConfig)
|
||||
@Inject
|
||||
private Notifier(final Provider<ClientUI> clientUI, final RuneLiteConfig runeliteConfig, final RuneLiteProperties
|
||||
runeLiteProperties)
|
||||
{
|
||||
this.appName = appName;
|
||||
this.trayIcon = trayIcon;
|
||||
this.appName = runeLiteProperties.getTitle();
|
||||
this.clientUI = clientUI;
|
||||
this.runeLiteConfig = runeliteConfig;
|
||||
}
|
||||
|
||||
@@ -69,6 +70,28 @@ public class Notifier
|
||||
|
||||
public void notify(String message, TrayIcon.MessageType type)
|
||||
{
|
||||
if (!runeLiteConfig.enableTrayNotifications())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
final ClientUI clientUI = this.clientUI.get();
|
||||
|
||||
if (clientUI == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!runeLiteConfig.sendNotificationsWhenFocused() && clientUI.isFocused())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (runeLiteConfig.requestFocusOnNotification())
|
||||
{
|
||||
clientUI.requestFocus();
|
||||
}
|
||||
|
||||
sendNotification(appName, message, type, null);
|
||||
|
||||
if (runeLiteConfig.enableNotificationSound())
|
||||
@@ -105,9 +128,16 @@ public class Notifier
|
||||
final String message,
|
||||
final TrayIcon.MessageType type)
|
||||
{
|
||||
if (trayIcon != null)
|
||||
final ClientUI clientUI = this.clientUI.get();
|
||||
|
||||
if (clientUI == null)
|
||||
{
|
||||
trayIcon.displayMessage(title, message, type);
|
||||
return;
|
||||
}
|
||||
|
||||
if (clientUI.getTrayIcon() != null)
|
||||
{
|
||||
clientUI.getTrayIcon().displayMessage(title, message, type);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -98,7 +98,6 @@ public class RuneLite
|
||||
|
||||
Client client;
|
||||
ClientUI gui;
|
||||
Notifier notifier;
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
@@ -161,9 +160,6 @@ public class RuneLite
|
||||
eventBus.register(gui);
|
||||
eventBus.register(pluginManager);
|
||||
|
||||
// Setup the notifier
|
||||
notifier = new Notifier(properties.getTitle(), gui.getTrayIcon(), runeliteConfig);
|
||||
|
||||
// Tell the plugin manager if client is outdated or not
|
||||
pluginManager.setOutdated(isOutdated);
|
||||
|
||||
@@ -219,12 +215,6 @@ public class RuneLite
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public void setNotifier(Notifier notifier)
|
||||
{
|
||||
this.notifier = notifier;
|
||||
}
|
||||
|
||||
public static Injector getInjector()
|
||||
{
|
||||
return injector;
|
||||
|
||||
@@ -73,12 +73,6 @@ public class RuneLiteModule extends AbstractModule
|
||||
return runelite.gui;
|
||||
}
|
||||
|
||||
@Provides
|
||||
Notifier provideNotifier(RuneLite runeLite)
|
||||
{
|
||||
return runeLite.notifier;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
RuneLiteConfig provideConfig(ConfigManager configManager)
|
||||
|
||||
@@ -76,6 +76,16 @@ public interface RuneLiteConfig extends Config
|
||||
return false;
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "notificationTray",
|
||||
name = "Enable tray notifications",
|
||||
description = "Enables tray notifications"
|
||||
)
|
||||
default boolean enableTrayNotifications()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "notificationSound",
|
||||
name = "Enable sound on notifications",
|
||||
@@ -85,4 +95,24 @@ public interface RuneLiteConfig extends Config
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "notificationFocused",
|
||||
name = "Send notifications when focused",
|
||||
description = "Toggles idle notifications for when the client is focused"
|
||||
)
|
||||
default boolean sendNotificationsWhenFocused()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "notificationRequestFocus",
|
||||
name = "Request focus on notification",
|
||||
description = "Toggles window focus request"
|
||||
)
|
||||
default boolean requestFocusOnNotification()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,6 @@ import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import joptsimple.OptionSet;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.client.Notifier;
|
||||
import net.runelite.client.RuneLite;
|
||||
import net.runelite.client.RuneLiteModule;
|
||||
import net.runelite.client.ui.ClientUI;
|
||||
@@ -74,9 +73,6 @@ public class PluginManagerTest
|
||||
@Mock
|
||||
Client client;
|
||||
|
||||
@Mock
|
||||
Notifier notifier;
|
||||
|
||||
@Before
|
||||
public void before() throws IOException
|
||||
{
|
||||
@@ -88,7 +84,6 @@ public class PluginManagerTest
|
||||
|
||||
runelite = injector.getInstance(RuneLite.class);
|
||||
runelite.setGui(clientUi);
|
||||
runelite.setNotifier(notifier);
|
||||
|
||||
// Find plugins we expect to have
|
||||
pluginClasses = new HashSet<>();
|
||||
|
||||
Reference in New Issue
Block a user