Skip to content

Commit

Permalink
修复FIREFOX下载书签(chrome协议格式)报错的问题。
Browse files Browse the repository at this point in the history
修复上传后显示远程书签数量不对的问题。
  • Loading branch information
dudor committed Jul 11, 2021
1 parent b0a3e77 commit 6dffb48
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/views/background/background.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { browser } from "webextension-polyfill-ts";
import { browser, Bookmarks } from "webextension-polyfill-ts";
import BookmarkService from '../../utils/services'
import { Setting } from '../../utils/setting'
import iconLogo from '../../icons/icon128.png'
Expand Down Expand Up @@ -89,6 +89,8 @@ async function uploadBookmarks() {
},
description: setting.gistFileName
}));
const count = getBookmarkCount(syncdata.bookmarks);
await browser.storage.local.set({ remoteCount: count });
if (setting.enableNotify) {
await browser.notifications.create({
type: "basic",
Expand Down Expand Up @@ -127,7 +129,7 @@ async function downloadBookmarks() {
}
await clearBookmarkTree();
await createBookmarkTree(syncdata.bookmarks);
let count = getBookmarkCount(syncdata.bookmarks);
const count = getBookmarkCount(syncdata.bookmarks);
await browser.storage.local.set({ remoteCount: count });
if (setting.enableNotify) {
await browser.notifications.create({
Expand Down Expand Up @@ -263,12 +265,18 @@ async function createBookmarkTree(bookmarkList: BookmarkInfo[] | undefined) {
continue;
}

let res = await browser.bookmarks.create({
parentId: node.parentId,
title: node.title,
url: node.url
});
if (res.url === undefined && node.children && node.children.length > 0) {
let res: Bookmarks.BookmarkTreeNode = { id: '', title: '' };
try {
/* 处理firefox中创建 chrome://chrome-urls/ 格式的书签会报错的问题 */
res = await browser.bookmarks.create({
parentId: node.parentId,
title: node.title,
url: node.url
});
} catch (err) {
console.error(res, err);
}
if (res.id && node.children && node.children.length > 0) {
node.children.forEach(c => c.parentId = res.id);
await createBookmarkTree(node.children);
}
Expand All @@ -292,7 +300,7 @@ function getBookmarkCount(bookmarkList: BookmarkInfo[] | undefined) {

async function refreshLocalCount() {
let bookmarkList = await getBookmarks();
let count = getBookmarkCount(bookmarkList);
const count = getBookmarkCount(bookmarkList);
await browser.storage.local.set({ localCount: count });
}

Expand Down

0 comments on commit 6dffb48

Please sign in to comment.