mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-06-06 03:34:40 +00:00
add automatic theme installing
This commit is contained in:
@@ -36,11 +36,7 @@ export const ThemeCover: React.FC<ThemeCoverProps> = ({
|
|||||||
|
|
||||||
const handleDeleteClick = (e: React.MouseEvent) => {
|
const handleDeleteClick = (e: React.MouseEvent) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
if (downloaded) {
|
onThemeDelete(theme.id);
|
||||||
DeleteDownloadedTheme(theme.id);
|
|
||||||
} else {
|
|
||||||
onThemeDelete(theme.id);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleShareClick = (event: React.MouseEvent) => {
|
const handleShareClick = (event: React.MouseEvent) => {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, { useEffect, useState, useCallback, forwardRef, useImperativeHandle, ForwardRefExoticComponent, RefAttributes } from 'react';
|
import React, { useEffect, useState, useCallback, forwardRef, useImperativeHandle, ForwardRefExoticComponent, RefAttributes } from 'react';
|
||||||
import { listThemes, deleteTheme, setTheme, disableTheme, getDownloadedThemes } from '../hooks/ThemeManagment';
|
import { listThemes, deleteTheme, setTheme, disableTheme, getDownloadedThemes, sendThemeUpdate } from '../hooks/ThemeManagment';
|
||||||
import { DeleteDownloadedTheme } from '../pages/Store';
|
import { DeleteDownloadedTheme } from '../pages/Store';
|
||||||
import { ThemeCover } from './ThemeCover';
|
import { ThemeCover } from './ThemeCover';
|
||||||
import browser from 'webextension-polyfill';
|
import browser from 'webextension-polyfill';
|
||||||
@@ -85,8 +85,16 @@ const ThemeSelector: ForwardRefExoticComponent<Omit<ThemeSelectorProps, "ref"> &
|
|||||||
const tempDownloadedThemes = await getDownloadedThemes();
|
const tempDownloadedThemes = await getDownloadedThemes();
|
||||||
|
|
||||||
setThemes(themes);
|
setThemes(themes);
|
||||||
setDownloadedThemes(tempDownloadedThemes);
|
//setDownloadedThemes(tempDownloadedThemes);
|
||||||
setSelectedTheme(selectedTheme ? selectedTheme : '');
|
setSelectedTheme(selectedTheme ? selectedTheme : '');
|
||||||
|
|
||||||
|
console.log(tempDownloadedThemes)
|
||||||
|
|
||||||
|
tempDownloadedThemes.forEach(async (theme) => {
|
||||||
|
console.log('Updating theme:', theme)
|
||||||
|
await sendThemeUpdate(theme as DownloadedTheme, true, false)
|
||||||
|
DeleteDownloadedTheme(theme.id);
|
||||||
|
});
|
||||||
|
|
||||||
const matchingThemes = themes.filter(theme =>
|
const matchingThemes = themes.filter(theme =>
|
||||||
tempDownloadedThemes.some(downloadedTheme => downloadedTheme.id === theme.id)
|
tempDownloadedThemes.some(downloadedTheme => downloadedTheme.id === theme.id)
|
||||||
@@ -133,11 +141,20 @@ const ThemeSelector: ForwardRefExoticComponent<Omit<ThemeSelectorProps, "ref"> &
|
|||||||
|
|
||||||
const handleThemeDelete = useCallback(
|
const handleThemeDelete = useCallback(
|
||||||
async (themeId: string) => {
|
async (themeId: string) => {
|
||||||
|
console.log(themeId, downloadedThemes)
|
||||||
try {
|
try {
|
||||||
await deleteTheme(themeId);
|
if (downloadedThemes.some((theme) => theme.id === themeId)) {
|
||||||
setThemes((prevThemes) => prevThemes.filter((theme) => theme.id !== themeId));
|
console.log('Deleting downloaded theme:', themeId)
|
||||||
|
DeleteDownloadedTheme(themeId);
|
||||||
|
setDownloadedThemes((prevThemes) => prevThemes.filter((theme) => theme.id !== themeId));
|
||||||
|
} else {
|
||||||
|
console.log('False')
|
||||||
|
await deleteTheme(themeId);
|
||||||
|
setThemes((prevThemes) => prevThemes.filter((theme) => theme.id !== themeId));
|
||||||
|
}
|
||||||
if (themeId === settingsState.selectedTheme) {
|
if (themeId === settingsState.selectedTheme) {
|
||||||
setSelectedTheme('');
|
setSelectedTheme('')
|
||||||
|
disableTheme();
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error deleting theme:', error);
|
console.error('Error deleting theme:', error);
|
||||||
|
|||||||
@@ -84,8 +84,9 @@ export const deleteTheme = async (themeID: string) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export const sendThemeUpdate = async (updatedTheme: CustomTheme | DownloadedTheme, saveTheme?: boolean, updateImages?: boolean) => {
|
export const sendThemeUpdate = async (updatedTheme: CustomTheme | DownloadedTheme, saveTheme?: boolean, updateImages?: boolean, enableTheme?: boolean) => {
|
||||||
saveTheme = saveTheme || false;
|
saveTheme = saveTheme || false;
|
||||||
|
enableTheme = enableTheme || false;
|
||||||
|
|
||||||
const imageDataPromises = updatedTheme.CustomImages.map(async (image) => {
|
const imageDataPromises = updatedTheme.CustomImages.map(async (image) => {
|
||||||
if (saveTheme || updateImages) {
|
if (saveTheme || updateImages) {
|
||||||
@@ -120,6 +121,7 @@ export const sendThemeUpdate = async (updatedTheme: CustomTheme | DownloadedThem
|
|||||||
info: 'UpdateThemePreview',
|
info: 'UpdateThemePreview',
|
||||||
body: themeData,
|
body: themeData,
|
||||||
save: saveTheme,
|
save: saveTheme,
|
||||||
|
enableTheme: enableTheme
|
||||||
});
|
});
|
||||||
|
|
||||||
if (saveTheme) {
|
if (saveTheme) {
|
||||||
|
|||||||
@@ -30,7 +30,9 @@ export class MessageHandler {
|
|||||||
if (request?.save == true) {
|
if (request?.save == true) {
|
||||||
const save = async () => {
|
const save = async () => {
|
||||||
await saveTheme(request.body)
|
await saveTheme(request.body)
|
||||||
await setTheme(request.body.id)
|
if (request.body.enableTheme) {
|
||||||
|
await setTheme(request.body.id)
|
||||||
|
}
|
||||||
sendResponse({ status: 'success' })
|
sendResponse({ status: 'success' })
|
||||||
sendThemeUpdate()
|
sendThemeUpdate()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user