java.lang.Object
net.i2p.desktopgui.ExternalMain
- All Implemented Interfaces:
ClientApp, NotificationService
Simplified main class for App Context only, requiring only
i2p.jar. Provides basic system tray functionality without router.jar dependency. Uses ExternalTrayManager for limited I2P management capabilities.Field Summary
FieldsModifier and TypeFieldDescriptionprivate final I2PAppContextThe application context.private final ClientAppManagerRuns the client apps the tray shows.private TrayManagerThe tray icon and its menu.private final LogLogger for this class.private static final StringProperty asking for the Swing tray instead of the native one.Constructor Summary
ConstructorsConstructorDescriptionCreate a new ExternalMain using the global context.ExternalMain(I2PAppContext ctx, ClientAppManager mgr, String[] args) Create a new ExternalMain with the specified context and manager.Method Summary
Modifier and TypeMethodDescriptionprivate voidMain method launching the application.booleancancel(int id) Cancel a notification if possible.The display name of the ClientApp, used in user interfaces.getName()The generic name of the ClientApp, used for registration, e.g.getState()The current state of the ClientApp.private static voidAvoids the app terminating because no Window is opened anymore.static voidMain entry point for the external desktop GUI application.intSend a notification to the user.private voidUnless we do this, when we start DesktopGUI we get a Java coffee cup in the tray.voidDo not take a long time.voidstartup()//// ClientApp methodsprivate voidstartUp()Start the tray icon code (loads tray icon in the tray area).booleanUpdate the text of a notification if possible.
Field Details
_appContext
The application context._mgr
Runs the client apps the tray shows.log
Logger for this class._trayManager
The tray icon and its menu.PROP_SWING
Property asking for the Swing tray instead of the native one.- See Also:
Constructor Details
ExternalMain
Create a new ExternalMain with the specified context and manager.- Parameters:
ctx- the I2P application contextmgr- the client application managerargs- command line arguments (unused)
ExternalMain
public ExternalMain()Create a new ExternalMain using the global context.
Method Details
main
Main entry point for the external desktop GUI application.- Parameters:
args- command line arguments (unused)
startUp
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. The icon is set by reflection, so there is no compile or runtime dependency on the macOS-only eawt classes; every failure is logged and otherwise ignored, since this is cosmetic. This is the canonical documentation of the macOS integration:Mainhas a copy of this method. The dock menu, dock icon bounce and application Quit handling are not supported, and no code for them exists. Based on code from https://gist.github.com/bchapuis/1562406 , no apparent license. See also https://stackoverflow.com/questions/6006173/how-do-you-change-the-dock-icon-of-a-java-programlaunchForeverLoop
private static void launchForeverLoop()Avoids the app terminating because no Window is opened anymore. More info: AWT Thread Issuesnotify
public int notify(String source, String category, int priority, String title, String message, String path) Send a notification to the user.- Specified by:
notifyin interfaceNotificationService- Parameters:
source- ignored; the tray message takes no sourcecategory- ignored; the tray message takes no categorypriority- the Log.WARN-style level mapped to the tray message typetitle- for the popup, translatedmessage- the popup body text, translatedpath- ignored; the tray popup takes no icon path- Returns:
- 0, or -1 on failure
cancel
public boolean cancel(int id) Cancel a notification if possible. Unsupported.- Specified by:
cancelin interfaceNotificationService- Parameters:
id- as received fromNotificationService.notify(String, String, int, String, String, String)- Returns:
- false always
update
Update the text of a notification if possible. Unsupported.- Specified by:
updatein interfaceNotificationService- Parameters:
id- as received from notify()title- for the popup, translatedmessage- body text of the notification, translatedpath- in console starting with /, must be URL-escaped, or null- Returns:
- false always
startup
shutdown
Description copied from interface:ClientAppDo not take a long time. Do not block. Use a thread if necessary. If previously running, client must callClientAppManager.notify(ClientApp, ClientAppState, String, Exception)at least once within this method to change the state to STOPPING or STOPPED. May be called multiple times on the same object, in any state.getState
Description copied from interface:ClientAppThe current state of the ClientApp.getName
getDisplayName
Description copied from interface:ClientAppThe display name of the ClientApp, used in user interfaces. The app must translate.- Specified by:
getDisplayNamein interfaceClientApp- Returns:
- non-null