java.lang.Object
net.i2p.desktopgui.Main
All Implemented Interfaces:
ClientApp, NotificationService, RouterApp

public class Mainextends Object implements RouterApp, NotificationService
Main entry point for the I2P Desktop GUI application. Implements RouterApp and NotificationService to provide system tray functionality with full router context access for comprehensive I2P management.
  • Field Details

    • _appContext

      private final I2PAppContext _appContext
      The app context, always present.
    • _context

      private final RouterContext _context
      The router context, null when running without a router.
    • _mgr

      private final ClientAppManager _mgr
      Starts and stops the client apps.
    • log

      private final Log log
      Logger for this class.
    • _state

      private ClientAppState _state
      The state the GUI is currently showing.
    • _trayManager

      private TrayManager _trayManager
      The system tray icon, null before startup.
    • PROP_ENABLE

      public static final String PROP_ENABLE
      Property to enable or disable the desktop GUI.
      See Also:
    • PROP_SWING

      private static final String PROP_SWING
      Property selecting the Swing implementation over AWT.
      See Also:
  • Constructor Details

    • Main

      public Main(RouterContext ctx, ClientAppManager mgr)
      Construct the GUI bound to a running router, so it registers with the given client app manager and gets the router's context directly.
      Parameters:
      ctx - router context supplying the global app context and logging
      mgr - ClientAppManager this GUI registers with, null when launched standalone
    • Main

      public Main()
      Construct the GUI from the global app context alone, for standalone launch outside a running router. The router context is left null when the global context is not a router context, and no client app manager is available to register with.
  • Method Details

    • startUp

      private void startUp() throws Exception
      Start the tray icon code (loads tray icon in the tray area).
      Throws:
      Exception - on startup error, including systray not supported
    • main

      public static void main(String[] args)
      Main entry point for the I2P Desktop GUI application.
      Parameters:
      args - command line arguments (unused)
    • beginStartup

      private void beginStartup()
      Main method launching the application.
    • setMacTrayIcon

      private void setMacTrayIcon()
      Unless we do this, when we start DesktopGUI we get a Java coffee cup in the tray. Same implementation as ExternalMain, which carries the canonical macOS notes.
    • launchForeverLoop

      private static void launchForeverLoop()
      Avoids the app terminating because no Window is opened anymore. More info: AWT Thread Issues
    • notify

      public int notify(String source, String category, int priority, String title, String message, String path)
      Send a notification to the user.
      Specified by:
      notify in interface NotificationService
      Parameters:
      source - ignored, the tray implementation does not use it
      category - ignored, the tray implementation does not use it
      priority - passed to TrayManager.displayMessage as the notice level
      title - for the popup, translated
      message - translated, shown as the body of the tray balloon
      path - icon path handed to the tray, may be null
      Returns:
      0, or -1 on failure
    • cancel

      public boolean cancel(int id)
      Cancel a notification if possible. Unsupported.
      Specified by:
      cancel in interface NotificationService
      Parameters:
      id - as received from NotificationService.notify(String, String, int, String, String, String)
      Returns:
      false always
    • update

      public boolean update(int id, String title, String message, String path)
      Update the text of a notification if possible. Unsupported.
      Specified by:
      update in interface NotificationService
      Parameters:
      id - as received from notify()
      title - for the popup, translated
      message - body text of the notification, translated
      path - in console starting with /, must be URL-escaped, or null
      Returns:
      false always
    • startup

      public void startup()
      Start the router.
      Specified by:
      startup in interface ClientApp
    • shutdown

      public void shutdown(String[] args)
      Stop the router.
      Specified by:
      shutdown in interface ClientApp
      Parameters:
      args - generally null but could be stopArgs from clients.config
    • getState

      public ClientAppState getState()
      Current router state.
      Specified by:
      getState in interface ClientApp
      Returns:
      non-null
    • getName

      public String getName()
      Name of the managed app.
      Specified by:
      getName in interface ClientApp
      Returns:
      non-null
    • getDisplayName

      public String getDisplayName()
      Display name of the managed app.
      Specified by:
      getDisplayName in interface ClientApp
      Returns:
      non-null
    • changeState

      private void changeState(ClientAppState state)
      Update the tray on a router state change.
      Parameters:
      state - the new client state to show in the tray
    • changeState

      private void changeState(ClientAppState state, String msg, Exception e)
      Update the tray with a state change message.
      Parameters:
      state - the new client state, recorded and passed to the tray manager
      msg - an optional message describing the change, null if none
      e - an optional exception to log with the change, null if none