From 952161ec4acbb46be8b62679174e11994c385c59 Mon Sep 17 00:00:00 2001 From: Gordon Martin Date: Mon, 16 Nov 2026 19:42:29 +0000 Subject: [PATCH 1/3] There's currently a bug with notifications in the poncho-wonky client when using ssb-chess-mithril that follows this pattern: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit *Poncho Wonky has an internal list of ‘views’ that it has a cache of rendered DOM for. If a view hasn’t been visited in 5 minutes, it’s removed from the cache and the next time the route is visited again it’s re-rendered and attached to the DOM. * ssb-chess-mithril, at startup, initiates a pull stream where the ‘source’ is events that the user might want a notification about and the ‘sink’ is displaying a notification. There’s nothing that aborts this stream when the chess view is removed from the cache (even though the chess component’s ‘destroy’ function is called to unmount the chess view and clear up some of its internal state.) * So if you switch between the chess view and other poncho views you’ll get multiple notification streams (a new one each time the view is remounted freshly after it’s been removed from the cache.) * This means multiple notifications will be displayed This PR solves this problem by: * Exposing notifications as a separate stream from ssb-chess-mithril * Creating a depject 'gives' exposing this stream alongside the chess component 'render' dependency and loading it at Patchwork startup so that notifications are displayed even if the chess component isn't mounted. This only happens once so multiple notifications will no longer be displayed. Other changes: * I cleaned up the initialisation code for the chess page rendering so that we don't have to loop (with a back-off) until mutant has put the chess component on the DOM --- lib/app/notifications.js | 9 ++ lib/depject/page/html/render/chess.js | 120 +++++++++++++++++--------- lib/main-window.js | 7 +- lib/plugins/notifier.js | 1 - multiple-identities-entrypoint.js | 14 +-- package.json | 2 +- 6 files changed, 104 insertions(+), 49 deletions(-) create mode 100644 lib/app/notifications.js diff --git a/lib/app/notifications.js b/lib/app/notifications.js new file mode 100644 index 00000000..115f6f29 --- /dev/null +++ b/lib/app/notifications.js @@ -0,0 +1,9 @@ +const pull = require("pull-stream"); + +module.exports = function (notificationStreams) { + notificationStreams.forEach((stream) => { + pull(stream, pull.drain((n) => { + electron.ipcRenderer.send('send-notification', n) + })) + }); +} \ No newline at end of file diff --git a/lib/depject/page/html/render/chess.js b/lib/depject/page/html/render/chess.js index 68720cdd..b077a4f6 100644 --- a/lib/depject/page/html/render/chess.js +++ b/lib/depject/page/html/render/chess.js @@ -3,57 +3,97 @@ const nest = require("depnest"); const SsbChessDataAccess = require("ssb-chess-data-access"); const SsbChessMithril = require("ssb-chess-mithril"); const { onceTrue, computed } = require("mutant"); +const defer = require('pull-defer'); +const pull = require('pull-stream'); exports.needs = nest({ "sbot.obs.connection": "first", "intl.sync.i18n": "first", }); -exports.gives = nest("page.html.render"); +exports.gives = nest({ + "page.html": ["render", "notifications"], +}); + +function createChess(ssb) { + const dataAccess = new SsbChessDataAccess.SbotClassic(ssb); + return SsbChessMithril(dataAccess); +} + +function waitForSbot(api) { + return new Promise((resolve, reject) => { + onceTrue(api.sbot.obs.connection, (ssb) => { + resolve(ssb) + }) + }) +} exports.create = function (api) { - return nest("page.html.render", function channel(path) { - if (path !== "/chess") return; - - let chessComponent = null; - let removed = false; - - const page = - h("div.wrapper", { className: 'Scroller' }, [ - h( - "section.content", - h("div", { id: "ssb-chess-mithril-plugin", style: { 'margin-top':'20px' } }), - ), - ]); - - onceTrue(api.sbot.obs.connection, (ssb) => { - const loadChess = () => { - const attachToElement = document.getElementById( - "ssb-chess-mithril-plugin", - ); - - if (!attachToElement && !removed) { - console.log("no element, loop"); - setTimeout(() => { - loadChess(); - }, 500); - return; - } else if (!removed) { - const dataAccess = new SsbChessDataAccess.SbotClassic(ssb); - chessComponent = SsbChessMithril(attachToElement, dataAccess); - } - }; + return nest({ + "page.html": { + notifications: function() { + const deferred = defer.source() + + const chessPromise = waitForSbot(api) + .then(createChess); + + chessPromise.then(chess => { + const notificationStream = pull( + chess.notifications.getNotificationStream(), + pull.map(notification => ({ + icon: null, + title: "Chess", + message: notification.message, + open: `/chess`, + anchor: { + gameId: notification.gameId + } + })) + ) + + deferred.resolve(notificationStream); + }) - loadChess() - }) - + return deferred; + }, + render: function channel(path) { + if (!path.startsWith("/chess")) return; - return computed(page, p => p, {onUnlisten: () => { - removed = true; + const page = h("div.wrapper", { className: "Scroller" }, [ + h( + "section.content", + h("div", { + id: "ssb-chess-mithril-plugin", + style: { "margin-top": "20px" }, + }), + ), + ]); - if (chessComponent) { - chessComponent.destroy(); + const chessMountTarget = document.createElement('div') + + const chessComponent = waitForSbot(api) + .then(createChess) + .then(chess =>chess.mount(chessMountTarget)); + + const view = computed(page, (p) => { + const chessElem = p.querySelector('#ssb-chess-mithril-plugin'); + chessElem.appendChild(chessMountTarget) + return p + }, { + onUnlisten: () => { + chessComponent.then(x => x.destroy()); + }, + }); + + view.setAnchor = function(data) { + if (data && data.gameId) { + const gameId = data.gameId; + chessComponent.then(c => c.goToGame(gameId)) + } } - }}); + + return view; + }, + }, }); }; diff --git a/lib/main-window.js b/lib/main-window.js index 12ad9264..1f941546 100644 --- a/lib/main-window.js +++ b/lib/main-window.js @@ -16,6 +16,7 @@ const pull = require("pull-stream"); const moment = require("moment-timezone"); const fullscreen = require("./fullscreen.js"); const appViews = require("./app/views.js"); +const startViewNotifications = require("./app/notifications.js"); const getGitHandler = require("./app/sync/external-handler/git"); const path = require("path"); const fs = require("fs"); @@ -53,6 +54,7 @@ module.exports = function (config) { "sbot.async.get": "first", "blob.sync.url": "first", "page.html.render": "first", + "page.html.notifications": "map", "app.html.search": "first", "app.html.channels": "first", "app.html.progressNotifier": "first", @@ -178,6 +180,7 @@ module.exports = function (config) { ); const views = appViews(api.page.html.render, defaultViews); + startViewNotifications(api.page.html.notifications()); const pendingCount = views.get("/mentions").pendingUpdates; @@ -191,8 +194,8 @@ module.exports = function (config) { electron.ipcRenderer.on("goToSettings", () => api.app.navigate("/settings")); electron.ipcRenderer.on("goTostatus", () => api.app.navigate("/status")); - electron.ipcRenderer.on("navigate-to", (ev, target) => { - navigate(target); + electron.ipcRenderer.on("navigate-to", (ev, target, anchor) => { + navigate(target, anchor); }); // context menus are handled on the server. however, we need to know some diff --git a/lib/plugins/notifier.js b/lib/plugins/notifier.js index c945e1c8..a4a72d2b 100644 --- a/lib/plugins/notifier.js +++ b/lib/plugins/notifier.js @@ -11,7 +11,6 @@ const path = require("path"); const toPull = require("stream-to-pull-stream"); const getAvatar = require("ssb-avatar"); const electron = require("electron"); -const ref = require("ssb-ref"); const ssbUri = require("ssb-uri2"); const defaultIcon = "&qjeAs8+uMXLlyovT4JnEpMwTNDx/QXHfOl2nv2u0VCM=.sha256"; diff --git a/multiple-identities-entrypoint.js b/multiple-identities-entrypoint.js index 0f61550a..02e612b5 100644 --- a/multiple-identities-entrypoint.js +++ b/multiple-identities-entrypoint.js @@ -261,7 +261,7 @@ electron.app.on("ready", () => { }; // Notification event - electron.ipcMain.on("send-notification", (ev, notif) => { + electron.ipcMain.on("send-notification", (sendNotificationEv, notif) => { const notificationsEnabled = preferences.get("notificationsEnabled", true); if (notificationsEnabled) { @@ -281,11 +281,13 @@ electron.app.on("ready", () => { }); notification.addListener("click", (ev) => { - console.log("notification clicked."); - console.log("ev", ev); - const id = windows.keys().next().value; + + const windowId = sendNotificationEv.sender.keyForWindowsMap || windows.keys().next().value; + const browserWindow = windows.get(windowId)?.renderer; + const url = notif.open; - const browserWindow = windows.get(id)?.renderer; + const anchor = notif.anchor; + console.log("browser window for open url", browserWindow); if (ssbUri.isClassicMessageSSBURI(url)) { const msgid = ssbUri.toMessageSigil(url); @@ -293,6 +295,8 @@ electron.app.on("ready", () => { } else if (ssbUri.isFeedSSBURI(url)) { const feedid = ssbUri.toFeedSigil(url); browserWindow.webContents.send("navigate-to", feedid); + } else { + browserWindow.webContents.send("navigate-to", url, anchor); } }); diff --git a/package.json b/package.json index f182cd17..ff333ece 100644 --- a/package.json +++ b/package.json @@ -90,7 +90,7 @@ "ssb-blobs": "^2.0.1", "ssb-book-schema": "^1.0.3", "ssb-chess-data-access": "^2.1.4", - "ssb-chess-mithril": "2.1.4", + "ssb-chess-mithril": "3.0.0", "ssb-client": "^4.9.0", "ssb-config": "^3.4.4", "ssb-conn": "~1.0.0", From 45d2d380dadbdfc97fc823314bc6f27dd4af6039 Mon Sep 17 00:00:00 2001 From: Gordon Martin Date: Tue, 17 Nov 2026 19:47:24 +0000 Subject: [PATCH 2/3] Bump to version of ssb-chess-mithril with notification stream hang fix --- package-lock.json | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index 05e26172..93444231 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "ssb-ponchowonky", - "version": "5.6.5", + "version": "5.7.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "ssb-ponchowonky", - "version": "5.6.5", + "version": "5.7.0", "license": "AGPL-3.0", "dependencies": { "@electron/remote": "^2.1.3", @@ -79,7 +79,7 @@ "ssb-blobs": "^2.0.1", "ssb-book-schema": "^1.0.3", "ssb-chess-data-access": "^2.1.4", - "ssb-chess-mithril": "2.1.4", + "ssb-chess-mithril": "3.0.1", "ssb-client": "^4.9.0", "ssb-config": "^3.4.4", "ssb-conn": "~1.0.0", @@ -12238,9 +12238,9 @@ } }, "node_modules/ssb-chess-mithril": { - "version": "2.1.4", - "resolved": "https://registry.npmjs.org/ssb-chess-mithril/-/ssb-chess-mithril-2.1.4.tgz", - "integrity": "sha512-lUY4eiinkzcypDUt/kFIHBAHM/oGupYxgyhuAQp/d8v5Jd6wNEsRbht2Gl/dnwdW2iMiJ/RIB2VntpTzmhnNtw==", + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/ssb-chess-mithril/-/ssb-chess-mithril-3.0.1.tgz", + "integrity": "sha512-AvZUoV3sfOpPLItYKserryzYUpyZ8ZmEQ+4LDWtenuLXPiN4cU+rLfr7VN9j3X/bdn6WTTaLCepE+xIR0Cl7SQ==", "license": "GPL-3.0", "dependencies": { "@lichess-org/chessground": "^10.4.2", diff --git a/package.json b/package.json index ff333ece..a50b2818 100644 --- a/package.json +++ b/package.json @@ -90,7 +90,7 @@ "ssb-blobs": "^2.0.1", "ssb-book-schema": "^1.0.3", "ssb-chess-data-access": "^2.1.4", - "ssb-chess-mithril": "3.0.0", + "ssb-chess-mithril": "3.0.1", "ssb-client": "^4.9.0", "ssb-config": "^3.4.4", "ssb-conn": "~1.0.0", From 2d716bc8ea5f7ab0afd6d9af5301423fb6960e8c Mon Sep 17 00:00:00 2001 From: Gordon Martin Date: Tue, 17 Nov 2026 21:09:11 +0000 Subject: [PATCH 3/3] Small refactor of chess notification logic --- lib/depject/page/html/render/chess.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/depject/page/html/render/chess.js b/lib/depject/page/html/render/chess.js index b077a4f6..66496003 100644 --- a/lib/depject/page/html/render/chess.js +++ b/lib/depject/page/html/render/chess.js @@ -34,11 +34,9 @@ exports.create = function (api) { notifications: function() { const deferred = defer.source() - const chessPromise = waitForSbot(api) - .then(createChess); - - chessPromise.then(chess => { - const notificationStream = pull( + waitForSbot(api) + .then(createChess) + .then(chess => pull( chess.notifications.getNotificationStream(), pull.map(notification => ({ icon: null, @@ -50,9 +48,7 @@ exports.create = function (api) { } })) ) - - deferred.resolve(notificationStream); - }) + ).then(notificationStream => deferred.resolve(notificationStream)) return deferred; },