Changeset fbeca5e


Ignore:
Timestamp:
Apr 29, 2016 2:57:29 PM (4 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
c2e486f
Parents:
d885e00
Message:

SysTray?: Remove systray4j.jar from linux installers
Move SysTray?.java to SysTrayImpl?.java
New SysTray?.java that instantiates SysTrayImpl?
by reflection, so the SysTrayImpl?.java source is optional
Remove systray4j.jar, systray4j.dll, and SysTrayImpl?.java
from Debian source packages
Remove systray4j.jar from Debian binary packages

Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • apps/systray/java/src/net/i2p/apps/systray/SysTray.java

    rd885e00 rfbeca5e  
    1 /*
    2  * I2P - An anonymous, secure, and fully-distributed communication network.
    3  *
    4  * SysTray.java
    5  * 2004 The I2P Project
    6  * http://www.i2p.net
    7  * This code is public domain.
    8  */
    9 
    101package net.i2p.apps.systray;
    112
    12 import java.awt.Frame;
    13 import java.io.File;
    14 import java.io.IOException;
     3import java.lang.reflect.Method;
    154
    16 import net.i2p.I2PAppContext;
    17 import net.i2p.util.SimpleTimer;
    18 import net.i2p.util.SimpleTimer2;
    195import net.i2p.util.SystemVersion;
    20 import snoozesoft.systray4j.SysTrayMenu;
    21 import snoozesoft.systray4j.SysTrayMenuEvent;
    22 import snoozesoft.systray4j.SysTrayMenuIcon;
    23 import snoozesoft.systray4j.SysTrayMenuItem;
    24 import snoozesoft.systray4j.SysTrayMenuListener;
    256
    267/**
    278 * A system tray control for launching the I2P router console.
    289 *
    29  * @author hypercubus
     10 * Not part of the public API. Works on 32-bit Windows only.
     11 * To be removed or replaced.
     12 *
     13 * @since implementation moved to SysTrayImpl in 0.9.26
    3014 */
    31 public class SysTray implements SysTrayMenuListener {
     15public class SysTray {
    3216
    33     private static BrowserChooser _browserChooser;
    34     private static String         _browserString;
    35     private static ConfigFile     _configFile     = new ConfigFile();
    36     private static Frame          _frame;
    37     private static SysTray        _instance;
    38     private static String         _portString;
    39     private static boolean        _showIcon;
    40     private static final boolean _is64 = SystemVersion.is64Bit();
    41 
    42     static {
    43         File config = new File(I2PAppContext.getGlobalContext().getConfigDir(), "systray.config");
    44         if (!_configFile.init(config.getAbsolutePath())) {
    45             _configFile.setProperty("browser", "default");
    46             _configFile.setProperty("port", "7657");
    47         }
    48 
    49         _browserString = _configFile.getProperty("browser", "default");
    50         _portString = _configFile.getProperty("port", "7657");
    51         _showIcon = Boolean.parseBoolean(_configFile.getProperty("visible", "true"));
    52 
    53         //if (!(new File("router.config")).exists())
    54         //    openRouterConsole("http://localhost:" + _portString + "/index.jsp");
    55 
    56         if ( (SystemVersion.isWindows()) && (!Boolean.getBoolean("systray.disable")) && (!_is64))
    57             _instance = new SysTray();
     17    /**
     18     *  Warning - systray4j.jar may not be present - may return null.
     19     *  As of 0.9.26, uses reflection so we may compile without systray4j.jar.
     20     *
     21     *  @return null if not supported, since 0.9.26 (prior to that would throw NoClassDefFoundError)
     22     *  @since 0.8.1
     23     */
     24    public static SysTray getInstance() {
     25        if (SystemVersion.isWindows() && !SystemVersion.is64Bit())
     26            return getImpl();
     27        return null;
    5828    }
    5929
    60     private SysTrayMenuItem _itemOpenConsole   = new SysTrayMenuItem("Open router console", "openconsole");
    61     private SysTrayMenuItem _itemSelectBrowser = new SysTrayMenuItem("Select browser...", "selectbrowser");
    62 //    private SysTrayMenuItem _itemShutdown      = new SysTrayMenuItem("Shut down I2P router", "shutdown");
    63     private SysTrayMenuIcon _sysTrayMenuIcon   = new SysTrayMenuIcon("icons/iggy");
    64     private SysTrayMenu     _sysTrayMenu       = new SysTrayMenu(_sysTrayMenuIcon, "I2P Control");
    65 
    66     private SysTray() {
    67         _sysTrayMenuIcon.addSysTrayMenuListener(this);
    68         createSysTrayMenu();
    69         SimpleTimer2.getInstance().addPeriodicEvent(new RefreshDisplayEvent(), REFRESH_DISPLAY_FREQUENCY);
    70     }
    71    
    72     private static final long REFRESH_DISPLAY_FREQUENCY = 30*1000;
    73     private class RefreshDisplayEvent implements SimpleTimer.TimedEvent {
    74         public void timeReached() {
    75             refreshDisplay();
     30    /**
     31     *  Warning - systray4j.jar may not be present - may return null
     32     *
     33     *  @return null if not supported
     34     *  @since 0.9.26
     35     */
     36    private static SysTray getImpl() {
     37        try {
     38            Class<?> impl = Class.forName("net.i2p.apps.systray.SysTrayImpl", true, ClassLoader.getSystemClassLoader());
     39            Method getInstance = impl.getMethod("getInstance");
     40            return (SysTray) getInstance.invoke(null,(Object[])  null);
     41        } catch (Throwable t) {
     42            System.out.println("WARN: Unable to start systray");
     43            t.printStackTrace();
     44            return null;
    7645        }
    7746    }
    7847
    79     public static synchronized SysTray getInstance() {
    80         return _instance;
    81     }
    82 
    83     private static void openRouterConsole(String url) {
    84 
    85         String browser = null;
    86         UrlLauncher urlLauncher = new UrlLauncher();
    87 
    88         if (_browserString == null || _browserString.equals("default")) {
    89             try {
    90                 if (urlLauncher.openUrl(url))
    91                     return;
    92             } catch (IOException ex) {
    93                 // Fall through.
    94             }
    95         } else {
    96             try {
    97                 if (urlLauncher.openUrl(url, _browserString))
    98                     return;
    99             } catch (IOException ex) {
    100                 // Fall through.
    101             }
     48    /**
     49     *  This mimics what is now in SysTrayImpl.main(),
     50     *  not that anybody was using that.
     51     */
     52    public static void main(String[] args) {
     53        SysTray impl = getImpl();
     54        if (impl == null) {
     55            System.out.println("No systray implementation found");
     56            System.exit(1);
    10257        }
    103 
    104         if (!(browser = promptForBrowser("Please select another browser")).equals("nullnull"))
    105             setBrowser(browser);
    106     }
    107 
    108     private static String promptForBrowser(String windowTitle) {
    109 
    110         String browser = null;
    111 
    112         _frame = new Frame();
    113         _browserChooser = new BrowserChooser(_frame, windowTitle);
    114         browser = _browserChooser.getDirectory() + _browserChooser.getFile();
    115         _browserChooser = null;
    116         _frame = null;
    117         return browser;
    118     }
    119 
    120     private static void setBrowser(String browser) {
    121         _browserString = browser;
    122         _configFile.setProperty("browser", browser);
    123     }
    124 
    125     public void refreshDisplay() {
    126         if (_showIcon)
    127             _sysTrayMenu.showIcon();
    128         else
    129             _sysTrayMenu.hideIcon();
    130     }
    131    
    132     public void hide() {
    133         _configFile.setProperty("visible", "false");
    134         _showIcon = false;
    135         _sysTrayMenu.hideIcon();
    136     }
    137 
    138     public void iconLeftClicked(SysTrayMenuEvent e) {}
    139 
    140     public void iconLeftDoubleClicked(SysTrayMenuEvent e) {
    141         openRouterConsole("http://127.0.0.1:" + _portString + "/index.jsp");
    142     }
    143 
    144     public void menuItemSelected(SysTrayMenuEvent e) {
    145 
    146         String browser = null;
    147 
    148 //        if (e.getActionCommand().equals("shutdown")) {
    149 //            _browserChooser = null;
    150 //            _frame = null;
    151 //            _itemShutdown = null;
    152 //            _itemSelectBrowser = null;
    153 //            _sysTrayMenuIcon = null;
    154 //            _sysTrayMenu = null;
    155 //            _browserChooser = null;
    156 //            _frame = null;
    157 //            System.exit(0);
    158         if (e.getActionCommand().equals("selectbrowser")) {
    159             if (!(browser = promptForBrowser("Select browser")).equals("nullnull"))
    160                 setBrowser(browser);
    161         } else if (e.getActionCommand().equals("openconsole")) {
    162             openRouterConsole("http://127.0.0.1:" + _portString + "/index.jsp");
    163         }
    164     }
    165 
    166     public void show() {
    167         _configFile.setProperty("visible", "true");
    168         _showIcon = true;
    169         _sysTrayMenu.showIcon();
    170     }
    171 
    172     private void createSysTrayMenu() {
    173 //        _itemShutdown.addSysTrayMenuListener(this);
    174         _itemSelectBrowser.addSysTrayMenuListener(this);
    175         _itemOpenConsole.addSysTrayMenuListener(this);
    176 //        _sysTrayMenu.addItem(_itemShutdown);
    177 //        _sysTrayMenu.addSeparator();
    178         // hide it, as there have been reports of b0rked behavior on some JVMs.
    179         // specifically, that on XP & sun1.5.0.1, a user launching i2p w/out the
    180         // service wrapper would create netDb/, peerProfiles/, and other files
    181         // underneath each directory browsed to - as if the router's "." directory
    182         // is changing whenever the itemSelectBrowser's JFileChooser changed
    183         // directories.  This has not been reproduced or confirmed yet, but is
    184         // pretty scary, and this function isn't too necessary.
    185         //_sysTrayMenu.addItem(_itemSelectBrowser);
    186         _sysTrayMenu.addItem(_itemOpenConsole);
    187         refreshDisplay();
    188     }
    189 
    190     /**
    191      *  Starts SysTray, even on linux (but requires kde3 libsystray4j.so to do anything)
    192      *  @since 0.8.1
    193      */
    194     public static void main(String args[]) {
    195         System.err.println("SysTray4j version " + SysTrayMenu.VERSION);
    19658        System.err.println("Hit ^C to exit");
    197         new SysTray();
    19859        Thread t = Thread.currentThread();
    19960        synchronized(t) {
  • build.xml

    rd885e00 rfbeca5e  
    11301130    <target name="preppkg-windows" depends="preppkg-base, preplicenses-windows, buildUtilityJar, buildexe">
    11311131        <copy file="build/i2p.exe" todir="pkg-temp/" failonerror="false" />
     1132        <copy file="apps/systray/java/lib/systray4j.jar" todir="pkg-temp/lib" />
    11321133        <copy file="apps/systray/java/lib/systray4j.dll" todir="pkg-temp/lib" />
    11331134        <copy file="apps/systray/java/resources/iggy.ico" todir="pkg-temp/icons" />
     
    11741175        <copy file="build/systray.jar" todir="pkg-temp/lib" />
    11751176        <copy file="build/i2psnark.jar" todir="pkg-temp/lib/" />
    1176         <copy file="apps/systray/java/lib/systray4j.jar" todir="pkg-temp/lib" />
    11771177        <copy file="build/i2ptunnel.war" todir="pkg-temp/webapps/" />
    11781178        <copy file="build/routerconsole.war" todir="pkg-temp/webapps/" />
     
    20272027            <fileset dir="../i2p-${Extended.Version}/Slackware" />
    20282028            <fileset dir="../i2p-${Extended.Version}/_MTN" />
     2029            <!-- systray4j -->
     2030            <fileset dir="../i2p-${Extended.Version}/apps/systray/java/lib" />
     2031            <file name="../i2p-${Extended.Version}/apps/systray/java/src/net/i2p/apps/systray/SysTrayImpl.java" />
    20292032            <!-- geoip-database -->
    20302033            <file name="../i2p-${Extended.Version}/installer/resources/geoip.txt" />
     
    20922095            <fileset dir="../i2p-${Extended.Version}/Slackware" />
    20932096            <fileset dir="../i2p-${Extended.Version}/_MTN" />
     2097            <fileset dir="../i2p-${Extended.Version}/apps/systray/java/lib" />
     2098            <file name="../i2p-${Extended.Version}/apps/systray/java/src/net/i2p/apps/systray/SysTrayImpl.java" />
    20942099            <file name="../i2p-${Extended.Version}/installer/resources/geoip.txt" />
    20952100            <file name="../i2p-${Extended.Version}/installer/resources/geoipv6.dat.gz" />
  • debian/i2p-router.install

    rd885e00 rfbeca5e  
    3232pkg-temp/lib/sam.jar usr/share/i2p/lib
    3333pkg-temp/lib/streaming.jar usr/share/i2p/lib
    34 pkg-temp/lib/systray4j.jar usr/share/i2p/lib
    3534pkg-temp/lib/systray.jar usr/share/i2p/lib
    3635
Note: See TracChangeset for help on using the changeset viewer.