Notifications on rips when window is hidden #11

This commit is contained in:
4pr0n 2014-04-07 21:57:18 -07:00
parent 12e199ae60
commit a5e3acc386
5 changed files with 110 additions and 60 deletions

View File

@ -4,7 +4,7 @@
<groupId>com.rarchives.ripme</groupId> <groupId>com.rarchives.ripme</groupId>
<artifactId>ripme</artifactId> <artifactId>ripme</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<version>1.0.9</version> <version>1.0.10</version>
<name>ripme</name> <name>ripme</name>
<url>http://rip.rarchives.com</url> <url>http://rip.rarchives.com</url>
<properties> <properties>

View File

@ -25,6 +25,8 @@ public class App {
public static final Logger logger = Logger.getLogger(App.class); public static final Logger logger = Logger.getLogger(App.class);
public static void main(String[] args) throws MalformedURLException { public static void main(String[] args) throws MalformedURLException {
System.setProperty("apple.laf.useScreenMenuBar", "true");
System.setProperty("com.apple.mrj.application.apple.menu.about.name", "RipMe");
logger.info("Initialized ripme v" + UpdateUtils.getThisJarVersion()); logger.info("Initialized ripme v" + UpdateUtils.getThisJarVersion());
UpdateUtils.moveUpdatedJar(); UpdateUtils.moveUpdatedJar();
if (args.length > 0) { if (args.length > 0) {

View File

@ -71,7 +71,7 @@ class AutoripThread extends Thread {
String url = m.group(); String url = m.group();
if (!rippedURLs.contains(url)) { if (!rippedURLs.contains(url)) {
rippedURLs.add(url); rippedURLs.add(url);
// TODO Start rip // TODO Queue rip instead of just starting it
MainWindow.ripAlbumStatic(url); MainWindow.ripAlbumStatic(url);
} }
} }

View File

@ -13,10 +13,15 @@ import java.awt.MenuItem;
import java.awt.PopupMenu; import java.awt.PopupMenu;
import java.awt.SystemTray; import java.awt.SystemTray;
import java.awt.TrayIcon; import java.awt.TrayIcon;
import java.awt.TrayIcon.MessageType;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.ItemEvent; import java.awt.event.ItemEvent;
import java.awt.event.ItemListener; import java.awt.event.ItemListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File; import java.io.File;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
@ -96,6 +101,7 @@ public class MainWindow implements Runnable, RipStatusHandler {
private static JTextField configRetriesText; private static JTextField configRetriesText;
private static JCheckBox configAutoupdateCheckbox; private static JCheckBox configAutoupdateCheckbox;
private static TrayIcon trayIcon;
private static MenuItem trayMenuMain; private static MenuItem trayMenuMain;
private static MenuItem trayMenuAbout; private static MenuItem trayMenuAbout;
private static MenuItem trayMenuExit; private static MenuItem trayMenuExit;
@ -174,63 +180,7 @@ public class MainWindow implements Runnable, RipStatusHandler {
} }
private void createUI(Container pane) { private void createUI(Container pane) {
// System tray setupTrayIcon();
PopupMenu trayMenu = new PopupMenu();
trayMenuMain = new MenuItem(mainFrame.getTitle());
trayMenuMain.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
if (mainFrame.isVisible()) {
mainFrame.setVisible(false);
trayMenuMain.setLabel("Show");
} else {
mainFrame.setVisible(true);
trayMenuMain.setLabel("Hide");
}
}
});
trayMenuAbout = new MenuItem("About " + mainFrame.getTitle());
trayMenuAbout.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
String aboutBlurb = "<html><center> Download albums from various websites. <a href=\"http://rarchives.com\">rarchives.com</a>";
JOptionPane.showMessageDialog(null,
aboutBlurb,
mainFrame.getTitle(),
JOptionPane.PLAIN_MESSAGE,
new ImageIcon(mainIcon));
}
});
trayMenuExit = new MenuItem("Exit");
trayMenuExit.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
System.exit(0);
}
});
trayMenuAutorip = new CheckboxMenuItem("Clipboard Autorip");
trayMenuAutorip.setState(ClipboardUtils.getClipboardAutoRip());
trayMenuAutorip.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent arg0) {
ClipboardUtils.setClipboardAutoRip(trayMenuAutorip.getState());
}
});
trayMenu.add(trayMenuMain);
trayMenu.add(trayMenuAbout);
trayMenu.addSeparator();
trayMenu.add(trayMenuAutorip);
trayMenu.addSeparator();
trayMenu.add(trayMenuExit);
try {
mainIcon = ImageIO.read(getClass().getClassLoader().getResource("icon.png"));
TrayIcon trayIcon = new TrayIcon(mainIcon);
trayIcon.setToolTip(mainFrame.getTitle());
trayIcon.setPopupMenu(trayMenu);
SystemTray.getSystemTray().add(trayIcon);
} catch (Exception e) {
e.printStackTrace();
}
EmptyBorder emptyBorder = new EmptyBorder(5, 5, 5, 5); EmptyBorder emptyBorder = new EmptyBorder(5, 5, 5, 5);
GridBagConstraints gbc = new GridBagConstraints(); GridBagConstraints gbc = new GridBagConstraints();
@ -263,6 +213,7 @@ public class MainWindow implements Runnable, RipStatusHandler {
gbc.gridx = 0; statusPanel.add(statusLabel, gbc); gbc.gridx = 0; statusPanel.add(statusLabel, gbc);
gbc.gridy = 1; statusPanel.add(openButton, gbc); gbc.gridy = 1; statusPanel.add(openButton, gbc);
gbc.gridy = 0;
JPanel progressPanel = new JPanel(new GridBagLayout()); JPanel progressPanel = new JPanel(new GridBagLayout());
progressPanel.setBorder(emptyBorder); progressPanel.setBorder(emptyBorder);
@ -485,6 +436,92 @@ public class MainWindow implements Runnable, RipStatusHandler {
}); });
} }
private void setupTrayIcon() {
mainFrame.addWindowListener(new WindowAdapter() {
public void windowActivated(WindowEvent e) { trayMenuMain.setLabel("Hide"); }
public void windowDeactivated(WindowEvent e) { trayMenuMain.setLabel("Show"); }
public void windowDeiconified(WindowEvent e) { trayMenuMain.setLabel("Hide"); }
public void windowIconified(WindowEvent e) { trayMenuMain.setLabel("Show"); }
});
PopupMenu trayMenu = new PopupMenu();
trayMenuMain = new MenuItem("Hide");
trayMenuMain.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
toggleTrayClick();
}
});
trayMenuAbout = new MenuItem("About " + mainFrame.getTitle());
trayMenuAbout.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
String aboutBlurb = "<html><center> Download albums from various websites. <a href=\"http://rarchives.com\">rarchives.com</a>";
JOptionPane.showMessageDialog(null,
aboutBlurb,
mainFrame.getTitle(),
JOptionPane.PLAIN_MESSAGE,
new ImageIcon(mainIcon));
}
});
trayMenuExit = new MenuItem("Exit");
trayMenuExit.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
System.exit(0);
}
});
trayMenuAutorip = new CheckboxMenuItem("Clipboard Autorip");
trayMenuAutorip.setState(ClipboardUtils.getClipboardAutoRip());
trayMenuAutorip.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent arg0) {
ClipboardUtils.setClipboardAutoRip(trayMenuAutorip.getState());
}
});
trayMenu.add(trayMenuMain);
trayMenu.add(trayMenuAbout);
trayMenu.addSeparator();
trayMenu.add(trayMenuAutorip);
trayMenu.addSeparator();
trayMenu.add(trayMenuExit);
try {
mainIcon = ImageIO.read(getClass().getClassLoader().getResource("icon.png"));
trayIcon = new TrayIcon(mainIcon);
trayIcon.setToolTip(mainFrame.getTitle());
trayIcon.setImageAutoSize(true);
trayIcon.setPopupMenu(trayMenu);
SystemTray.getSystemTray().add(trayIcon);
trayIcon.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
toggleTrayClick();
if (mainFrame.getExtendedState() != JFrame.NORMAL) {
mainFrame.setExtendedState(JFrame.NORMAL);
}
mainFrame.setAlwaysOnTop(true);
mainFrame.setAlwaysOnTop(false);
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
private void toggleTrayClick() {
if (mainFrame.getExtendedState() == JFrame.ICONIFIED
|| !mainFrame.isActive()
|| !mainFrame.isVisible()) {
mainFrame.setVisible(true);
mainFrame.setAlwaysOnTop(true);
mainFrame.setAlwaysOnTop(false);
trayMenuMain.setLabel("Hide");
}
else {
mainFrame.setVisible(false);
trayMenuMain.setLabel("Show");
}
}
private void appendLog(final String text, final Color color) { private void appendLog(final String text, final Color color) {
SimpleAttributeSet sas = new SimpleAttributeSet(); SimpleAttributeSet sas = new SimpleAttributeSet();
StyleConstants.setForeground(sas, color); StyleConstants.setForeground(sas, color);
@ -547,6 +584,17 @@ public class MainWindow implements Runnable, RipStatusHandler {
ripper.setObserver((RipStatusHandler) this); ripper.setObserver((RipStatusHandler) this);
Thread t = new Thread(ripper); Thread t = new Thread(ripper);
t.start(); t.start();
if (!mainFrame.isVisible()) {
mainFrame.toFront();
mainFrame.setAlwaysOnTop(true);
trayIcon.displayMessage(mainFrame.getTitle(), "Started ripping " + ripper.getURL().toExternalForm(), MessageType.INFO);
mainFrame.setAlwaysOnTop(false);
} else if (!mainFrame.isActive()) {
mainFrame.toFront();
mainFrame.setAlwaysOnTop(true);
trayIcon.displayMessage(mainFrame.getTitle(), "Started ripping " + ripper.getURL().toExternalForm(), MessageType.INFO);
mainFrame.setAlwaysOnTop(false);
}
return t; return t;
} catch (Exception e) { } catch (Exception e) {
logger.error("[!] Error while ripping: " + e.getMessage(), e); logger.error("[!] Error while ripping: " + e.getMessage(), e);

View File

@ -17,7 +17,7 @@ import org.jsoup.nodes.Document;
public class UpdateUtils { public class UpdateUtils {
private static final Logger logger = Logger.getLogger(UpdateUtils.class); private static final Logger logger = Logger.getLogger(UpdateUtils.class);
private static final String DEFAULT_VERSION = "1.0.9"; private static final String DEFAULT_VERSION = "1.0.10";
private static final String updateJsonURL = "http://rarchives.com/ripme.json"; private static final String updateJsonURL = "http://rarchives.com/ripme.json";
private static final String updateJarURL = "http://rarchives.com/ripme.jar"; private static final String updateJarURL = "http://rarchives.com/ripme.jar";
private static final String mainFileName = "ripme.jar"; private static final String mainFileName = "ripme.jar";