fix(settings): issues with new themes systems

This commit is contained in:
StroepWafel committed 2026-08-26 21:11:53 +09:30
1 parent d980c01c81
commit dc3b77f82b
14 files changed
+477 -147

No files matched your search

@@ -3,12 +3,12 @@
import { onDestroy, onMount } from 'svelte'
import browser from 'webextension-polyfill'
import { themeUpdates } from '@/interface/hooks/ThemeUpdates'
import { closeExtensionPopup } from '@/seqta/utils/Closers/closeExtensionPopup'
import { ThemeManager } from '@/plugins/built-in/themes/theme-manager'
import { cloudAuth } from '@/seqta/utils/CloudAuth'
import SignInToFavoriteModal from '@/interface/components/SignInToFavoriteModal.svelte'
import ThemeBlobImage from '@/interface/components/themes/ThemeBlobImage.svelte'
import { filterThemesByMode, type ThemeListMode } from '@/interface/utils/themeListFilters'
import { filterThemesByMode, isLocalCustomTheme, type ThemeListMode } from '@/interface/utils/themeListFilters'
import { closeExtensionPopup, SettingsClicked } from '@/seqta/utils/Closers/closeExtensionPopup'
const themeManager = ThemeManager.getInstance();
@@ -19,7 +19,9 @@
listMode?: ThemeListMode;
}>();
let isDragging = $state(false);
let dragDepth = $state(0);
let tempTheme = $state(null);
let fileInput = $state<HTMLInputElement | null>(null);
let favoriteStatus = $state<Record<string, boolean>>({});
let cloudLoggedIn = $state(cloudAuth.state.isLoggedIn);
let prevLoggedIn = $state(false);
@@ -72,21 +74,33 @@
}
}
const handleDragOver = (e: DragEvent) => {
const allowsFileImport = $derived(listMode === 'custom');
const handleDragEnter = (e: DragEvent) => {
if (!allowsFileImport) return;
e.preventDefault();
dragDepth += 1;
isDragging = true;
}
const handleDragLeave = () => {
isDragging = false;
const handleDragOver = (e: DragEvent) => {
if (!allowsFileImport) return;
e.preventDefault();
if (e.dataTransfer) e.dataTransfer.dropEffect = 'copy';
isDragging = true;
}
const handleDrop = async (e: DragEvent) => {
const handleDragLeave = (e: DragEvent) => {
if (!allowsFileImport) return;
e.preventDefault();
isDragging = false;
const file = e.dataTransfer?.files[0];
if (!file) return;
dragDepth -= 1;
if (dragDepth <= 0) {
dragDepth = 0;
isDragging = false;
}
}
async function importThemeFromFile(file: File) {
const reader = new FileReader();
reader.onload = async (event: ProgressEvent<FileReader>) => {
try {
@@ -103,6 +117,27 @@
reader.readAsText(file);
}
const handleDrop = async (e: DragEvent) => {
if (!allowsFileImport) return;
e.preventDefault();
dragDepth = 0;
isDragging = false;
const file = e.dataTransfer?.files[0];
if (!file) return;
await importThemeFromFile(file);
}
const handleFileInputChange = async (e: Event) => {
const input = e.currentTarget as HTMLInputElement;
const file = input.files?.[0];
if (file) await importThemeFromFile(file);
input.value = '';
}
const triggerFileUpload = () => {
fileInput?.click();
}
const fetchThemes = async () => {
themes = {
themes: await themeManager.getAvailableThemes(),
@@ -139,20 +174,30 @@
const openThemeCreator = async (themeId?: string) => {
const { OpenThemeCreator } = await import('@/plugins/built-in/themes/ThemeCreator')
OpenThemeCreator(themeId)
closeExtensionPopup()
if (!SettingsClicked) closeExtensionPopup()
}
const openCommunitySubmit = async () => {
if (SettingsClicked) {
const [{ requestSettingsDestination }, { requestOpenCommunityThemeSubmit }] =
await Promise.all([
import('@/seqta/utils/settingsNavigation'),
import('@/seqta/utils/openCommunityThemeSubmit'),
])
requestOpenCommunityThemeSubmit()
requestSettingsDestination({ page: 'themes', view: 'community' })
return
}
const { openCommunityThemeSubmit } = await import('@/seqta/utils/openCommunityThemeSubmit')
await openCommunityThemeSubmit()
closeExtensionPopup()
}
const customThemeActionClass =
'flex items-center justify-center gap-2 w-full rounded-xl transition bg-zinc-100 text-xl dark:bg-zinc-900 dark:text-white hover:bg-zinc-200 dark:hover:bg-zinc-800'
'flex h-12 items-center justify-center gap-2 w-full rounded-xl transition bg-zinc-100 text-xl dark:bg-zinc-900 dark:text-white hover:bg-zinc-200 dark:hover:bg-zinc-800'
const customThemeActionCompactClass =
`${customThemeActionClass} h-full min-h-0`
const customThemeActionCompactClass = customThemeActionClass
const handleToggleFavorite = async (theme: CustomTheme, e: MouseEvent) => {
e.stopPropagation();
@@ -187,29 +232,51 @@
const useTwoColumnLayout = $derived(listMode === 'downloaded' || listMode === 'custom');
</script>
{#snippet customThemeUploadZone()}
<button
type="button"
onclick={triggerFileUpload}
class="flex aspect-theme w-full flex-col items-center justify-center gap-2 rounded-xl border-2 border-dashed border-zinc-300 bg-zinc-50 px-4 py-6 text-center transition hover:border-zinc-400 hover:bg-zinc-100 dark:border-zinc-600 dark:bg-zinc-900/40 dark:hover:border-zinc-500 dark:hover:bg-zinc-900 {useTwoColumnLayout ? 'col-span-2' : ''}"
>
<span class="text-2xl font-IconFamily text-zinc-500 dark:text-zinc-400" aria-hidden="true">&#xe9fc;</span>
<span class="text-base font-medium text-zinc-700 dark:text-zinc-200">Drag and drop theme files here</span>
<span class="text-sm text-zinc-500 dark:text-zinc-400">or click to upload</span>
</button>
{/snippet}
<div
class="mb-1 w-full {useTwoColumnLayout ? '' : 'max-w-lg mx-auto'}"
class="relative mb-1 w-full {useTwoColumnLayout ? '' : 'max-w-lg mx-auto'}"
role="list"
tabindex="-1"
ondragenter={handleDragEnter}
ondragover={handleDragOver}
ondragleave={handleDragLeave}
ondrop={handleDrop}
>
<div class="{isDragging ? 'opacity-100' : 'opacity-0'} transition pointer-events-none absolute w-full p-2 z-50">
<div class="sticky top-5 w-full h-64 bg-white rounded-xl shadow-xl dark:bg-zinc-900 dark:text-white outline-dashed outline-4 outline-zinc-200 dark:outline-zinc-700">
<div class="flex justify-center items-center h-full">
<div class="flex flex-col justify-center items-center">
<svg height="48" width="48" viewBox="0 0 48 48" xmlns="http://www.w3.org/2000/svg">
<g fill="currentColor">
<path d="M44,31a1,1,0,0,0-1,1v8a3,3,0,0,1-3,3H8a3,3,0,0,1-3-3V32a1,1,0,0,0-2,0v8a5.006,5.006,0,0,0,5,5H40a5.006,5.006,0,0,0,5-5V32A1,1,0,0,0,44,31Z" fill="currentColor"/>
<path d="M23.2,33.6a1,1,0,0,0,1.6,0l9-12A1,1,0,0,0,33,20H26V5a2,2,0,0,0-4,0V20H15a1,1,0,0,0-.8,1.6Z" fill="currentColor"/>
</g>
</svg>
<span class="text-lg">Import Theme</span>
</div>
{#if allowsFileImport}
<input
bind:this={fileInput}
type="file"
accept=".json,application/json"
class="hidden"
onchange={(e) => void handleFileInputChange(e)}
/>
{/if}
{#if allowsFileImport && isDragging}
<div class="absolute inset-0 z-50 flex items-center justify-center p-3 pointer-events-none">
<div class="flex h-full w-full flex-col items-center justify-center gap-3 rounded-xl border-4 border-dashed border-zinc-300 bg-white/95 px-6 text-center shadow-xl dark:border-zinc-600 dark:bg-zinc-900/95 dark:text-white">
<svg height="48" width="48" viewBox="0 0 48 48" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
<g fill="currentColor">
<path d="M44,31a1,1,0,0,0-1,1v8a3,3,0,0,1-3,3H8a3,3,0,0,1-3-3V32a1,1,0,0,0-2,0v8a5.006,5.006,0,0,0,5,5H40a5.006,5.006,0,0,0,5-5V32A1,1,0,0,0,44,31Z" fill="currentColor"/>
<path d="M23.2,33.6a1,1,0,0,0,1.6,0l9-12A1,1,0,0,0,33,20H26V5a2,2,0,0,0-4,0V20H15a1,1,0,0,0-.8,1.6Z" fill="currentColor"/>
</g>
</svg>
<span class="text-lg font-medium">Drop theme file to import</span>
</div>
</div>
</div>
{/if}
<div class="{useTwoColumnLayout ? 'grid grid-cols-2 gap-3' : 'flex flex-col gap-2 px-2'}">
{#if themes}
{#each visibleThemes as theme (theme.id)}
@@ -230,38 +297,45 @@
{/if}
{#if !isEditMode}
<div
class="flex absolute right-24 top-1/4 z-20 place-items-center p-2 w-8 h-8 text-center rounded-full opacity-0 transition-all -translate-y-1/2 group-hover:opacity-100 group-hover:top-1/2 {(favoriteStatus[theme.id] ?? false) ? 'text-red-400' : 'text-white/80'} bg-black/50"
onclick={(event) => handleToggleFavorite(theme, event)}
onkeydown={(event) => { if (event.key === 'Enter' || event.key === ' ') handleToggleFavorite(theme, event as any) }}
role="button"
tabindex="-1"
title={cloudLoggedIn ? ((favoriteStatus[theme.id] ?? false) ? 'Remove from favorites' : 'Add to favorites') : 'Sign in to favorite themes'}
>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill={(favoriteStatus[theme.id] ?? false) ? 'currentColor' : 'none'} stroke="currentColor" stroke-width="2" class="w-5 h-5">
<path stroke-linecap="round" stroke-linejoin="round" d="M4.318 6.318a4.5 4.5 0 000 6.364L12 20.364l7.682-7.682a4.5 4.5 0 00-6.364-6.364L12 7.636l-1.318-1.318a4.5 4.5 0 00-6.364 0z" />
</svg>
</div>
{#if theme.isEditable}
<div class="absolute inset-y-0 right-3 z-20 flex items-center gap-2 opacity-0 transition-opacity group-hover:opacity-100">
{#if !isLocalCustomTheme(theme)}
<div
class="flex h-8 w-8 place-items-center rounded-full bg-black/50 p-2 text-center {(favoriteStatus[theme.id] ?? false) ? 'text-red-400' : 'text-white/80'}"
onclick={(event) => handleToggleFavorite(theme, event)}
onkeydown={(event) => { if (event.key === 'Enter' || event.key === ' ') handleToggleFavorite(theme, event as any) }}
role="button"
tabindex="-1"
title={cloudLoggedIn ? ((favoriteStatus[theme.id] ?? false) ? 'Remove from favorites' : 'Add to favorites') : 'Sign in to favorite themes'}
>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill={(favoriteStatus[theme.id] ?? false) ? 'currentColor' : 'none'} stroke="currentColor" stroke-width="2" class="h-5 w-5">
<path stroke-linecap="round" stroke-linejoin="round" d="M4.318 6.318a4.5 4.5 0 000 6.364L12 20.364l7.682-7.682a4.5 4.5 0 00-6.364-6.364L12 7.636l-1.318-1.318a4.5 4.5 0 00-6.364 0z" />
</svg>
</div>
{/if}
<div
class="absolute z-20 flex w-8 h-8 p-2 text-white transition-all rounded-full delay-[20ms] opacity-0 top-1/4 right-2 bg-black/50 place-items-center group-hover:opacity-100 group-hover:top-1/2 -translate-y-1/2"
onclick={(event) => { event.stopPropagation(); void openThemeCreator(theme.id) }}
onkeydown={(event) => { if (event.key === 'Enter' || event.key === ' ') void openThemeCreator(theme.id) }}
class="flex h-8 w-8 place-items-center rounded-full bg-black/50 p-2 text-white/80"
onclick={(event) => { event.stopPropagation(); handleShareTheme(theme) }}
onkeydown={(event) => { if (event.key === 'Enter' || event.key === ' ') handleShareTheme(theme) }}
role="button"
tabindex="-1"
title="Export theme"
>
<span class="text-lg font-IconFamily">&#xeaa5;</span>
<span class="text-lg font-IconFamily">&#xecb3;</span>
</div>
{/if}
<div
class="flex absolute right-12 top-1/4 z-20 place-items-center p-2 w-8 h-8 text-center rounded-full opacity-0 transition-all -translate-y-1/2 text-white/80 bg-black/50 group-hover:opacity-100 group-hover:top-1/2"
onclick={(event) => { event.stopPropagation(); handleShareTheme(theme) }}
onkeydown={(event) => { if (event.key === 'Enter' || event.key === ' ') handleShareTheme(theme) }}
role="button"
tabindex="-1"
>
<span class="text-lg font-IconFamily">&#xecb3;</span>
{#if isLocalCustomTheme(theme)}
<div
class="flex h-8 w-8 place-items-center rounded-full bg-black/50 p-2 text-white"
onclick={(event) => { event.stopPropagation(); void openThemeCreator(theme.id) }}
onkeydown={(event) => { if (event.key === 'Enter' || event.key === ' ') void openThemeCreator(theme.id) }}
role="button"
tabindex="-1"
title="Edit theme"
>
<span class="text-lg font-IconFamily">&#xeaa5;</span>
</div>
{/if}
</div>
{/if}
@@ -297,17 +371,10 @@
No custom themes yet
</h3>
<p class="mt-2 max-w-md text-base text-zinc-500 dark:text-zinc-400" style="text-wrap: pretty">
Create your own theme or follow our guide to get started.
Create your own theme, or follow our guide to get started.
</p>
<div class="mt-6 grid w-full max-w-md grid-cols-1 gap-2">
<button
type="button"
onclick={() => void openThemeCreator()}
class="flex h-11 items-center justify-center gap-2 rounded-lg bg-zinc-200 px-4 font-medium text-zinc-900 transition-[background-color,color,transform] duration-150 hover:bg-zinc-300 active:scale-[0.96] focus:outline-none focus:ring-2 focus:ring-zinc-400 dark:bg-zinc-700 dark:text-white dark:hover:bg-zinc-600"
>
<span class="font-IconFamily text-lg" aria-hidden="true">&#xec60;</span>
Create a theme
</button>
<div class="mt-6 w-full max-w-md">
{@render customThemeUploadZone()}
</div>
{:else if listMode === 'downloaded'}
<h3 class="text-xl font-semibold text-zinc-900 dark:text-white" style="text-wrap: balance">
@@ -355,36 +422,38 @@
</div>
{/if}
{#if themes && ((showNavigation && visibleThemes.length > 0) || (listMode === 'custom' && visibleThemes.length > 0) || (listMode === 'downloaded' && visibleThemes.length > 0))}
{#if allowsFileImport && themes && visibleThemes.length > 0 && !tempTheme}
{@render customThemeUploadZone()}
{/if}
{#if themes && (listMode === 'custom' || (showNavigation && visibleThemes.length > 0) || (listMode === 'downloaded' && visibleThemes.length > 0))}
<div id="divider" class="w-full h-[1px] my-2 bg-zinc-100 dark:bg-zinc-600 {useTwoColumnLayout ? 'col-span-2' : ''}"></div>
{#if listMode === 'custom'}
<div class="grid gap-2 {useTwoColumnLayout ? 'col-span-2' : ''}">
<div class="grid w-full grid-cols-2 gap-2 aspect-[10/1]">
<button
type="button"
onclick={() => void openThemeCreator()}
class={customThemeActionCompactClass}
>
<span class="text-2xl font-IconFamily" aria-hidden="true">&#xec60;</span>
<span>Create theme</span>
</button>
<div class="grid grid-cols-2 gap-2 {useTwoColumnLayout ? 'col-span-2' : ''}">
<button
type="button"
onclick={() => void openThemeCreator()}
class={customThemeActionCompactClass}
>
<span class="text-2xl font-IconFamily" aria-hidden="true">&#xec60;</span>
<span>Create theme</span>
</button>
<a
href="https://docs.betterseqta.org/theme-creation/"
target="_blank"
rel="noopener noreferrer"
class={customThemeActionCompactClass}
>
<span class="text-2xl font-IconFamily" aria-hidden="true">{'\uecb3'}</span>
<span>View docs</span>
</a>
</div>
<a
href="https://docs.betterseqta.org/theme-creation/"
target="_blank"
rel="noopener noreferrer"
class={customThemeActionCompactClass}
>
<span class="text-2xl font-IconFamily" aria-hidden="true">{'\uecb3'}</span>
<span>View docs</span>
</a>
<button
type="button"
onclick={() => void openCommunitySubmit()}
class="{customThemeActionClass} aspect-[10/1]"
class="{customThemeActionClass} col-span-2"
>
<span class="text-2xl font-IconFamily" aria-hidden="true">&#xe9fc;</span>
<span>Submit theme</span>
+3 -3
View File
@@ -34,7 +34,7 @@
} from "@/seqta/utils/customThemes/buildThemeUploadFormData";
import type { CustomThemeOwner, CustomThemeFile } from "@/seqta/utils/customThemes/types";
import type { LoadedCustomTheme } from "@/types/CustomThemes";
import { consumeOpenCommunityThemeSubmit, OPEN_COMMUNITY_SUBMIT_EVENT } from "@/seqta/utils/openCommunityThemeSubmit";
import { isLocalCustomTheme } from "@/interface/utils/themeListFilters";
let {
searchTerm,
@@ -138,7 +138,7 @@
async function loadEditableThemes() {
const all = await themeManager.getAvailableThemes();
editableThemes = all.filter((t) => t.isEditable === true) as LoadedCustomTheme[];
editableThemes = all.filter(isLocalCustomTheme) as LoadedCustomTheme[];
}
async function openDetail(theme: CustomThemeOwner) {
@@ -219,7 +219,7 @@
payload = mergeUploadPayload(await buildUploadPartsFromZipFile(selectedZipFile), submitNotes);
} else if (selectedLocalThemeId) {
const local = (await themeManager.getTheme(selectedLocalThemeId)) as LoadedCustomTheme | null;
if (!local || !local.isEditable) throw new Error("Select a custom theme to submit");
if (!local || !isLocalCustomTheme(local)) throw new Error("Select a custom theme to submit");
payload = mergeUploadPayload(await buildUploadPartsFromLocalTheme(local), submitNotes);
} else {
throw new Error("Choose a ZIP file or a custom theme");
+6 -6
View File
@@ -293,6 +293,12 @@
</span>
</a>
<button
onclick={submitTheme}
class="mt-3 w-full rounded-xl bg-zinc-900 px-4 py-3 text-[13px] font-medium text-white transition hover:bg-zinc-700 dark:bg-zinc-100 dark:text-zinc-900 dark:hover:bg-white">
Save Theme
</button>
<Divider />
<div>
@@ -424,11 +430,5 @@
] as SettingItem[] as setting}
{@render settingItem(setting)}
{/each}
<button
onclick={submitTheme}
class="w-full px-4 py-2 mt-3 text-[13px] dark:text-white transition rounded-xl bg-zinc-200 dark:bg-zinc-700/50">
Save Theme
</button>
</div>
</div>
+87 -7
View File
@@ -3,7 +3,10 @@ import type { Theme } from '@/interface/types/Theme';
import {
filterThemesByMode,
getThemeApplyButtonStyles,
isDownloadedTheme,
isLocalCustomTheme,
isStoreThemeInstalled,
resolveLocalThemeInstallId,
resolveStoreVariantAccentColor,
} from './themeListFilters';
@@ -30,20 +33,97 @@ function makeStoreTheme(overrides: Partial<Theme> & Pick<Theme, 'id' | 'name'>):
};
}
describe('isLocalCustomTheme', () => {
it('returns true for file imports and theme creator saves', () => {
expect(isLocalCustomTheme(makeCustomTheme({ id: 'a', name: 'A' }))).toBe(true);
expect(
isLocalCustomTheme(
makeCustomTheme({ id: 'b', name: 'B', installedFromStore: false }),
),
).toBe(true);
});
it('returns false for store and community installs', () => {
expect(
isLocalCustomTheme(
makeCustomTheme({ id: 's', name: 'S', installedFromStore: true }),
),
).toBe(false);
expect(
isLocalCustomTheme(
makeCustomTheme({ id: 'c', name: 'C', installedFromCommunity: true }),
),
).toBe(false);
});
});
describe('resolveLocalThemeInstallId', () => {
it('keeps the id for store installs', () => {
expect(resolveLocalThemeInstallId('theme-1', null, true, false)).toBe('theme-1');
});
it('generates a new id when a local import collides with a store copy', () => {
const nextId = resolveLocalThemeInstallId(
'theme-1',
makeCustomTheme({ id: 'theme-1', name: 'Store', installedFromStore: true }),
false,
false,
);
expect(nextId).not.toBe('theme-1');
});
it('keeps the id when replacing an existing local copy', () => {
expect(
resolveLocalThemeInstallId(
'theme-1',
makeCustomTheme({ id: 'theme-1', name: 'Local' }),
false,
false,
),
).toBe('theme-1');
});
});
describe('filterThemesByMode', () => {
const downloaded = makeCustomTheme({ id: 'store-1', name: 'Store Theme', isEditable: false });
const custom = makeCustomTheme({ id: 'custom-1', name: 'Custom Theme', isEditable: true });
const storeTheme = makeCustomTheme({
id: 'store-1',
name: 'Store Theme',
installedFromStore: true,
});
const communityTheme = makeCustomTheme({
id: 'community-1',
name: 'Community Theme',
installedFromCommunity: true,
});
const localTheme = makeCustomTheme({ id: 'local-1', name: 'Local Theme' });
const fileImport = makeCustomTheme({
id: 'file-1',
name: 'Imported Theme',
installedFromStore: false,
isEditable: false,
});
it('returns all themes in all mode', () => {
expect(filterThemesByMode([downloaded, custom], 'all')).toEqual([downloaded, custom]);
expect(filterThemesByMode([storeTheme, localTheme], 'all')).toEqual([storeTheme, localTheme]);
});
it('returns only non-editable themes in downloaded mode', () => {
expect(filterThemesByMode([downloaded, custom], 'downloaded')).toEqual([downloaded]);
it('returns store and community themes in downloaded mode', () => {
expect(
filterThemesByMode([storeTheme, communityTheme, localTheme, fileImport], 'downloaded'),
).toEqual([storeTheme, communityTheme]);
});
it('returns only editable themes in custom mode', () => {
expect(filterThemesByMode([downloaded, custom], 'custom')).toEqual([custom]);
it('returns local/file themes in custom mode', () => {
expect(
filterThemesByMode([storeTheme, communityTheme, localTheme, fileImport], 'custom'),
).toEqual([localTheme, fileImport]);
});
it('isDownloadedTheme is the inverse of isLocalCustomTheme for known sources', () => {
expect(isDownloadedTheme(storeTheme)).toBe(true);
expect(isLocalCustomTheme(storeTheme)).toBe(false);
expect(isDownloadedTheme(localTheme)).toBe(false);
expect(isLocalCustomTheme(localTheme)).toBe(true);
});
});
+32 -2
View File
@@ -6,10 +6,40 @@ export type ThemeListMode = 'downloaded' | 'custom' | 'all';
const DEFAULT_THEME_ACCENT = 'rgba(0, 123, 255, 1)';
/** Local themes: created in the editor or imported from a file (not store/community). */
export function isLocalCustomTheme(theme: CustomTheme): boolean {
return theme.installedFromStore !== true && theme.installedFromCommunity !== true;
}
/** Themes installed from the official store or community API. */
export function isDownloadedTheme(theme: CustomTheme): boolean {
return theme.installedFromStore === true || theme.installedFromCommunity === true;
}
/**
* When importing a local copy of a theme whose id already belongs to a store/community
* install, use a new id so both copies can coexist.
*/
export function resolveLocalThemeInstallId(
themeId: string,
existing: Pick<CustomTheme, 'installedFromStore' | 'installedFromCommunity'> | null,
fromStore: boolean,
fromCommunity: boolean,
): string {
if (fromStore || fromCommunity) return themeId;
if (
existing &&
(existing.installedFromStore === true || existing.installedFromCommunity === true)
) {
return crypto.randomUUID();
}
return themeId;
}
export function filterThemesByMode(themes: CustomTheme[], mode: ThemeListMode): CustomTheme[] {
if (mode === 'all') return themes;
if (mode === 'custom') return themes.filter((theme) => theme.isEditable === true);
return themes.filter((theme) => theme.isEditable !== true);
if (mode === 'custom') return themes.filter(isLocalCustomTheme);
return themes.filter(isDownloadedTheme);
}
export function isStoreThemeInstalled(theme: Theme, installedIds: string[]): boolean {
+13 -3
View File
@@ -23,6 +23,7 @@ import {
type ThemePageSyncInput,
} from "@/seqta/utils/patchThemeImagesPageContext";
import { verboseDebug, verboseInfo } from "@/utils/verboseLog";
import { resolveLocalThemeInstallId } from "@/interface/utils/themeListFilters";
import {
clearThemeRuntime,
injectThemeDom,
@@ -704,6 +705,15 @@ export class ThemeManager {
const fromStore = meta?.fromStore ?? false;
const fromCommunity = meta?.fromCommunity ?? false;
const serverUpdatedAtSec = meta?.serverUpdatedAtSec;
const isLocalInstall = !fromStore && !fromCommunity;
const existingTheme = (await localforage.getItem(themeData.id)) as CustomTheme | null;
const themeId = resolveLocalThemeInstallId(
themeData.id,
existingTheme,
fromStore,
fromCommunity,
);
// Handle cover image (optional)
let coverImageBlob = null;
@@ -740,17 +750,17 @@ export class ThemeManager {
.filter((img) => img !== null) ?? [];
const theme: LoadedCustomTheme = {
id: themeData.id,
id: themeId,
name: themeData.name,
description: themeData.description || "",
webURL: themeData.id,
webURL: themeId,
coverImage: coverImageBlob,
CustomImages: images,
CustomCSS: themeData.CustomCSS || "",
defaultColour: themeData.defaultColour || "rgba(0, 123, 255, 1)",
CanChangeColour: themeData.CanChangeColour ?? true,
allowBackgrounds: true,
isEditable: false,
isEditable: isLocalInstall,
hideThemeName: themeData.hideThemeName ?? false,
forceDark: themeData.forceDark,
installedFromStore: fromStore,
+2 -3
View File
@@ -6,6 +6,7 @@ import ColorLuminance from "./ColorLuminance";
import { settingsState } from "@/seqta/utils/listeners/SettingsState";
import { getAdaptiveColour } from "@/seqta/utils/adaptiveThemeColour";
import { getCustomThemeAdaptiveCssVariableBindings } from "@/seqta/ui/colors/customThemeAdaptiveBindings";
import { syncTransparencyEffectsClass } from "@/seqta/ui/colors/syncTransparencyEffectsClass";
import { resolveExtensionAssetUrl } from "@/lib/extensionAssetUrl";
import darkLogo from "@/resources/icons/betterseqta-light-full.png";
@@ -126,9 +127,7 @@ function getRepresentativeRgbChannels(s: string): { r: number; g: number; b: num
}
function applyColorsWith(selectedColor: string) {
if (settingsState.transparencyEffects) {
document.documentElement.classList.add("transparencyEffects");
}
syncTransparencyEffectsClass(settingsState.transparencyEffects === true);
// Common properties, always applied
const commonProps = {
@@ -0,0 +1,20 @@
/** @jest-environment jsdom */
import { syncTransparencyEffectsClass } from "./syncTransparencyEffectsClass";
describe("syncTransparencyEffectsClass", () => {
beforeEach(() => {
document.documentElement.classList.remove("transparencyEffects");
});
it("adds the transparency class when enabled", () => {
syncTransparencyEffectsClass(true);
expect(document.documentElement.classList.contains("transparencyEffects")).toBe(true);
});
it("removes the transparency class when disabled", () => {
document.documentElement.classList.add("transparencyEffects");
syncTransparencyEffectsClass(false);
expect(document.documentElement.classList.contains("transparencyEffects")).toBe(false);
});
});
@@ -0,0 +1,10 @@
export function syncTransparencyEffectsClass(
enabled: boolean,
root: HTMLElement = document.documentElement,
): void {
if (enabled) {
root.classList.add("transparencyEffects");
} else {
root.classList.remove("transparencyEffects");
}
}
+32 -14
View File
@@ -2,30 +2,48 @@ import { settingsState } from "@/seqta/utils/listeners/SettingsState";
import { animate } from "motion";
import { settingsPopup } from "@/seqta/utils/settingsPopup";
import {
beginSettingsPopupTransition,
isCurrentSettingsPopupTransition,
resetSettingsPopupVisualState,
trackSettingsPopupAnimation,
} from "@/seqta/utils/settingsPopupTransition";
export let SettingsClicked = false;
export const closeExtensionPopup = (extensionPopup?: HTMLElement) => {
if (!extensionPopup)
extensionPopup = document.getElementById("ExtensionPopup")!;
const generation = beginSettingsPopupTransition();
changeSettingsClicked(false);
if (!extensionPopup) {
extensionPopup = document.getElementById("ExtensionPopup") ?? undefined;
}
if (!extensionPopup) return false;
extensionPopup.classList.add("hide");
resetSettingsPopupVisualState(extensionPopup);
if (settingsState.animations) {
const panel = extensionPopup.shadowRoot?.querySelector<HTMLElement>(
"[data-settings-panel]",
);
animate(1, 0, {
onUpdate: (progress) => {
extensionPopup.style.opacity = Math.max(0, progress).toString();
},
duration: 0.18,
ease: "easeIn",
});
trackSettingsPopupAnimation(
animate(1, 0, {
onUpdate: (progress) => {
if (!isCurrentSettingsPopupTransition(generation)) return;
extensionPopup.style.opacity = Math.max(0, progress).toString();
},
duration: 0.18,
ease: "easeIn",
}),
);
if (panel) {
animate(
panel,
{ scale: [1, 0], opacity: [1, 0] },
{ duration: 0.18, ease: "easeIn" },
trackSettingsPopupAnimation(
animate(
panel,
{ scale: [1, 0], opacity: [1, 0] },
{ duration: 0.18, ease: "easeIn" },
),
);
}
} else {
@@ -33,7 +51,7 @@ export const closeExtensionPopup = (extensionPopup?: HTMLElement) => {
}
settingsPopup.triggerClose();
return (SettingsClicked = false);
return false;
};
export function changeSettingsClicked(newVal: boolean) {
+2 -6
View File
@@ -1,6 +1,6 @@
import { settingsState } from "./SettingsState";
import { updateAllColors } from "@/seqta/ui/colors/Manager";
import { applySelectedFont } from "@/seqta/ui/fonts/Manager";
import { syncTransparencyEffectsClass } from "@/seqta/ui/colors/syncTransparencyEffectsClass";
// Shortcuts rendering
import { renderShortcuts } from "@/seqta/utils/Render/renderShortcuts";
@@ -85,10 +85,6 @@ export class StorageChangeHandler {
}
private handleTransparencyEffectsChange(newValue: boolean) {
if (newValue) {
document.documentElement.classList.add("transparencyEffects");
} else {
document.documentElement.classList.remove("transparencyEffects");
}
syncTransparencyEffectsClass(newValue === true);
}
}
@@ -0,0 +1,30 @@
/** @jest-environment jsdom */
import {
beginSettingsPopupTransition,
isCurrentSettingsPopupTransition,
stopSettingsPopupAnimations,
trackSettingsPopupAnimation,
} from "./settingsPopupTransition";
describe("settingsPopupTransition", () => {
it("invalidates prior transitions when a new one begins", () => {
const first = beginSettingsPopupTransition();
expect(isCurrentSettingsPopupTransition(first)).toBe(true);
const second = beginSettingsPopupTransition();
expect(isCurrentSettingsPopupTransition(first)).toBe(false);
expect(isCurrentSettingsPopupTransition(second)).toBe(true);
});
it("clears tracked animations when a new transition begins", () => {
const stop = jest.fn();
stopSettingsPopupAnimations();
beginSettingsPopupTransition();
trackSettingsPopupAnimation({ stop } as never);
beginSettingsPopupTransition();
expect(stop).toHaveBeenCalledTimes(1);
});
});
@@ -0,0 +1,43 @@
import type { AnimationPlaybackControls } from "motion";
let popupTransitionGeneration = 0;
let activePopupAnimations: AnimationPlaybackControls[] = [];
export function beginSettingsPopupTransition(): number {
popupTransitionGeneration += 1;
stopSettingsPopupAnimations();
return popupTransitionGeneration;
}
export function isCurrentSettingsPopupTransition(generation: number): boolean {
return generation === popupTransitionGeneration;
}
export function trackSettingsPopupAnimation(
controls: AnimationPlaybackControls,
): void {
activePopupAnimations.push(controls);
}
export function stopSettingsPopupAnimations(): void {
for (const animation of activePopupAnimations) {
try {
animation.stop();
} catch {
/* ignore */
}
}
activePopupAnimations = [];
}
export function resetSettingsPopupVisualState(extensionPopup: HTMLElement): void {
extensionPopup.style.removeProperty("opacity");
extensionPopup.style.removeProperty("transition");
const panel = extensionPopup.shadowRoot?.querySelector<HTMLElement>(
"[data-settings-panel]",
);
if (panel) {
panel.style.removeProperty("opacity");
panel.style.removeProperty("scale");
}
}
+43 -18
View File
@@ -7,6 +7,11 @@ import { animate } from "motion";
import { settingsState } from "./listeners/SettingsState";
import { renderSettingsIfNeeded } from "./Adders/AddExtensionSettings";
import { delay } from "./delay";
import {
beginSettingsPopupTransition,
isCurrentSettingsPopupTransition,
trackSettingsPopupAnimation,
} from "./settingsPopupTransition";
export function setupSettingsButton() {
const AddedSettings = document.getElementById("AddedSettings");
@@ -26,38 +31,60 @@ export function setupSettingsButton() {
}
export async function openSettingsPopup(): Promise<void> {
if (SettingsClicked && document.getElementById("ExtensionPopup")) return;
// Re-query each time — Engage SPA navigations can recreate the host.
let extensionPopup = document.getElementById("ExtensionPopup");
if (
SettingsClicked &&
extensionPopup &&
!extensionPopup.classList.contains("hide")
) {
return;
}
const generation = beginSettingsPopupTransition();
changeSettingsClicked(true);
if (!extensionPopup) {
const { addExtensionSettings } = await import("./Adders/AddExtensionSettings");
addExtensionSettings();
extensionPopup = document.getElementById("ExtensionPopup");
}
if (!extensionPopup) return;
if (!extensionPopup) {
changeSettingsClicked(false);
return;
}
await renderSettingsIfNeeded();
if (!isCurrentSettingsPopupTransition(generation)) return;
await delay(30);
if (!isCurrentSettingsPopupTransition(generation)) return;
extensionPopup.style.transform = "none";
extensionPopup.classList.remove("hide");
const panel = extensionPopup.shadowRoot?.querySelector<HTMLElement>(
"[data-settings-panel]",
);
if (settingsState.animations) {
animate(0, 1, {
onUpdate: (progress) => {
extensionPopup.style.opacity = progress.toString();
},
type: "spring",
stiffness: 280,
damping: 20,
});
extensionPopup.style.opacity = "0";
trackSettingsPopupAnimation(
animate(0, 1, {
onUpdate: (progress) => {
if (!isCurrentSettingsPopupTransition(generation)) return;
extensionPopup.style.opacity = progress.toString();
},
type: "spring",
stiffness: 280,
damping: 20,
}),
);
if (panel) {
animate(
panel,
{ scale: [0, 1], opacity: [0, 1] },
{ type: "spring", stiffness: 330, damping: 30 },
trackSettingsPopupAnimation(
animate(
panel,
{ scale: [0, 1], opacity: [0, 1] },
{ type: "spring", stiffness: 330, damping: 30 },
),
);
}
} else {
@@ -68,6 +95,4 @@ export async function openSettingsPopup(): Promise<void> {
panel.style.opacity = "1";
}
}
extensionPopup.classList.remove("hide");
changeSettingsClicked(true);
}