Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/app/notifications.js
Original file line number Diff line number Diff line change
@@ -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)
}))
});
}
116 changes: 76 additions & 40 deletions lib/depject/page/html/render/chess.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,57 +3,93 @@ 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()

waitForSbot(api)
.then(createChess)
.then(chess => pull(
chess.notifications.getNotificationStream(),
pull.map(notification => ({
icon: null,
title: "Chess",
message: notification.message,
open: `/chess`,
anchor: {
gameId: notification.gameId
}
}))
)
).then(notificationStream => 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;
},
},
});
};
7 changes: 5 additions & 2 deletions lib/main-window.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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;

Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion lib/plugins/notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
14 changes: 9 additions & 5 deletions multiple-identities-entrypoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -281,18 +281,22 @@ 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);
browserWindow.webContents.send("navigate-to", msgid);
} else if (ssbUri.isFeedSSBURI(url)) {
const feedid = ssbUri.toFeedSigil(url);
browserWindow.webContents.send("navigate-to", feedid);
} else {
browserWindow.webContents.send("navigate-to", url, anchor);
}
});

Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.1",
"ssb-client": "^4.9.0",
"ssb-config": "^3.4.4",
"ssb-conn": "~1.0.0",
Expand Down
Loading