Skip to content

Support bookmarks stored inside folders for chrome #163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions src/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ type Item = {
text?: string
isFavorite?: boolean // injected in UI array
isRunning?: boolean // only apps have this
bookmarkFolder? : null | string // only bookmarks have this
}

type OnboardingStep =
Expand Down
61 changes: 43 additions & 18 deletions src/stores/ui.store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ let minisearch = new MiniSearch({
'shortcut',
'isFavorite',
'isRunning',
'bookmarkFolder',
],
searchOptions: {
prefix: true,
Expand Down Expand Up @@ -261,9 +262,17 @@ export const createUIStore = (root: IRootStore) => {
launchAtLogin: true,
useBackgroundOverlay: true,
hasFullDiskAccess: false,
safariBookmarks: [] as {title: string; url: string}[],
braveBookmarks: [] as {title: string; url: string}[],
chromeBookmarks: [] as {title: string; url: string}[],
safariBookmarks: [] as {
title: string
url: string
bookmarkFolder: string | null
}[],
braveBookmarks: [] as {title: string; url: string; bookmarkFolder: string | null}[],
chromeBookmarks: [] as {
title: string
url: string
bookmarkFolder: string | null
}[],
mediaKeyForwardingEnabled: true,
targetHeight: 64,
isDarkMode: Appearance.getColorScheme() === 'dark',
Expand Down Expand Up @@ -328,6 +337,7 @@ export const createUIStore = (root: IRootStore) => {
id: `${bookmark.title}_safari_${idx}`,
name: bookmark.title,
type: ItemType.BOOKMARK,
bookmarkFolder: null,
iconImage: Assets.Safari,
callback: () => {
Linking.openURL(bookmark.url)
Expand All @@ -338,6 +348,7 @@ export const createUIStore = (root: IRootStore) => {
return {
id: `${bookmark.title}_brave_${idx}`,
name: bookmark.title,
bookmarkFolder: bookmark.bookmarkFolder,
type: ItemType.BOOKMARK,
iconImage: Assets.Brave,
callback: () => {
Expand All @@ -350,6 +361,7 @@ export const createUIStore = (root: IRootStore) => {
id: `${bookmark.title}_chrome_${idx}`,
name: bookmark.title,
type: ItemType.BOOKMARK,
bookmarkFolder: bookmark.bookmarkFolder,
iconImage: Assets.Chrome,
callback: async () => {
if (!bookmark.url) {
Expand Down Expand Up @@ -741,13 +753,21 @@ export const createUIStore = (root: IRootStore) => {
return
}
const OGbookmarks = JSON.parse(bookmarksString)
let bookmarks = OGbookmarks.roots.bookmark_bar.children.map(
(v: any) => ({
title: v.name,
url: v.url,
}),
)

let bookmarks: {
title: string
url: string
bookmarkFolder: null | string
}[] = []
const traverse = (nodes: any[], bookmarkFolder: null | string) => {
nodes.forEach(node => {
if (node.type === 'folder') {
traverse(node.children, node.name)
} else if (node.type === 'url') {
bookmarks.push({title: node.name, url: node.url, bookmarkFolder})
}
})
}
traverse(OGbookmarks.roots.bookmark_bar.children, null)
store.braveBookmarks = bookmarks
}
},
Expand All @@ -761,13 +781,18 @@ export const createUIStore = (root: IRootStore) => {
return
}
const OGbookmarks = JSON.parse(bookmarksString)
let bookmarks = OGbookmarks.roots.bookmark_bar.children.map(
(v: any) => ({
title: v.name,
url: v.url,
}),
)

let bookmarks: {title: string; url: string; bookmarkFolder: null | string}[] =
[]
const traverse = (nodes: any[], bookmarkFolder: null | string) => {
nodes.forEach(node => {
if (node.type === 'folder') {
traverse(node.children, node.name)
} else if (node.type === 'url') {
bookmarks.push({title: node.name, url: node.url, bookmarkFolder})
}
})
}
traverse(OGbookmarks.roots.bookmark_bar.children, null)
store.chromeBookmarks = bookmarks
}
},
Expand Down Expand Up @@ -825,7 +850,7 @@ export const createUIStore = (root: IRootStore) => {
setCustomSearchUrl: (url: string) => {
store.customSearchUrl = url
},

onHotkey({id}: {id: string}) {
let item = store.items.find(i => i.id === id)
if (item == null) {
Expand Down
6 changes: 6 additions & 0 deletions src/widgets/search.widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ export const SearchWidget: FC<Props> = observer(() => {
{renderToKeys(store.ui.shortcuts[item.id])}
</View>
)}
{item.type === ItemType.BOOKMARK && !!item.bookmarkFolder && (
<Text className="flex-row gap-1 items-center">{`${item.bookmarkFolder.substring(
0,
16,
)}${item.bookmarkFolder.length > 16 ? '...' : ''}`}</Text>
)}
</View>
</TouchableOpacity>
)
Expand Down