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.Escaper;
|
||||||
import com.google.common.escape.Escapers;
|
import com.google.common.escape.Escapers;
|
||||||
|
import com.google.inject.Inject;
|
||||||
import java.awt.Toolkit;
|
import java.awt.Toolkit;
|
||||||
import java.awt.TrayIcon;
|
import java.awt.TrayIcon;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import javax.inject.Provider;
|
||||||
|
import javax.inject.Singleton;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.runelite.client.config.RuneLiteConfig;
|
import net.runelite.client.config.RuneLiteConfig;
|
||||||
import net.runelite.client.util.OSType;
|
import net.runelite.client.util.OSType;
|
||||||
|
import net.runelite.client.ui.ClientUI;
|
||||||
|
|
||||||
|
@Singleton
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class Notifier
|
public class Notifier
|
||||||
{
|
{
|
||||||
|
|
||||||
// Default timeout of notification in milliseconds
|
// Default timeout of notification in milliseconds
|
||||||
private static final int DEFAULT_TIMEOUT = 10000;
|
private static final int DEFAULT_TIMEOUT = 10000;
|
||||||
private static final String DOUBLE_QUOTE = "\"";
|
private static final String DOUBLE_QUOTE = "\"";
|
||||||
private static final Escaper SHELL_ESCAPE;
|
private static final Escaper SHELL_ESCAPE = Escapers.builder()
|
||||||
|
.addEscape('"', "'")
|
||||||
static
|
.build();
|
||||||
{
|
|
||||||
final Escapers.Builder builder = Escapers.builder();
|
|
||||||
builder.addEscape('"', "'");
|
|
||||||
SHELL_ESCAPE = builder.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
private final String appName;
|
private final String appName;
|
||||||
private final TrayIcon trayIcon;
|
|
||||||
private final RuneLiteConfig runeLiteConfig;
|
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.appName = runeLiteProperties.getTitle();
|
||||||
this.trayIcon = trayIcon;
|
this.clientUI = clientUI;
|
||||||
this.runeLiteConfig = runeliteConfig;
|
this.runeLiteConfig = runeliteConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,6 +70,28 @@ public class Notifier
|
|||||||
|
|
||||||
public void notify(String message, TrayIcon.MessageType type)
|
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);
|
sendNotification(appName, message, type, null);
|
||||||
|
|
||||||
if (runeLiteConfig.enableNotificationSound())
|
if (runeLiteConfig.enableNotificationSound())
|
||||||
@@ -105,9 +128,16 @@ public class Notifier
|
|||||||
final String message,
|
final String message,
|
||||||
final TrayIcon.MessageType type)
|
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;
|
Client client;
|
||||||
ClientUI gui;
|
ClientUI gui;
|
||||||
Notifier notifier;
|
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception
|
public static void main(String[] args) throws Exception
|
||||||
{
|
{
|
||||||
@@ -161,9 +160,6 @@ public class RuneLite
|
|||||||
eventBus.register(gui);
|
eventBus.register(gui);
|
||||||
eventBus.register(pluginManager);
|
eventBus.register(pluginManager);
|
||||||
|
|
||||||
// Setup the notifier
|
|
||||||
notifier = new Notifier(properties.getTitle(), gui.getTrayIcon(), runeliteConfig);
|
|
||||||
|
|
||||||
// Tell the plugin manager if client is outdated or not
|
// Tell the plugin manager if client is outdated or not
|
||||||
pluginManager.setOutdated(isOutdated);
|
pluginManager.setOutdated(isOutdated);
|
||||||
|
|
||||||
@@ -219,12 +215,6 @@ public class RuneLite
|
|||||||
this.client = client;
|
this.client = client;
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
public void setNotifier(Notifier notifier)
|
|
||||||
{
|
|
||||||
this.notifier = notifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Injector getInjector()
|
public static Injector getInjector()
|
||||||
{
|
{
|
||||||
return injector;
|
return injector;
|
||||||
|
|||||||
@@ -73,12 +73,6 @@ public class RuneLiteModule extends AbstractModule
|
|||||||
return runelite.gui;
|
return runelite.gui;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
|
||||||
Notifier provideNotifier(RuneLite runeLite)
|
|
||||||
{
|
|
||||||
return runeLite.notifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
RuneLiteConfig provideConfig(ConfigManager configManager)
|
RuneLiteConfig provideConfig(ConfigManager configManager)
|
||||||
|
|||||||
@@ -76,6 +76,16 @@ public interface RuneLiteConfig extends Config
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ConfigItem(
|
||||||
|
keyName = "notificationTray",
|
||||||
|
name = "Enable tray notifications",
|
||||||
|
description = "Enables tray notifications"
|
||||||
|
)
|
||||||
|
default boolean enableTrayNotifications()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
keyName = "notificationSound",
|
keyName = "notificationSound",
|
||||||
name = "Enable sound on notifications",
|
name = "Enable sound on notifications",
|
||||||
@@ -85,4 +95,24 @@ public interface RuneLiteConfig extends Config
|
|||||||
{
|
{
|
||||||
return true;
|
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 java.util.Set;
|
||||||
import joptsimple.OptionSet;
|
import joptsimple.OptionSet;
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
import net.runelite.client.Notifier;
|
|
||||||
import net.runelite.client.RuneLite;
|
import net.runelite.client.RuneLite;
|
||||||
import net.runelite.client.RuneLiteModule;
|
import net.runelite.client.RuneLiteModule;
|
||||||
import net.runelite.client.ui.ClientUI;
|
import net.runelite.client.ui.ClientUI;
|
||||||
@@ -74,9 +73,6 @@ public class PluginManagerTest
|
|||||||
@Mock
|
@Mock
|
||||||
Client client;
|
Client client;
|
||||||
|
|
||||||
@Mock
|
|
||||||
Notifier notifier;
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void before() throws IOException
|
public void before() throws IOException
|
||||||
{
|
{
|
||||||
@@ -88,7 +84,6 @@ public class PluginManagerTest
|
|||||||
|
|
||||||
runelite = injector.getInstance(RuneLite.class);
|
runelite = injector.getInstance(RuneLite.class);
|
||||||
runelite.setGui(clientUi);
|
runelite.setGui(clientUi);
|
||||||
runelite.setNotifier(notifier);
|
|
||||||
|
|
||||||
// Find plugins we expect to have
|
// Find plugins we expect to have
|
||||||
pluginClasses = new HashSet<>();
|
pluginClasses = new HashSet<>();
|
||||||
|
|||||||
Reference in New Issue
Block a user