Skip to content

Commit

Permalink
Initialize correctly without the "bookmarks" optional permission #3440
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Jan 30, 2024
1 parent 05dbdae commit 99ff6b1
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions webextensions/background/migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,23 +402,17 @@ async function migrateBookmarkUrl(bookmark) {
}

let mObservingBookmarks = false;
let mBookmarksListenersRegistered = false;

async function startBookmarksUrlAutoMigration() {
if (mObservingBookmarks)
return;

mObservingBookmarks = true;
}

browser.bookmarks.onCreated.addListener((id, bookmark) => {
function onBookmarkCreated(id, bookmark) {
if (!mObservingBookmarks)
return;

if (bookmark.url)
migrateBookmarkUrl(bookmark);
});
}

browser.bookmarks.onChanged.addListener(async (id, changeInfo) => {
async function onBookmarkChanged(id, changeInfo) {
if (!mObservingBookmarks)
return;

Expand All @@ -430,7 +424,31 @@ browser.bookmarks.onChanged.addListener(async (id, changeInfo) => {
else
migrateBookmarkUrl(bookmark);
}
});
}

if (browser.bookmarks &&
browser.bookmarks.onCreated) {
browser.bookmarks.onCreated.addListener(onBookmarkCreated);
browser.bookmarks.onChanged.addListener(onBookmarkChanged);
mBookmarksListenersRegistered = true;
}

async function startBookmarksUrlAutoMigration() {
if (mObservingBookmarks)
return;

mObservingBookmarks = true;

if (mBookmarksListenersRegistered ||
!browser.bookmarks ||
!browser.bookmarks.onCreated)
return;

browser.bookmarks.onCreated.addListener(onBookmarkCreated);
browser.bookmarks.onChanged.addListener(onBookmarkChanged);
mBookmarksListenersRegistered = true;
}


configs.$loaded.then(() => {
configs.$addObserver(async key => {
Expand Down

0 comments on commit 99ff6b1

Please sign in to comment.