Skip to content
Open
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
14 changes: 9 additions & 5 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ async function fetchAndStoreAlbums() {
});
if (!res.ok) throw new Error("Failed to fetch albums");
const albums = await res.json();
await browser.storage.sync.set({ immich_albums: albums });
await browser.storage.local.set({ immich_albums: albums });
return albums;
} catch (e) {
console.error("Error fetching albums:", e);
await browser.storage.sync.set({ immich_albums: [] });
await browser.storage.local.set({ immich_albums: [] });
return [];
}
}
Expand All @@ -26,7 +26,7 @@ async function createAlbumMenus() {
title: "Upload image/video to Immich",
contexts: ["image", "video"],
});
const { immich_albums } = await browser.storage.sync.get("immich_albums");
const { immich_albums } = await browser.storage.local.get("immich_albums");
if (immich_albums && Array.isArray(immich_albums)) {
for (const album of immich_albums) {
browser.contextMenus.create({
Expand All @@ -39,8 +39,12 @@ async function createAlbumMenus() {
}
}

// Initial load of albums and menus
fetchAndStoreAlbums().then(createAlbumMenus);

// Remove initial load. Instead, update albums and menus when context menu is about to show
browser.contextMenus.onShown.addListener(async () => {
await fetchAndStoreAlbums();
await createAlbumMenus();
});

// Listen for reload message from options
browser.runtime.onMessage.addListener((msg, sender, sendResponse) => {
Expand Down