feat(background): implement IndexedDB for custom background storage and enhance background management features

This commit is contained in:
alexsparkes
2026-01-24 18:55:27 +00:00
parent d84b09801c
commit 76c9aa4df9
9 changed files with 552 additions and 106 deletions

View File

@@ -35,6 +35,29 @@ function MainModal({ modalClose, deepLinkData }) {
setProductView(null);
}, [currentTab]);
// Handle deep link updates (when modal opens via EventBus with new deep link)
useEffect(() => {
if (deepLinkData) {
// Update tab if different
if (deepLinkData.tab && deepLinkData.tab !== currentTab) {
setCurrentTab(deepLinkData.tab);
}
// Handle settings section navigation with subsection
if (deepLinkData.tab === TAB_TYPES.SETTINGS && deepLinkData.section) {
setNavigationTrigger({
type: 'settings-section',
data: deepLinkData.section,
timestamp: Date.now(),
});
// Set sub-section if present
if (deepLinkData.subSection) {
setCurrentSubSection(deepLinkData.subSection);
}
}
}
}, [deepLinkData]);
// Clear hash when modal closes
useEffect(() => {
return () => {

View File

@@ -10,16 +10,17 @@ const FileUpload = memo(({ id, type, accept, loadFunction }) => {
if (!fileInput) return;
const handleChange = (e) => {
const reader = new FileReader();
const file = e.target.files[0];
const files = Array.from(e.target.files);
if (type === 'settings') {
const reader = new FileReader();
const file = files[0];
reader.readAsText(file, 'UTF-8');
reader.onload = (e) => {
return loadFunction(e.target.result);
};
} else {
// background upload
// background upload - handle multiple files
const settings = {};
Object.keys(localStorage).forEach((key) => {
@@ -27,26 +28,30 @@ const FileUpload = memo(({ id, type, accept, loadFunction }) => {
});
const settingsSize = new TextEncoder().encode(JSON.stringify(settings)).length;
if (videoCheck(file.type) === true) {
if (settingsSize + file.size > 4850000) {
return toast(variables.getMessage('toasts.no_storage'));
// Process each file
files.forEach((file, index) => {
if (videoCheck(file.type) === true) {
if (settingsSize + file.size > 4850000) {
return toast(variables.getMessage('toasts.no_storage'));
}
return loadFunction(file, index);
}
return loadFunction(file);
}
compressAccurately(file, {
size: 450,
accuracy: 0.9,
}).then(async (res) => {
if (settingsSize + res.size > 4850000) {
return toast(variables.getMessage('toasts.no_storage'));
}
compressAccurately(file, {
size: 450,
accuracy: 0.9,
}).then(async (res) => {
if (settingsSize + res.size > 4850000) {
return toast(variables.getMessage('toasts.no_storage'));
}
loadFunction({
target: {
result: await filetoDataURL(res),
},
loadFunction({
target: {
result: await filetoDataURL(res),
},
}, index);
});
});
}
@@ -67,6 +72,7 @@ const FileUpload = memo(({ id, type, accept, loadFunction }) => {
type="file"
style={{ display: 'none' }}
accept={accept}
multiple={type !== 'settings'}
/>
);
});