mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-06-06 03:34:40 +00:00
fix: updated theme style store install
This commit is contained in:
@@ -1,8 +1,6 @@
|
|||||||
import browser from 'webextension-polyfill'
|
import browser from 'webextension-polyfill'
|
||||||
import { onError } from './seqta/utils/onError';
|
import { onError } from './seqta/utils/onError';
|
||||||
import { SettingsState } from "./types/storage";
|
import { SettingsState } from "./types/storage";
|
||||||
import DownloadTheme from "./seqta/ui/themes/downloadTheme";
|
|
||||||
|
|
||||||
|
|
||||||
export const openDB = () => {
|
export const openDB = () => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@@ -121,10 +119,6 @@ browser.runtime.onMessage.addListener((request: any, _sender: any, sendResponse:
|
|||||||
GetNews(sendResponse, url);
|
GetNews(sendResponse, url);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case 'DownloadTheme':
|
|
||||||
DownloadTheme(request.body.theme);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
console.log('Unknown request type');
|
console.log('Unknown request type');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ export const ThemeCover: React.FC<ThemeCoverProps> = ({
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{ ( !isEditMode ) && !downloaded && !theme.webURL || true ? (
|
{ ( !isEditMode ) && !downloaded /* && !theme.webURL */ ? (
|
||||||
<>
|
<>
|
||||||
<div
|
<div
|
||||||
className="absolute z-20 flex w-8 h-8 p-2 text-white transition-all rounded-full delay-[20ms] opacity-0 top-1 right-2 bg-black/50 place-items-center group-hover:opacity-100 group-hover:top-[1.25rem]"
|
className="absolute z-20 flex w-8 h-8 p-2 text-white transition-all rounded-full delay-[20ms] opacity-0 top-1 right-2 bg-black/50 place-items-center group-hover:opacity-100 group-hover:top-[1.25rem]"
|
||||||
|
|||||||
@@ -2,18 +2,6 @@ import browser from 'webextension-polyfill'
|
|||||||
import { CustomTheme, DownloadedTheme, ThemeList } from '../types/CustomThemes';
|
import { CustomTheme, DownloadedTheme, ThemeList } from '../types/CustomThemes';
|
||||||
import localforage from 'localforage';
|
import localforage from 'localforage';
|
||||||
|
|
||||||
export const downloadTheme = async (themeName: string, themeURL: string) => {
|
|
||||||
// send message to the background script
|
|
||||||
await browser.runtime.sendMessage({
|
|
||||||
type: 'currentTab',
|
|
||||||
info: 'DownloadTheme',
|
|
||||||
body: {
|
|
||||||
themeName: themeName,
|
|
||||||
themeURL: themeURL
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export const setTheme = async (themeID: string) => {
|
export const setTheme = async (themeID: string) => {
|
||||||
// send message to the background script
|
// send message to the background script
|
||||||
await browser.runtime.sendMessage({
|
await browser.runtime.sendMessage({
|
||||||
|
|||||||
@@ -1,104 +1,52 @@
|
|||||||
//import PocketBase from 'pocketbase';
|
|
||||||
import localforage from 'localforage';
|
import localforage from 'localforage';
|
||||||
import { ThemesResponse } from '../../../interface/types/pocketbase-types';
|
|
||||||
import { CustomTheme } from '../../../interface/types/CustomThemes';
|
|
||||||
import { Theme } from '../../../interface/pages/Store';
|
import { Theme } from '../../../interface/pages/Store';
|
||||||
|
import base64ToBlob from '../../utils/base64ToBlob';
|
||||||
const DownloadTheme = async (theme: ThemesResponse & { theme: CustomTheme & { images: { id: string, variableName: string }[] } }) => {
|
|
||||||
const images: { imageData: Blob, imageID: string }[] = []
|
|
||||||
for (const imageID of theme.images) {
|
|
||||||
console.log(theme.images, `https://betterseqta.pockethost.io/api/files/${theme.collectionId}/${theme.id}/${imageID}`);
|
|
||||||
const image = await fetch(
|
|
||||||
`https://betterseqta.pockethost.io/api/files/${theme.collectionId}/${theme.id}/${imageID}`
|
|
||||||
)
|
|
||||||
const imageData = await image.blob();
|
|
||||||
|
|
||||||
images.push({ imageData, imageID });
|
|
||||||
}
|
|
||||||
|
|
||||||
const coverImage = await fetch(
|
|
||||||
`https://betterseqta.pockethost.io/api/files/${theme.collectionId}/${theme.id}/${theme.coverImage}`
|
|
||||||
);
|
|
||||||
|
|
||||||
// add to temp storage index
|
|
||||||
let availableThemes = await localforage.getItem('availableThemes') as string[];
|
|
||||||
if (availableThemes && !availableThemes.includes(theme.theme.id)) {
|
|
||||||
availableThemes.push(theme.theme.id);
|
|
||||||
} else if (!availableThemes) {
|
|
||||||
availableThemes = [theme.theme.id];
|
|
||||||
}
|
|
||||||
localforage.setItem('availableThemes', availableThemes);
|
|
||||||
|
|
||||||
localforage.setItem(theme.theme.id, {
|
|
||||||
...theme.theme,
|
|
||||||
webURL: theme.id,
|
|
||||||
coverImage: await coverImage.blob(),
|
|
||||||
CustomImages: theme.theme.images.map((image) => {
|
|
||||||
return {
|
|
||||||
...image,
|
|
||||||
blob: images.find((img) => {
|
|
||||||
return image.id.includes(img.imageID.split('_')[0]);
|
|
||||||
})?.imageData
|
|
||||||
}
|
|
||||||
})
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
type ThemeContent = {
|
type ThemeContent = {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
coverImage: string;
|
coverImage: string; // base64
|
||||||
description: string;
|
description: string;
|
||||||
defaultColour: string;
|
defaultColour: string;
|
||||||
CanChangeColour: boolean;
|
CanChangeColour: boolean;
|
||||||
CustomCSS: string;
|
CustomCSS: string;
|
||||||
hideThemeName: boolean;
|
hideThemeName: boolean;
|
||||||
images: { id: string, variableName: string }[];
|
images: { id: string, variableName: string, data: string }[]; // data: base64
|
||||||
}
|
};
|
||||||
|
|
||||||
export const StoreDownloadTheme = async (theme: { themeContent: Theme }) => {
|
export const StoreDownloadTheme = async (theme: { themeContent: Theme }) => {
|
||||||
console.log(theme.themeContent.id);
|
console.log(theme.themeContent.id);
|
||||||
if (!theme.themeContent.id) return;
|
if (!theme.themeContent.id) return;
|
||||||
|
|
||||||
const themeContent = await fetch(`https://raw.githubusercontent.com/BetterSEQTA/BetterSEQTA-Themes/main/store/themes/${theme.themeContent.id}/theme.json`);
|
const themeContent = await fetch(`https://raw.githubusercontent.com/BetterSEQTA/BetterSEQTA-Themes/main/store/themes/${theme.themeContent.id}/theme.json`);
|
||||||
const themeData = await themeContent.json() as ThemeContent;
|
const themeData = await themeContent.json() as ThemeContent;
|
||||||
|
|
||||||
const images: { imageData: Blob, imageID: string }[] = []
|
const coverImageBlob = base64ToBlob(themeData.coverImage);
|
||||||
for (const image of themeData.images) {
|
|
||||||
const data = await fetch(
|
|
||||||
`https://raw.githubusercontent.com/BetterSEQTA/BetterSEQTA-Themes/main/store/themes/${themeData.id}/images/${image.id}`
|
|
||||||
)
|
|
||||||
const imageData = await data.blob();
|
|
||||||
|
|
||||||
images.push({ imageData, imageID: image.id });
|
const images = themeData.images.map((image) => ({
|
||||||
}
|
...image,
|
||||||
|
blob: base64ToBlob(image.data)
|
||||||
|
}));
|
||||||
|
|
||||||
const coverImage = await fetch(
|
|
||||||
`https://raw.githubusercontent.com/BetterSEQTA/BetterSEQTA-Themes/main/store/themes/${themeData.id}/images/${themeData.coverImage}`
|
|
||||||
);
|
|
||||||
|
|
||||||
// add to temp storage index
|
|
||||||
let availableThemes = await localforage.getItem('availableThemes') as string[];
|
let availableThemes = await localforage.getItem('availableThemes') as string[];
|
||||||
if (availableThemes && !availableThemes.includes(themeData.id)) {
|
if (availableThemes && !availableThemes.includes(themeData.id)) {
|
||||||
availableThemes.push(themeData.id);
|
availableThemes.push(themeData.id);
|
||||||
} else if (!availableThemes) {
|
} else if (!availableThemes) {
|
||||||
availableThemes = [themeData.id];
|
availableThemes = [themeData.id];
|
||||||
}
|
}
|
||||||
localforage.setItem('availableThemes', availableThemes);
|
await localforage.setItem('availableThemes', availableThemes);
|
||||||
|
|
||||||
localforage.setItem(themeData.id, {
|
await localforage.setItem(themeData.id, {
|
||||||
...themeData,
|
...themeData,
|
||||||
webURL: theme.themeContent.id,
|
webURL: theme.themeContent.id,
|
||||||
coverImage: await coverImage.blob(),
|
coverImage: coverImageBlob,
|
||||||
CustomImages: themeData.images.map((image) => {
|
CustomImages: themeData.images.map((image) => {
|
||||||
return {
|
return {
|
||||||
...image,
|
...image,
|
||||||
blob: images.find((img) => {
|
blob: images.find((img) => image.id === img.id)?.blob
|
||||||
return image.id.includes(img.imageID.split('_')[0]);
|
};
|
||||||
})?.imageData
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
|
export default StoreDownloadTheme;
|
||||||
export default DownloadTheme;
|
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
const base64ToBlob = (base64: string, contentType: string = ''): Blob => {
|
||||||
|
const byteCharacters = atob(base64.split(',')[1]);
|
||||||
|
const byteArrays: Uint8Array[] = [];
|
||||||
|
|
||||||
|
for (let offset = 0; offset < byteCharacters.length; offset += 512) {
|
||||||
|
const slice = byteCharacters.slice(offset, offset + 512);
|
||||||
|
const byteNumbers = new Array(slice.length);
|
||||||
|
for (let i = 0; i < slice.length; i++) {
|
||||||
|
byteNumbers[i] = slice.charCodeAt(i);
|
||||||
|
}
|
||||||
|
const byteArray = new Uint8Array(byteNumbers);
|
||||||
|
byteArrays.push(byteArray);
|
||||||
|
}
|
||||||
|
return new Blob(byteArrays, { type: contentType });
|
||||||
|
};
|
||||||
|
|
||||||
|
export default base64ToBlob;
|
||||||
Reference in New Issue
Block a user