diff --git a/pom.xml b/pom.xml index b0b18606..6551c2fd 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.rarchives.ripme ripme jar - 1.0.9 + 1.0.10 ripme http://rip.rarchives.com diff --git a/src/main/java/com/rarchives/ripme/App.java b/src/main/java/com/rarchives/ripme/App.java index 929f3dfc..d45f4c55 100644 --- a/src/main/java/com/rarchives/ripme/App.java +++ b/src/main/java/com/rarchives/ripme/App.java @@ -25,6 +25,8 @@ public class App { public static final Logger logger = Logger.getLogger(App.class); 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()); UpdateUtils.moveUpdatedJar(); if (args.length > 0) { diff --git a/src/main/java/com/rarchives/ripme/ui/ClipboardUtils.java b/src/main/java/com/rarchives/ripme/ui/ClipboardUtils.java index 1cae501b..c6c3cbf4 100644 --- a/src/main/java/com/rarchives/ripme/ui/ClipboardUtils.java +++ b/src/main/java/com/rarchives/ripme/ui/ClipboardUtils.java @@ -71,7 +71,7 @@ class AutoripThread extends Thread { String url = m.group(); if (!rippedURLs.contains(url)) { rippedURLs.add(url); - // TODO Start rip + // TODO Queue rip instead of just starting it MainWindow.ripAlbumStatic(url); } } diff --git a/src/main/java/com/rarchives/ripme/ui/MainWindow.java b/src/main/java/com/rarchives/ripme/ui/MainWindow.java index 55edc01e..0a3b31e5 100644 --- a/src/main/java/com/rarchives/ripme/ui/MainWindow.java +++ b/src/main/java/com/rarchives/ripme/ui/MainWindow.java @@ -13,10 +13,15 @@ import java.awt.MenuItem; import java.awt.PopupMenu; import java.awt.SystemTray; import java.awt.TrayIcon; +import java.awt.TrayIcon.MessageType; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; 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.net.MalformedURLException; import java.net.URL; @@ -96,6 +101,7 @@ public class MainWindow implements Runnable, RipStatusHandler { private static JTextField configRetriesText; private static JCheckBox configAutoupdateCheckbox; + private static TrayIcon trayIcon; private static MenuItem trayMenuMain; private static MenuItem trayMenuAbout; private static MenuItem trayMenuExit; @@ -174,63 +180,7 @@ public class MainWindow implements Runnable, RipStatusHandler { } private void createUI(Container pane) { - // System tray - 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 = "
Download albums from various websites. rarchives.com"; - 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(); - } + setupTrayIcon(); EmptyBorder emptyBorder = new EmptyBorder(5, 5, 5, 5); GridBagConstraints gbc = new GridBagConstraints(); @@ -263,6 +213,7 @@ public class MainWindow implements Runnable, RipStatusHandler { gbc.gridx = 0; statusPanel.add(statusLabel, gbc); gbc.gridy = 1; statusPanel.add(openButton, gbc); + gbc.gridy = 0; JPanel progressPanel = new JPanel(new GridBagLayout()); progressPanel.setBorder(emptyBorder); @@ -484,6 +435,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 = "
Download albums from various websites. rarchives.com"; + 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) { SimpleAttributeSet sas = new SimpleAttributeSet(); @@ -547,6 +584,17 @@ public class MainWindow implements Runnable, RipStatusHandler { ripper.setObserver((RipStatusHandler) this); Thread t = new Thread(ripper); 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; } catch (Exception e) { logger.error("[!] Error while ripping: " + e.getMessage(), e); diff --git a/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java b/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java index 460cb9ae..5dd97679 100644 --- a/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java +++ b/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java @@ -17,7 +17,7 @@ import org.jsoup.nodes.Document; public class UpdateUtils { 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 updateJarURL = "http://rarchives.com/ripme.jar"; private static final String mainFileName = "ripme.jar";