Skip to content
This repository was archived by the owner on Dec 27, 2022. It is now read-only.

Commit 01f3a64

Browse files
committed
Fix toolbar/bookmark updating to better preserve existing items on change
1 parent 38d1187 commit 01f3a64

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

app/bg/filesystem/bookmarks.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { joinPath, slugify } from '../../lib/strings.js'
22
import { query } from './query.js'
33
import * as filesystem from './index'
4-
import { includesList as toolbarIncludesList, add as addToToolbar, remove as removeFromToolbar } from './toolbar'
4+
import {
5+
includesList as toolbarIncludesList,
6+
add as addToToolbar,
7+
remove as removeFromToolbar,
8+
getCurrentBookmark as getToolbarCurrentBookmark
9+
} from './toolbar'
510
import { URL } from 'url'
611
import * as profileDb from '../dbs/profile-data-db'
712

@@ -62,12 +67,23 @@ export async function add ({href, title, pinned, toolbar}) {
6267
}
6368
slug = slug.toLowerCase()
6469

65-
await remove(href) // in case this is an edit
70+
let openInPane = undefined
71+
let existing = await get(href)
72+
if (existing) {
73+
if (existing.toolbar) {
74+
let existingToolbar = await getToolbarCurrentBookmark(href)
75+
openInPane = existingToolbar ? existingToolbar.openInPane : undefined
76+
}
77+
if (typeof title === 'undefined') title = existing.title
78+
if (typeof pinned === 'undefined') pinned = existing.pinned
79+
if (typeof toolbar === 'undefined') toolbar = existing.toolbar
80+
await remove(href)
81+
}
6682

6783
var filename = await filesystem.getAvailableName('/bookmarks', slug, 'goto') // avoid collisions
6884
var path = joinPath('/bookmarks', filename)
6985
await filesystem.get().pda.writeFile(path, '', {metadata: {href, title, pinned: pinned ? '1' : undefined}})
70-
if (toolbar) await addToToolbar({bookmark: filename})
86+
if (toolbar) await addToToolbar({bookmark: filename, openInPane})
7187
return path
7288
}
7389

app/bg/filesystem/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export async function setup () {
8989

9090
// default bookmarks
9191
if (isInitialCreation) {
92-
await bookmarks.add({href: 'beaker://explorer/', title: 'Files Explorer', pinned: true})
92+
await bookmarks.add({href: 'beaker://explorer/', title: 'Explore Files', pinned: true})
9393
await bookmarks.add({href: 'beaker://webterm/', title: 'Terminal', pinned: true})
9494
await bookmarks.add({href: 'https://userlist.beakerbrowser.com/', title: 'User Directory', pinned: true})
9595
await bookmarks.add({href: 'hyper://a8e9bd0f4df60ed5246a1b1f53d51a1feaeb1315266f769ac218436f12fda830/', title: 'Blahbity Blog', pinned: true})

app/bg/filesystem/toolbar.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ export async function getCurrent () {
3636
return items
3737
}
3838

39+
export async function getCurrentBookmark (href) {
40+
var current = await getCurrent()
41+
return current.find(item => item.href === href)
42+
}
43+
3944
export async function includesList (bookmarks) {
4045
var data = await read()
4146
return bookmarks.map(bookmark => {

0 commit comments

Comments
 (0)