Skip to content

Commit e7a011e

Browse files
committed
new features
- Tray is back - Smooth scroll in thread view - New root message cache
1 parent 1ddfb8c commit e7a011e

File tree

19 files changed

+315
-75
lines changed

19 files changed

+315
-75
lines changed

app.js

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
const { Menu, app, dialog, shell, protocol, BrowserWindow, ipcMain } = require("electron")
1+
const {
2+
Menu,
3+
app,
4+
dialog,
5+
shell,
6+
protocol,
7+
BrowserWindow,
8+
Tray,
9+
ipcMain } = require("electron")
210
const path = require("path")
311
const defaultMenu = require("electron-default-menu")
412
const windowStateKeeper = require("electron-window-state")
@@ -7,6 +15,7 @@ const queryString = require("query-string")
715

816
let windows = new Set()
917
let sbot = null
18+
let tray = null
1019

1120
const createWindow = (data = false, windowState = false) => {
1221
let win
@@ -18,6 +27,7 @@ const createWindow = (data = false, windowState = false) => {
1827
win = new BrowserWindow({
1928
width: 800,
2029
height: 800,
30+
show: false,
2131
webPreferences: {
2232
nodeIntegration: true,
2333
contextIsolation: false,
@@ -27,6 +37,7 @@ const createWindow = (data = false, windowState = false) => {
2737
win = new BrowserWindow({
2838
x: windowState.x,
2939
y: windowState.y,
40+
show: false,
3041
width: windowState.width,
3142
height: windowState.height,
3243
webPreferences: {
@@ -49,6 +60,10 @@ const createWindow = (data = false, windowState = false) => {
4960
win.webContents.send("window:focus")
5061
})
5162

63+
win.once("ready-to-show", () => {
64+
win.show()
65+
})
66+
5267
win.webContents.on("will-navigate", (event, url) => {
5368
console.log("event", event)
5469
console.log("url", url)
@@ -152,6 +167,9 @@ ipcMain.on("menu:set", (event, group) => {
152167
createWindow()
153168
},
154169
},
170+
{
171+
role: "shareMenu"
172+
}
155173
],
156174
}
157175

@@ -180,11 +198,95 @@ ipcMain.on("menu:set", (event, group) => {
180198
Menu.setApplicationMenu(finalMenu)
181199
})
182200

201+
ipcMain.on("tray:set", (event, group) => {
202+
// console.log("received menu", JSON.stringify(group, null, 2))
203+
let menu = []
204+
let keys = Object.keys(group)
205+
206+
// console.log(JSON.stringify(menu,null,2))
207+
208+
const makeSubmenu = subgroup => {
209+
let toPush = []
210+
subgroup.forEach(m => {
211+
m.items.forEach(i => {
212+
let m = {
213+
label: i.label,
214+
click: (item, win) => {
215+
win.webContents.send("menu:trigger", {
216+
event: i.event,
217+
data: i.data,
218+
})
219+
},
220+
}
221+
222+
if (i?.shortcut) {
223+
m.accelerator = i.shortcut
224+
}
225+
226+
toPush.push(m)
227+
})
228+
toPush.push({ type: "separator" })
229+
})
230+
toPush.pop()
231+
return toPush
232+
}
233+
234+
keys.forEach(k => {
235+
let m = {
236+
label: k,
237+
submenu: makeSubmenu(group[k]),
238+
}
239+
240+
if (k.toLowerCase() == "help") {
241+
m.role = "help"
242+
}
243+
244+
menu.push(m)
245+
})
246+
247+
// FIXME: menu has wrong order for toplevel items.
248+
let topItems = [
249+
{
250+
label: "New Window",
251+
accelerator: "CmdOrCtrl+Shift+N",
252+
click: () => {
253+
createWindow()
254+
},
255+
}
256+
]
257+
258+
let bottomItems = [
259+
{
260+
type: "separator"
261+
},
262+
{
263+
label: "Quit",
264+
click() { app.quit() }
265+
}
266+
]
267+
268+
let finalMenu = Menu.buildFromTemplate([...topItems, ...menu, ...bottomItems])
269+
270+
tray.setContextMenu(finalMenu)
271+
})
272+
183273
// This method will be called when Electron has finished
184274
// initialization and is ready to create browser windows.
185275
// Some APIs can only be used after this event occurs.
186276
app.on("ready", () => {
187277
console.log("Attempting to start server...")
278+
279+
tray = new Tray(`${__dirname}/ui/assets/images/patchfox_pixel_16.png`)
280+
tray.setToolTip("Patchfox")
281+
282+
const initialMenu = Menu.buildFromTemplate([
283+
{
284+
label: "Quit",
285+
click() { app.quit() }
286+
}
287+
])
288+
tray.setContextMenu(initialMenu)
289+
188290
startDefaultPatchfoxServer((err, ssb) => {
189291
console.log("Server started!", ssb.id)
190292
sbot = ssb

package-lock.json

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
"localbuild": "run-s build builder:*"
112112
},
113113
"dependencies": {
114+
"hashlru": "^2.3.0",
114115
"ssb-about": "^2.0.1",
115116
"ssb-blobs": "^2.0.1",
116117
"ssb-conn": "^6.0.3",

ui/assets/css/tailwind.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4078,6 +4078,10 @@ html {
40784078
flex: 1 1 0%;
40794079
}
40804080

4081+
.flex-auto {
4082+
flex: 1 1 auto;
4083+
}
4084+
40814085
.flex-initial {
40824086
flex: 0 1 auto;
40834087
}

ui/assets/images/bg.jpg

-94.6 KB
Binary file not shown.

ui/assets/images/logo.svg

Lines changed: 0 additions & 39 deletions
This file was deleted.
2.59 KB
Loading

ui/core/components/Card.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ const Card = {
4242
}
4343

4444

45-
return m("div", {"class": cardCss()}, [
45+
return m("div", {
46+
"class": cardCss(),
47+
"data-key": msg.key
48+
}, [
4649
m(".card-title",
4750
[
4851
m(".navbar",

ui/core/components/MessageDropdown.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,12 @@ const MessageDropdown = {
4343
view: "thread",
4444
thread: msg.key
4545
})
46-
46+
}
47+
48+
const shareItem = () => {
49+
vnode.state.dropdownActive = false
50+
console.log(msg)
51+
ipcRenderer.send("share", ssbUri.fromMessageSigil(msg.key))
4752
}
4853

4954
const menuRight = {
@@ -82,6 +87,11 @@ const MessageDropdown = {
8287
icon: "copy",
8388
onclick: copyHash,
8489
}),
90+
m(MenuItem, {
91+
label: "Share SSB URI",
92+
icon: "share",
93+
onclick: shareItem,
94+
}),
8595
m(".divider", "FOR THE CURIOUS"),
8696
m(MenuItem, {
8797
label: "Raw Message",

ui/core/components/MessageRenderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const MessageRenderer = {
4242
if (typeof msg.value.content === "string") {
4343
type = "private"
4444
} else {
45-
type = msg.value.content.type
45+
type = msg.value.content.type ?? "unknown"
4646
}
4747

4848
for (let p of messageTypes) {

ui/core/kernel/kernel.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ function _package(pkg) {
1313
let name = pkg.name
1414
let ssb = global.ssb
1515
if (pkg.supportedPlatforms.includes("all")) {
16-
console.log(`Loading package ${pkg.name} because it supports *all* platforms.`)
16+
// console.log(`Loading package ${pkg.name} because it supports *all* platforms.`)
1717
_.set(packages, name, pkg)
1818
} else if (pkg.supportedPlatforms.includes(ssb?.platform)) {
19-
console.log(`Loading package ${pkg.name}`)
19+
// console.log(`Loading package ${pkg.name}`)
2020
_.set(packages, name, pkg)
2121
} else {
2222
console.error(`Not loading package ${pkg.name}`, ssb)

ui/core/kernel/menus.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ function menus() {
1010
return _.flatten(result)
1111
}
1212

13+
function trayItems() {
14+
let result = []
15+
let packagesWithGlobalMenuEntries = _.filter(patchfox.packages, (p) => p.tray)
16+
packagesWithGlobalMenuEntries.forEach((p) => {
17+
result.push(p.menu)
18+
})
19+
return _.flatten(result)
20+
}
21+
1322
function menuGroups() {
1423
let ms = menus()
1524
let groups = {}
@@ -23,6 +32,19 @@ function menuGroups() {
2332
return groups
2433
}
2534

35+
function trayGroups() {
36+
let ms = trayItems()
37+
let groups = {}
38+
ms.forEach((m) => {
39+
if (m.group && !groups[m.group]) {
40+
groups[m.group] = []
41+
}
42+
43+
groups[m.group].push(m)
44+
})
45+
return groups
46+
}
47+
2648
function triggerMenu(menuItem) {
2749
let { event, data } = menuItem
2850
console.log("menu event:", event)
@@ -32,5 +54,6 @@ function triggerMenu(menuItem) {
3254
module.exports = {
3355
menus,
3456
menuGroups,
57+
trayGroups,
3558
triggerMenu,
3659
}

ui/core/platforms/common/cache.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const HLRU = require("hashlru")
2+
const rootCache = HLRU(200)
13

24
const caches = {}
35
let avatarCache = {}
@@ -29,21 +31,15 @@ const resultFromCache = (kind, msgId, falseIfOlderThan) => {
2931

3032

3133
const getMsgCache = (id) => {
32-
let data = sessionStorage.getItem(id)
33-
if (data) {
34-
try {
35-
return JSON.parse(data)
36-
} catch (n) {
37-
sessionStorage.removeItem(id)
38-
return false
39-
}
34+
if (rootCache.has(id)) {
35+
return rootCache.get(id)
4036
} else {
4137
return false
4238
}
4339
}
4440

4541
const setMsgCache = (id, data) => {
46-
sessionStorage.setItem(id, JSON.stringify(data))
42+
rootCache.set(id, data)
4743
}
4844

4945
function setAvatarCache(feed, data) {

0 commit comments

Comments
 (0)