Changeset 85bb495


Ignore:
Timestamp:
Nov 19, 2017 12:40:50 AM (3 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
3ba46f16
Parents:
0ba207c
Message:

DTG: On OSX, set dock icon, and enable by default

Location:
apps
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • apps/desktopgui/src/net/i2p/desktopgui/Main.java

    r0ba207c r85bb495  
    44 * Main.java
    55 */
     6
     7import java.awt.Image;
     8import java.awt.Toolkit;
     9import java.io.File;
     10import java.lang.reflect.Method;
     11import java.net.URL;
    612
    713import javax.swing.SwingUtilities;
     
    2531public class Main implements RouterApp {
    2632
     33    // non-null
    2734    private final I2PAppContext _appContext;
     35    // warning, null in app context
    2836    private final RouterContext _context;
    2937    private final ClientAppManager _mgr;
     
    107115            return;
    108116        }
     117        if (SystemVersion.isMac())
     118            setMacTrayIcon();
    109119
    110120        // TODO process args with getopt if needed
     
    128138        });
    129139
     140    }
     141   
     142    /**
     143     *  Unless we do this, when we start DesktopGUI we get a Java coffee cup
     144     *  in the tray.
     145     *
     146     *  Based on code from https://gist.github.com/bchapuis/1562406 , no apparent license.
     147     *  See also https://stackoverflow.com/questions/6006173/how-do-you-change-the-dock-icon-of-a-java-program
     148     *
     149     *  TODO, if we wanted to add our own menu, see
     150     *  https://stackoverflow.com/questions/1319805/java-os-x-dock-menu
     151     *
     152     *  TODO, if we want to make it bounce, see
     153     *  https://stackoverflow.com/questions/15079783/how-to-make-my-app-icon-bounce-in-the-mac-dock
     154     *
     155     *  TODO, if we want to handle Quit, see
     156     *  https://nakkaya.com/2009/04/19/java-osx-integration/
     157     *
     158     *  @since 0.9.33
     159     */
     160    @SuppressWarnings("unchecked")
     161    private void setMacTrayIcon() {
     162        File f = new File(_appContext.getBaseDir(), "docs/themes/console/images/itoopie_sm.png");
     163        if (!f.exists())
     164            return;
     165        try {
     166            Class util = Class.forName("com.apple.eawt.Application");
     167            Method getApplication = util.getMethod("getApplication", new Class[0]);
     168            Object application = getApplication.invoke(util);
     169            Class params[] = new Class[1];
     170            params[0] = Image.class;
     171            Method setDockIconImage = util.getMethod("setDockIconImage", params);
     172            URL url = f.toURI().toURL();
     173            Image image = Toolkit.getDefaultToolkit().getImage(url);
     174            setDockIconImage.invoke(application, image);
     175        } catch (Exception e) {
     176            if (log.shouldWarn())
     177                log.warn("Can't set OSX Dock icon", e);
     178        }
    130179    }
    131180   
  • apps/routerconsole/java/src/net/i2p/router/web/ConfigServiceHandler.java

    r0ba207c r85bb495  
    203203        return !
    204204            (SystemVersion.isLinuxService() ||
    205              (SystemVersion.isWindows() && _context.hasWrapper() && WrapperManager.isLaunchedAsService()) ||
    206              // headless=true is forced in i2prouter script to prevent useless dock icon;
    207              // must fix this first
    208              SystemVersion.isMac());
     205             (SystemVersion.isWindows() && _context.hasWrapper() && WrapperManager.isLaunchedAsService()));
    209206    }
    210207
     
    215212     */
    216213    public boolean isSystrayEnabled() {
    217         // default false for now, except on non-service windows
     214        // default false for now, except on OSX and non-service windows
    218215        String sdtg = _context.getProperty(RouterConsoleRunner.PROP_DTG_ENABLED);
    219216        return Boolean.parseBoolean(sdtg) ||
    220                (sdtg == null && SystemVersion.isWindows());
     217               (sdtg == null && (SystemVersion.isWindows() || SystemVersion.isMac()));
    221218    }
    222219
  • apps/routerconsole/java/src/net/i2p/router/web/RouterConsoleRunner.java

    r0ba207c r85bb495  
    299299        }
    300300        try {
    301             // default false for now, except on non-service windows
     301            // default false for now, except on OSX and non-service windows
    302302            String sdtg = _context.getProperty(PROP_DTG_ENABLED);
    303303            boolean desktopguiEnabled = Boolean.parseBoolean(sdtg) ||
    304                                         (sdtg == null && SystemVersion.isWindows());
     304                                        (sdtg == null && (SystemVersion.isWindows() || SystemVersion.isMac()));
    305305            if (desktopguiEnabled) {
    306306                System.setProperty("java.awt.headless", "false");
Note: See TracChangeset for help on using the changeset viewer.