Move creation of tray icon to ClientUI
Move creation of tray icon from RuneLite to ClientUI. Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
@@ -29,19 +29,9 @@ import com.google.inject.Guice;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import java.applet.Applet;
|
||||
import java.awt.AWTException;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Image;
|
||||
import java.awt.SystemTray;
|
||||
import java.awt.TrayIcon;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.inject.Singleton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPopupMenu;
|
||||
@@ -70,13 +60,10 @@ public class RuneLite
|
||||
public static final File PROFILES_DIR = new File(RUNELITE_DIR, "profiles");
|
||||
public static final File PLUGIN_DIR = new File(RUNELITE_DIR, "plugins");
|
||||
|
||||
public static Image ICON;
|
||||
|
||||
private static Injector injector;
|
||||
|
||||
private static OptionSet options;
|
||||
private static RuneLite runelite;
|
||||
private static TrayIcon trayIcon;
|
||||
|
||||
private ClientUI gui;
|
||||
|
||||
@@ -110,19 +97,6 @@ public class RuneLite
|
||||
Client client;
|
||||
Notifier notifier;
|
||||
|
||||
static
|
||||
{
|
||||
try
|
||||
{
|
||||
final URL icon = ClientUI.class.getResource("/runelite.png");
|
||||
ICON = ImageIO.read(icon.openStream());
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
log.warn(null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
// Force heavy-weight popups/tooltips.
|
||||
@@ -184,7 +158,6 @@ public class RuneLite
|
||||
}
|
||||
|
||||
gui = new ClientUI(properties, client);
|
||||
setupTrayIcon();
|
||||
});
|
||||
|
||||
configManager.load();
|
||||
@@ -194,7 +167,7 @@ public class RuneLite
|
||||
eventBus.register(chatMessageManager);
|
||||
|
||||
// Setup the notifier
|
||||
notifier = new Notifier(properties.getTitle(), trayIcon);
|
||||
notifier = new Notifier(properties.getTitle(), gui.getTrayIcon());
|
||||
|
||||
// Tell the plugin manager if client is outdated or not
|
||||
pluginManager.setOutdated(isOutdated);
|
||||
@@ -217,40 +190,6 @@ public class RuneLite
|
||||
pluginManager.watch();
|
||||
}
|
||||
|
||||
private void setupTrayIcon()
|
||||
{
|
||||
if (!SystemTray.isSupported())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SystemTray systemTray = SystemTray.getSystemTray();
|
||||
|
||||
trayIcon = new TrayIcon(ICON, properties.getTitle());
|
||||
trayIcon.setImageAutoSize(true);
|
||||
|
||||
try
|
||||
{
|
||||
systemTray.add(trayIcon);
|
||||
}
|
||||
catch (AWTException ex)
|
||||
{
|
||||
log.debug("Unable to add system tray icon", ex);
|
||||
return;
|
||||
}
|
||||
|
||||
// bring to front when tray icon is clicked
|
||||
trayIcon.addMouseListener(new MouseAdapter()
|
||||
{
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e)
|
||||
{
|
||||
gui.setVisible(true);
|
||||
gui.setState(Frame.NORMAL); // unminimize
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public ClientUI getGui()
|
||||
{
|
||||
return gui;
|
||||
@@ -280,10 +219,4 @@ public class RuneLite
|
||||
{
|
||||
RuneLite.options = options;
|
||||
}
|
||||
|
||||
public static TrayIcon getTrayIcon()
|
||||
{
|
||||
return trayIcon;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,11 +26,20 @@ package net.runelite.client.ui;
|
||||
|
||||
import java.applet.Applet;
|
||||
import com.google.common.base.Strings;
|
||||
import java.awt.AWTException;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Frame;
|
||||
import java.awt.SystemTray;
|
||||
import java.awt.TrayIcon;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.util.Enumeration;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
@@ -39,6 +48,7 @@ import javax.swing.ScrollPaneConstants;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.plaf.FontUIResource;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.GameState;
|
||||
@@ -53,6 +63,9 @@ public class ClientUI extends JFrame
|
||||
private static final int SCROLLBAR_WIDTH = 17;
|
||||
private static final int EXPANDED_WIDTH = CLIENT_WIDTH + PluginPanel.PANEL_WIDTH + SCROLLBAR_WIDTH;
|
||||
|
||||
@Getter
|
||||
private TrayIcon trayIcon;
|
||||
|
||||
private final Applet client;
|
||||
private final RuneliteProperties properties;
|
||||
private JPanel container;
|
||||
@@ -60,18 +73,20 @@ public class ClientUI extends JFrame
|
||||
private ClientPanel panel;
|
||||
private PluginToolbar pluginToolbar;
|
||||
private PluginPanel pluginPanel;
|
||||
private BufferedImage icon;
|
||||
|
||||
public ClientUI(RuneliteProperties properties, Applet client)
|
||||
{
|
||||
this.properties = properties;
|
||||
this.client = client;
|
||||
setUIFont(new FontUIResource(FontManager.getRunescapeFont()));
|
||||
setupTrayIcon();
|
||||
init();
|
||||
pack();
|
||||
TitleBarPane titleBarPane = new TitleBarPane(this.getRootPane(), (SubstanceRootPaneUI)this.getRootPane().getUI());
|
||||
titleBarPane.editTitleBar(this);
|
||||
setTitle(null);
|
||||
setIconImage(RuneLite.ICON);
|
||||
setIconImage(icon);
|
||||
setLocationRelativeTo(getOwner());
|
||||
setResizable(true);
|
||||
setVisible(true);
|
||||
@@ -93,6 +108,49 @@ public class ClientUI extends JFrame
|
||||
}
|
||||
}
|
||||
|
||||
private void setupTrayIcon()
|
||||
{
|
||||
if (!SystemTray.isSupported())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SystemTray systemTray = SystemTray.getSystemTray();
|
||||
|
||||
try
|
||||
{
|
||||
icon = ImageIO.read(ClientUI.class.getResourceAsStream("/runelite.png"));
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
log.warn("Client icon failed to load", e);
|
||||
}
|
||||
|
||||
trayIcon = new TrayIcon(icon, properties.getTitle());
|
||||
trayIcon.setImageAutoSize(true);
|
||||
|
||||
try
|
||||
{
|
||||
systemTray.add(trayIcon);
|
||||
}
|
||||
catch (AWTException ex)
|
||||
{
|
||||
log.debug("Unable to add system tray icon", ex);
|
||||
return;
|
||||
}
|
||||
|
||||
// bring to front when tray icon is clicked
|
||||
trayIcon.addMouseListener(new MouseAdapter()
|
||||
{
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e)
|
||||
{
|
||||
setVisible(true);
|
||||
setState(Frame.NORMAL); // unminimize
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setTitle(String extra)
|
||||
|
||||
Reference in New Issue
Block a user