From 962cc31f315cf652b87d0ce120fbf23d36a791a2 Mon Sep 17 00:00:00 2001 From: zzz <zzz@i2pmail.org> Date: Sat, 4 Dec 2021 09:50:08 -0500 Subject: [PATCH] DTG: Show all CRIT messages on DTG. Experimental, may add a separate config or disable later. Show I2P starting message in DTG --- .../i2p/desktopgui/InternalTrayManager.java | 9 +++++ core/java/src/net/i2p/util/LogWriter.java | 35 +++++++++++++++++-- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/apps/desktopgui/src/net/i2p/desktopgui/InternalTrayManager.java b/apps/desktopgui/src/net/i2p/desktopgui/InternalTrayManager.java index eeb9c958d3..2d98fd22a1 100644 --- a/apps/desktopgui/src/net/i2p/desktopgui/InternalTrayManager.java +++ b/apps/desktopgui/src/net/i2p/desktopgui/InternalTrayManager.java @@ -1,5 +1,6 @@ package net.i2p.desktopgui; +import java.awt.AWTException; import java.awt.Desktop; import java.awt.Desktop.Action; import java.awt.MenuItem; @@ -44,6 +45,14 @@ class InternalTrayManager extends TrayManager { log = ctx.logManager().getLog(InternalTrayManager.class); } + /** + * @since 0.9.53 + */ + public void startManager() throws AWTException { + super.startManager(); + displayMessage(Log.INFO, _t("Starting"), _t("I2P is starting!"), null); + } + public synchronized PopupMenu getMainMenu() { PopupMenu popup = new PopupMenu(); diff --git a/core/java/src/net/i2p/util/LogWriter.java b/core/java/src/net/i2p/util/LogWriter.java index 172b7aa15b..9d7275e1e4 100644 --- a/core/java/src/net/i2p/util/LogWriter.java +++ b/core/java/src/net/i2p/util/LogWriter.java @@ -11,6 +11,9 @@ package net.i2p.util; import java.util.Queue; +import net.i2p.app.ClientAppManager; +import net.i2p.app.NotificationService; + /** * Log writer thread that pulls log records from the LogManager and writes them to * the log. This also periodically instructs the LogManager to reread its config @@ -186,15 +189,43 @@ abstract class LogWriter implements Runnable { // we always add to the console buffer, but only sometimes write to stdout _manager.getBuffer().add(val); - if (rec.getPriority() >= Log.CRIT) + int priority = rec.getPriority(); + if (priority >= Log.CRIT) _manager.getBuffer().addCritical(val); - if (_manager.getDisplayOnScreenLevel() <= rec.getPriority()) { + // Default is CRIT + if (_manager.getDisplayOnScreenLevel() <= priority) { if (_manager.displayOnScreen()) { // wrapper and android logs already do time stamps, so reformat without the date if (_manager.getContext().hasWrapper() || SystemVersion.isAndroid()) System.out.print(LogRecordFormatter.formatRecord(_manager, rec, false)); else System.out.print(val); + + // + // Display a popup on DTG + // Experimental, may disable or add a separate config after testing + // These also aren't translated. + // May be appropriate for advanced users only. + // + String msg = rec.getMessage(); + if (priority >= Log.ERROR && msg != null && !SystemVersion.isAndroid()) { + ClientAppManager cmgr = _manager.getContext().clientAppManager(); + if (cmgr != null) { + NotificationService ns = (NotificationService) cmgr.getRegisteredApp("desktopgui"); + if (ns != null) { + String name; + Class cls = rec.getSource(); + if (cls != null) { + name = cls.getSimpleName(); + } else { + name = rec.getSourceName(); + if (name == null) + name = "I2P"; + } + ns.notify(name, null, priority, name, msg, null); + } + } + } } } } -- GitLab