mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-06-06 11:44:40 +00:00
perf: prevent background from being mounted when not in use
This commit is contained in:
@@ -1,7 +1,13 @@
|
||||
import backgroundPage from 'url:./background/background.html'
|
||||
import browser from 'webextension-polyfill';
|
||||
import { SettingsState } from '../../types/storage';
|
||||
|
||||
export async function appendBackgroundToUI() {
|
||||
console.log('Starting appendBackgroundToUI...');
|
||||
const settings = await browser.storage.local.get() as SettingsState;
|
||||
|
||||
console.log(settings.theme);
|
||||
|
||||
if (settings.theme == '') return;
|
||||
|
||||
const parent = document.getElementById('container');
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
<body>
|
||||
<!-- Container for the media -->
|
||||
<div id="media-container"></div>
|
||||
|
||||
<script src="background.ts"></script>
|
||||
|
||||
<script src="./background.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -19,7 +19,7 @@ const openDB = (): Promise<IDBDatabase> => {
|
||||
request.onsuccess = () => resolve(request.result);
|
||||
|
||||
request.onupgradeneeded = (event: IDBVersionChangeEvent) => {
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error - The event type is not recognized by TypeScript
|
||||
event?.target?.result.createObjectStore('backgrounds', { keyPath: 'id' });
|
||||
};
|
||||
});
|
||||
@@ -27,7 +27,9 @@ const openDB = (): Promise<IDBDatabase> => {
|
||||
|
||||
const readData = async (): Promise<Data | null> => {
|
||||
const selectedBackground = localStorage.getItem('selectedBackground');
|
||||
if (!selectedBackground) {
|
||||
|
||||
//const selectedBackground = localStorage.getItem('selectedBackground');
|
||||
if (!selectedBackground || selectedBackground === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -46,8 +48,6 @@ const updateBackground = async (): Promise<void> => {
|
||||
try {
|
||||
const data = await readData();
|
||||
if (!data) {
|
||||
console.log('No data found in IndexedDB.');
|
||||
|
||||
const container = document.getElementById('media-container');
|
||||
const currentMedia = container?.querySelector('.current-media');
|
||||
if (currentMedia) {
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
} from '../../SEQTA';
|
||||
import { updateBgDurations } from '../ui/Animation';
|
||||
import { getDarkMode, updateAllColors } from '../ui/colors/Manager';
|
||||
import { appendBackgroundToUI } from '../ui/ImageBackgrounds';
|
||||
|
||||
|
||||
export default class StorageListener {
|
||||
@@ -21,6 +22,7 @@ export default class StorageListener {
|
||||
}
|
||||
|
||||
handleStorageChanges(changes: any) {
|
||||
console.log('Storage changed:', changes);
|
||||
Object.keys(changes).forEach((changeKey) => {
|
||||
switch (changeKey) {
|
||||
|
||||
@@ -80,6 +82,15 @@ export default class StorageListener {
|
||||
document.documentElement.classList.remove('transparencyEffects');
|
||||
}
|
||||
break;
|
||||
|
||||
case 'theme':
|
||||
if (changes.theme.newValue === '' && changes.theme.oldValue !== '') {
|
||||
document.querySelector('iframe#background')?.remove();
|
||||
} else if (changes.theme.newValue !== '' && changes.theme.oldValue === '') {
|
||||
appendBackgroundToUI();
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
// Add default case if you need to handle a case where changeKey does not match any case
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user