Skip to content

Commit

Permalink
Merge branch 'master' of i2pgit.org:i2p-hackers/i2p.i2p into i2p.i2p.…
Browse files Browse the repository at this point in the history
…2.2.1-xor-messageIDs-as-interface-change
  • Loading branch information
eyedeekay committed May 31, 2023
2 parents ed51f15 + 63f2ae3 commit e23ebeb
Show file tree
Hide file tree
Showing 10 changed files with 458 additions and 10 deletions.
89 changes: 87 additions & 2 deletions apps/desktopgui/src/net/i2p/desktopgui/ExternalMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import net.i2p.app.ClientAppManager;
import net.i2p.app.ClientApp;
import net.i2p.app.ClientAppState;
import net.i2p.app.MenuCallback;
import net.i2p.app.MenuHandle;
import net.i2p.app.MenuService;
import net.i2p.app.NotificationService;
import net.i2p.util.Log;
import net.i2p.util.SystemVersion;
Expand All @@ -24,7 +27,7 @@
*
* @since 0.9.54
*/
public class ExternalMain implements ClientApp, NotificationService {
public class ExternalMain implements ClientApp, NotificationService, MenuService {

private final I2PAppContext _appContext;
private final ClientAppManager _mgr;
Expand Down Expand Up @@ -60,7 +63,6 @@ public static void main(String[] args) {
* @throws AWTException on startup error, including systray not supported
*/
private synchronized void startUp() throws Exception {
final TrayManager trayManager;
boolean useSwingDefault = !(SystemVersion.isWindows() || SystemVersion.isMac());
boolean useSwing = _appContext.getProperty(PROP_SWING, useSwingDefault);
_trayManager = new ExternalTrayManager(_appContext, useSwing);
Expand Down Expand Up @@ -200,6 +202,89 @@ public boolean update(int id, String title, String message, String path) {
return false;
}

/////// MenuService methods

/**
* Menu will start out shown and enabled, in the root menu
*
* @param message for the menu, translated
* @param callback fired on click
* @return null on error
* @since 0.9.59
*/
public MenuHandle addMenu(String message, MenuCallback callback) {
return addMenu(message, callback, null);
}

/**
* Menu will start out enabled, as a submenu
*
* @param message for the menu, translated
* @param callback fired on click
* @param parent the parent menu this will be a submenu of, or null for top level
* @return null on error
* @since 0.9.59
*/
public MenuHandle addMenu(String message, MenuCallback callback, MenuHandle parent) {
if (_trayManager == null)
return null;
return _trayManager.addMenu(message, callback, parent);
}

/**
* @since 0.9.59
*/
public void removeMenu(MenuHandle item) {
if (_trayManager == null)
return;
_trayManager.removeMenu(item);
}

/**
* @since 0.9.59
*/
public void showMenu(MenuHandle item) {
if (_trayManager == null)
return;
_trayManager.showMenu(item);
}

/**
* @since 0.9.59
*/
public void hideMenu(MenuHandle item) {
if (_trayManager == null)
return;
_trayManager.hideMenu(item);
}

/**
* @since 0.9.59
*/
public void enableMenu(MenuHandle item) {
if (_trayManager == null)
return;
_trayManager.enableMenu(item);
}

/**
* @since 0.9.59
*/
public void disableMenu(MenuHandle item) {
if (_trayManager == null)
return;
_trayManager.disableMenu(item);
}

/**
* @since 0.9.59
*/
public void updateMenu(String message, MenuHandle item) {
if (_trayManager == null)
return;
_trayManager.updateMenu(message, item);
}

/////// ClientApp methods

public synchronized void startup() {
Expand Down
88 changes: 87 additions & 1 deletion apps/desktopgui/src/net/i2p/desktopgui/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
import net.i2p.app.ClientAppManager;
import net.i2p.app.ClientAppState;
import static net.i2p.app.ClientAppState.*;
import net.i2p.app.MenuCallback;
import net.i2p.app.MenuHandle;
import net.i2p.app.MenuService;
import net.i2p.app.NotificationService;
import net.i2p.desktopgui.router.RouterManager;
import net.i2p.router.RouterContext;
Expand All @@ -29,7 +32,7 @@
/**
* The main class of the application.
*/
public class Main implements RouterApp, NotificationService {
public class Main implements RouterApp, NotificationService, MenuService {

// non-null
private final I2PAppContext _appContext;
Expand Down Expand Up @@ -245,6 +248,89 @@ public boolean update(int id, String title, String message, String path) {
return false;
}

/////// MenuService methods

/**
* Menu will start out shown and enabled, in the root menu
*
* @param message for the menu, translated
* @param callback fired on click
* @return null on error
* @since 0.9.59
*/
public MenuHandle addMenu(String message, MenuCallback callback) {
return addMenu(message, callback, null);
}

/**
* Menu will start out enabled, as a submenu
*
* @param message for the menu, translated
* @param callback fired on click
* @param parent the parent menu this will be a submenu of, or null for top level
* @return null on error
* @since 0.9.59
*/
public MenuHandle addMenu(String message, MenuCallback callback, MenuHandle parent) {
if (_trayManager == null)
return null;
return _trayManager.addMenu(message, callback, parent);
}

/**
* @since 0.9.59
*/
public void removeMenu(MenuHandle item) {
if (_trayManager == null)
return;
_trayManager.removeMenu(item);
}

/**
* @since 0.9.59
*/
public void showMenu(MenuHandle item) {
if (_trayManager == null)
return;
_trayManager.showMenu(item);
}

/**
* @since 0.9.59
*/
public void hideMenu(MenuHandle item) {
if (_trayManager == null)
return;
_trayManager.hideMenu(item);
}

/**
* @since 0.9.59
*/
public void enableMenu(MenuHandle item) {
if (_trayManager == null)
return;
_trayManager.enableMenu(item);
}

/**
* @since 0.9.59
*/
public void disableMenu(MenuHandle item) {
if (_trayManager == null)
return;
_trayManager.disableMenu(item);
}

/**
* @since 0.9.59
*/
public void updateMenu(String message, MenuHandle item) {
if (_trayManager == null)
return;
_trayManager.updateMenu(message, item);
}

/////// ClientApp methods

/** @since 0.9.26 */
Expand Down
Loading

0 comments on commit e23ebeb

Please sign in to comment.