Compare commits
7
Commits
4d57184b73
...
51f5fa3e46
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
51f5fa3e46 | ||
|
|
07cbfa39a6 | ||
|
|
11aefee7ed | ||
|
|
5eea428802 | ||
|
|
760bd9a283 | ||
|
|
47c022642f | ||
|
|
5613c3be25 |
No files matched your search
@@ -32,8 +32,8 @@
|
|||||||
"script-src": "'self' 'unsafe-inline' 'unsafe-eval' asset: http://asset.localhost https://asset.localhost http://127.0.0.1:* https://analytics.ez-pp.farm",
|
"script-src": "'self' 'unsafe-inline' 'unsafe-eval' asset: http://asset.localhost https://asset.localhost http://127.0.0.1:* https://analytics.ez-pp.farm",
|
||||||
"worker-src": ["'self'", "blob:"],
|
"worker-src": ["'self'", "blob:"],
|
||||||
"style-src": "'self' 'unsafe-inline' asset: http://asset.localhost https://asset.localhost http://127.0.0.1:*",
|
"style-src": "'self' 'unsafe-inline' asset: http://asset.localhost https://asset.localhost http://127.0.0.1:*",
|
||||||
"img-src": "'self' asset: http://asset.localhost https://asset.localhost blob: data: http://127.0.0.1:* https://assets.ppy.sh https://a.ez-pp.farm https://git.ez-pp.farm https://osu.direct",
|
"img-src": "'self' asset: http://asset.localhost https://asset.localhost blob: data: http://127.0.0.1:* https://assets.ppy.sh https://a.ez-pp.farm https://git.ez-pp.farm https://osu.direct https://themes.ez-pp.farm",
|
||||||
"connect-src": "'self' ipc: http://ipc.localhost asset: http://asset.localhost https://asset.localhost http://127.0.0.1:* https://ez-pp.farm https://api.ez-pp.farm https://c.ez-pp.farm https://analytics.ez-pp.farm https://git.ez-pp.farm https://osu.direct https://osu.ppy.sh https://api.fontsource.org https://cdn.jsdelivr.net",
|
"connect-src": "'self' ipc: http://ipc.localhost asset: http://asset.localhost https://asset.localhost http://127.0.0.1:* https://ez-pp.farm https://api.ez-pp.farm https://c.ez-pp.farm https://analytics.ez-pp.farm https://git.ez-pp.farm https://osu.direct https://osu.ppy.sh https://api.fontsource.org https://cdn.jsdelivr.net https://themes.ez-pp.farm",
|
||||||
"media-src": "'self' asset: http://asset.localhost https://asset.localhost http://127.0.0.1:* blob:",
|
"media-src": "'self' asset: http://asset.localhost https://asset.localhost http://127.0.0.1:* blob:",
|
||||||
"font-src": [
|
"font-src": [
|
||||||
"'self'",
|
"'self'",
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { config } from './config';
|
import { config } from './config';
|
||||||
|
import { normalizeThemeVersion } from './themeV2';
|
||||||
import {
|
import {
|
||||||
reloadThemes,
|
reloadThemes,
|
||||||
themesDirectory,
|
themesDirectory,
|
||||||
@@ -727,6 +728,13 @@ export async function publishThemeToWorkshop(options: {
|
|||||||
throw new Error('You must be logged in to EZPPFarm to publish themes.');
|
throw new Error('You must be logged in to EZPPFarm to publish themes.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const version = normalizeThemeVersion(options.version ?? '1.0.0');
|
||||||
|
if (!version) {
|
||||||
|
throw new Error(
|
||||||
|
'Theme version must use semantic versioning, for example 1.2.3 or 1.2.3-beta.1.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
onProgress('Packaging theme archive...', 5);
|
onProgress('Packaging theme archive...', 5);
|
||||||
|
|
||||||
const baseThemesDir = await themesDirectory();
|
const baseThemesDir = await themesDirectory();
|
||||||
@@ -771,7 +779,7 @@ export async function publishThemeToWorkshop(options: {
|
|||||||
themeId: options.workshopId || options.themeId,
|
themeId: options.workshopId || options.themeId,
|
||||||
name: options.name,
|
name: options.name,
|
||||||
description: options.description || '',
|
description: options.description || '',
|
||||||
version: options.version || '1.0.0',
|
version,
|
||||||
apiVersion: options.apiVersion || '2.0.0',
|
apiVersion: options.apiVersion || '2.0.0',
|
||||||
totalSize,
|
totalSize,
|
||||||
totalChunks,
|
totalChunks,
|
||||||
|
|||||||
File diff suppressed because it is too large.
Load diff
@@ -1,6 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import Logo from '$assets/logo.png';
|
import Logo from '$assets/logo.png';
|
||||||
import { publishThemeToWorkshop } from '$lib/communityThemes';
|
import { fetchCommunityThemeDetails, publishThemeToWorkshop } from '$lib/communityThemes';
|
||||||
import FontPreview from '$lib/components/theme/FontPreview.svelte';
|
import FontPreview from '$lib/components/theme/FontPreview.svelte';
|
||||||
import ThemeBehaviorInspector from '$lib/components/theme/ThemeBehaviorInspector.svelte';
|
import ThemeBehaviorInspector from '$lib/components/theme/ThemeBehaviorInspector.svelte';
|
||||||
import ThemeElementInspector from '$lib/components/theme/ThemeElementInspector.svelte';
|
import ThemeElementInspector from '$lib/components/theme/ThemeElementInspector.svelte';
|
||||||
@@ -75,6 +75,7 @@
|
|||||||
normalizeChrome,
|
normalizeChrome,
|
||||||
normalizeThemeTags,
|
normalizeThemeTags,
|
||||||
normalizeThemeV2,
|
normalizeThemeV2,
|
||||||
|
normalizeThemeVersion,
|
||||||
themeAssetName,
|
themeAssetName,
|
||||||
themeHasLaunchButton,
|
themeHasLaunchButton,
|
||||||
type ThemeV2Asset,
|
type ThemeV2Asset,
|
||||||
@@ -173,6 +174,7 @@
|
|||||||
import { getCurrentWindow } from '@tauri-apps/api/window';
|
import { getCurrentWindow } from '@tauri-apps/api/window';
|
||||||
import { open, save as saveDialog } from '@tauri-apps/plugin-dialog';
|
import { open, save as saveDialog } from '@tauri-apps/plugin-dialog';
|
||||||
import * as fs from '@tauri-apps/plugin-fs';
|
import * as fs from '@tauri-apps/plugin-fs';
|
||||||
|
import semver from 'semver';
|
||||||
import { sileo } from 'sileo';
|
import { sileo } from 'sileo';
|
||||||
import { onMount, tick } from 'svelte';
|
import { onMount, tick } from 'svelte';
|
||||||
import { SvelteMap, SvelteSet } from 'svelte/reactivity';
|
import { SvelteMap, SvelteSet } from 'svelte/reactivity';
|
||||||
@@ -287,6 +289,7 @@
|
|||||||
let panStart = { x: 0, y: 0, panX: 0, panY: 0 };
|
let panStart = { x: 0, y: 0, panX: 0, panY: 0 };
|
||||||
const canvasScale = $derived(canvasFitScale * canvasZoom);
|
const canvasScale = $derived(canvasFitScale * canvasZoom);
|
||||||
let statusMessage = $state('Ready');
|
let statusMessage = $state('Ready');
|
||||||
|
let lastPublishedVersion = $state<string | undefined>(undefined);
|
||||||
let renamingId = $state<string | undefined>(undefined);
|
let renamingId = $state<string | undefined>(undefined);
|
||||||
let draggingLayer = $state<LayerDragItem | undefined>(undefined);
|
let draggingLayer = $state<LayerDragItem | undefined>(undefined);
|
||||||
let dropTarget = $state<LayerDropTarget | undefined>(undefined);
|
let dropTarget = $state<LayerDropTarget | undefined>(undefined);
|
||||||
@@ -1803,6 +1806,7 @@
|
|||||||
|
|
||||||
async function loadContext() {
|
async function loadContext() {
|
||||||
loading = true;
|
loading = true;
|
||||||
|
lastPublishedVersion = undefined;
|
||||||
try {
|
try {
|
||||||
const context = await invoke<ThemeEditorContext>('theme_editor_context');
|
const context = await invoke<ThemeEditorContext>('theme_editor_context');
|
||||||
const parsed = context.themeJson
|
const parsed = context.themeJson
|
||||||
@@ -2920,6 +2924,12 @@
|
|||||||
notifyError('Add an author name so people know who made the theme.');
|
notifyError('Add an author name so people know who made the theme.');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
const version = normalizeThemeVersion(definition.version);
|
||||||
|
if (!version) {
|
||||||
|
notifyError('The version must use semantic versioning, for example 1.2.3 or 1.2.3-beta.1.');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (definition.version !== version) definition.version = version;
|
||||||
const folderName = savedFolder ?? toSafeName(definition.name);
|
const folderName = savedFolder ?? toSafeName(definition.name);
|
||||||
if (!folderName.replace(/_/g, '')) {
|
if (!folderName.replace(/_/g, '')) {
|
||||||
notifyError('The theme name needs at least one letter or number.');
|
notifyError('The theme name needs at least one letter or number.');
|
||||||
@@ -3016,8 +3026,10 @@
|
|||||||
|
|
||||||
if (!definition.name.trim()) error('The theme needs a name.');
|
if (!definition.name.trim()) error('The theme needs a name.');
|
||||||
if (!definition.author.trim()) error('The theme needs an author.');
|
if (!definition.author.trim()) error('The theme needs an author.');
|
||||||
if (!/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(definition.version.trim())) {
|
if (!normalizeThemeVersion(definition.version)) {
|
||||||
warning('The version should use semantic versioning, for example 1.0.0.');
|
error(
|
||||||
|
'The version must use semantic versioning, for example 1.0.0 or 1.0.0-beta.1, with no "v" prefix.'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (!themeHasLaunchButton(definition)) {
|
if (!themeHasLaunchButton(definition)) {
|
||||||
error(
|
error(
|
||||||
@@ -3340,10 +3352,68 @@
|
|||||||
let publishStatusMessage = $state('');
|
let publishStatusMessage = $state('');
|
||||||
let publishProgress = $state(0);
|
let publishProgress = $state(0);
|
||||||
|
|
||||||
|
async function checkPublishVersion(): Promise<
|
||||||
|
{ ok: true; version: string } | { ok: false; error: string }
|
||||||
|
> {
|
||||||
|
const proposed = normalizeThemeVersion(definition.version);
|
||||||
|
if (!proposed) {
|
||||||
|
return {
|
||||||
|
ok: false,
|
||||||
|
error: 'Use a semantic version such as 1.2.3 in the Theme tab before publishing.',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
let publishedVersion = lastPublishedVersion;
|
||||||
|
const workshopId = definition.workshopId?.trim();
|
||||||
|
if (workshopId) {
|
||||||
|
let remoteVersion: string;
|
||||||
|
try {
|
||||||
|
remoteVersion = (await fetchCommunityThemeDetails(workshopId)).version?.trim() ?? '';
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('[Workshop] Could not verify the published theme version:', error);
|
||||||
|
return {
|
||||||
|
ok: false,
|
||||||
|
error:
|
||||||
|
'Could not verify the current workshop version. Check your connection and try again.',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const validRemote = normalizeThemeVersion(remoteVersion);
|
||||||
|
if (!validRemote) {
|
||||||
|
return {
|
||||||
|
ok: false,
|
||||||
|
error:
|
||||||
|
'The current workshop version could not be read. Contact a workshop administrator.',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (!publishedVersion || semver.gt(validRemote, publishedVersion)) {
|
||||||
|
publishedVersion = validRemote;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (publishedVersion) {
|
||||||
|
if (semver.eq(proposed, publishedVersion)) {
|
||||||
|
return {
|
||||||
|
ok: false,
|
||||||
|
error: `Version ${proposed} has already been published. Increase the version before publishing again.`,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (!semver.gt(proposed, publishedVersion)) {
|
||||||
|
return {
|
||||||
|
ok: false,
|
||||||
|
error: `Version ${proposed} must be higher than the last published version ${publishedVersion}.`,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return { ok: true, version: proposed };
|
||||||
|
}
|
||||||
|
|
||||||
async function openPublishDialog() {
|
async function openPublishDialog() {
|
||||||
if (exporting || saving || publishing) return;
|
if (exporting || saving || publishing) return;
|
||||||
|
|
||||||
if (!$currentUser) {
|
const user = $currentUser;
|
||||||
|
if (!user) {
|
||||||
sileo.error({
|
sileo.error({
|
||||||
title: 'Authentication Required',
|
title: 'Authentication Required',
|
||||||
description:
|
description:
|
||||||
@@ -3361,8 +3431,23 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dirty) {
|
const versionCheck = await checkPublishVersion();
|
||||||
await saveTheme({ notify: false });
|
if (!versionCheck.ok) {
|
||||||
|
sileo.error({
|
||||||
|
title: 'Version not publishable',
|
||||||
|
description: versionCheck.error,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const versionChanged = definition.version !== versionCheck.version;
|
||||||
|
if (versionChanged) definition.version = versionCheck.version;
|
||||||
|
|
||||||
|
const authorIdChanged = definition.authorId !== user.id;
|
||||||
|
if (authorIdChanged) definition.authorId = user.id;
|
||||||
|
|
||||||
|
if (dirty || authorIdChanged || versionChanged) {
|
||||||
|
const saved = await saveTheme({ notify: false });
|
||||||
|
if (!saved) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
publishThemeId = definition.workshopId ?? '';
|
publishThemeId = definition.workshopId ?? '';
|
||||||
@@ -3399,17 +3484,34 @@
|
|||||||
|
|
||||||
async function handlePublishToWorkshop() {
|
async function handlePublishToWorkshop() {
|
||||||
if (publishing) return;
|
if (publishing) return;
|
||||||
if (!savedFolder) {
|
|
||||||
await saveTheme({ notify: false });
|
|
||||||
if (!savedFolder) return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const firstPublish = !definition.workshopId;
|
const firstPublish = !definition.workshopId;
|
||||||
publishing = true;
|
publishing = true;
|
||||||
publishProgress = 5;
|
publishProgress = 5;
|
||||||
publishStatusMessage = 'Packaging theme archive...';
|
publishStatusMessage = 'Checking version...';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const versionCheck = await checkPublishVersion();
|
||||||
|
if (!versionCheck.ok) {
|
||||||
|
sileo.error({
|
||||||
|
title: 'Version not publishable',
|
||||||
|
description: versionCheck.error,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (definition.version !== versionCheck.version) {
|
||||||
|
definition.version = versionCheck.version;
|
||||||
|
const saved = await saveTheme({ notify: false });
|
||||||
|
if (!saved) return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!savedFolder) {
|
||||||
|
const saved = await saveTheme({ notify: false });
|
||||||
|
if (!saved || !savedFolder) return;
|
||||||
|
}
|
||||||
|
|
||||||
|
publishStatusMessage = 'Packaging theme archive...';
|
||||||
const baseThemesDir = await themesDirectory();
|
const baseThemesDir = await themesDirectory();
|
||||||
const themeFolder = await path.join(baseThemesDir, savedFolder);
|
const themeFolder = await path.join(baseThemesDir, savedFolder);
|
||||||
const themeId = savedFolder || toSafeName(definition.name);
|
const themeId = savedFolder || toSafeName(definition.name);
|
||||||
@@ -3420,7 +3522,7 @@
|
|||||||
workshopId: definition.workshopId,
|
workshopId: definition.workshopId,
|
||||||
name: definition.name,
|
name: definition.name,
|
||||||
description: definition.description || '',
|
description: definition.description || '',
|
||||||
version: definition.version || '1.0.0',
|
version: versionCheck.version,
|
||||||
apiVersion: definition.apiVersion || '2.0.0',
|
apiVersion: definition.apiVersion || '2.0.0',
|
||||||
tags: definition.tags ?? [],
|
tags: definition.tags ?? [],
|
||||||
allowForking: definition.allowForking !== false,
|
allowForking: definition.allowForking !== false,
|
||||||
@@ -3430,6 +3532,8 @@
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
lastPublishedVersion = versionCheck.version;
|
||||||
|
|
||||||
if (result.themeId) {
|
if (result.themeId) {
|
||||||
// Persist the server-assigned ID so the next publish updates this
|
// Persist the server-assigned ID so the next publish updates this
|
||||||
// workshop record instead of creating another one.
|
// workshop record instead of creating another one.
|
||||||
@@ -6983,7 +7087,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<p class="text-[10px] leading-relaxed text-muted-foreground/70">
|
<p class="text-[10px] leading-relaxed text-muted-foreground/70">
|
||||||
These details come from the Theme tab. Change them there before publishing.
|
These details come from the Theme tab. Published versions cannot be reused, so increase
|
||||||
|
the version before every update.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -646,6 +646,8 @@ export type ThemeV2Definition = {
|
|||||||
version: string;
|
version: string;
|
||||||
apiVersion: '2.0';
|
apiVersion: '2.0';
|
||||||
author: string;
|
author: string;
|
||||||
|
/** EZPPFarm user ID of the publisher, written when the theme is published. */
|
||||||
|
authorId?: number;
|
||||||
description?: string;
|
description?: string;
|
||||||
/** Workshop discovery tags for this theme. */
|
/** Workshop discovery tags for this theme. */
|
||||||
tags?: string[];
|
tags?: string[];
|
||||||
@@ -746,6 +748,16 @@ export const normalizeThemeTags = (raw: unknown): string[] => {
|
|||||||
return tags;
|
return tags;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const THEME_VERSION_PATTERN =
|
||||||
|
/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*)?(?:\+[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*)?$/;
|
||||||
|
|
||||||
|
/** Accept only strict SemVer 2.0.0, preserving prerelease and build metadata. */
|
||||||
|
export const normalizeThemeVersion = (raw: unknown): string | undefined => {
|
||||||
|
if (typeof raw !== 'string') return undefined;
|
||||||
|
const version = raw.trim();
|
||||||
|
return version.length > 0 && THEME_VERSION_PATTERN.test(version) ? version : undefined;
|
||||||
|
};
|
||||||
|
|
||||||
const WORKSHOP_ID_PATTERN = /^[a-z0-9][a-z0-9_-]{0,63}$/;
|
const WORKSHOP_ID_PATTERN = /^[a-z0-9][a-z0-9_-]{0,63}$/;
|
||||||
|
|
||||||
/** Keep a server-assigned workshop ID while preserving legacy slug IDs. */
|
/** Keep a server-assigned workshop ID while preserving legacy slug IDs. */
|
||||||
@@ -755,6 +767,11 @@ const normalizeWorkshopId = (raw: unknown): string | undefined => {
|
|||||||
return WORKSHOP_ID_PATTERN.test(id) ? id : undefined;
|
return WORKSHOP_ID_PATTERN.test(id) ? id : undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const normalizeAuthorId = (raw: unknown): number | undefined => {
|
||||||
|
if (typeof raw !== 'number' || !Number.isSafeInteger(raw) || raw <= 0) return undefined;
|
||||||
|
return raw;
|
||||||
|
};
|
||||||
|
|
||||||
const clampInteger = (value: unknown, fallback: number, min: number, max: number) =>
|
const clampInteger = (value: unknown, fallback: number, min: number, max: number) =>
|
||||||
Math.round(clamp(value, fallback, min, max));
|
Math.round(clamp(value, fallback, min, max));
|
||||||
|
|
||||||
@@ -1913,6 +1930,7 @@ export const normalizeThemeV2 = (raw: Partial<ThemeV2Definition>): ThemeV2Defini
|
|||||||
version: text(raw.version, '1.0.0'),
|
version: text(raw.version, '1.0.0'),
|
||||||
apiVersion: '2.0',
|
apiVersion: '2.0',
|
||||||
author: text(raw.author, 'Unknown'),
|
author: text(raw.author, 'Unknown'),
|
||||||
|
authorId: normalizeAuthorId(raw.authorId),
|
||||||
description: text(raw.description),
|
description: text(raw.description),
|
||||||
tags: normalizeThemeTags(raw.tags),
|
tags: normalizeThemeTags(raw.tags),
|
||||||
workshopId: normalizeWorkshopId(raw.workshopId),
|
workshopId: normalizeWorkshopId(raw.workshopId),
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ export type Theme = {
|
|||||||
version: string;
|
version: string;
|
||||||
apiVersion: string;
|
apiVersion: string;
|
||||||
author: string;
|
author: string;
|
||||||
|
/** EZPPFarm user ID stored in the manifest when the theme is published. */
|
||||||
|
authorId?: number;
|
||||||
description: string;
|
description: string;
|
||||||
nsfw: boolean;
|
nsfw: boolean;
|
||||||
scriptUrl: string;
|
scriptUrl: string;
|
||||||
@@ -44,6 +46,7 @@ export type ThemeInfo = {
|
|||||||
apiVersion?: string;
|
apiVersion?: string;
|
||||||
workshopId?: string;
|
workshopId?: string;
|
||||||
author?: string;
|
author?: string;
|
||||||
|
authorId?: number;
|
||||||
description?: string;
|
description?: string;
|
||||||
nsfw?: boolean;
|
nsfw?: boolean;
|
||||||
entry?: string;
|
entry?: string;
|
||||||
@@ -173,6 +176,12 @@ const themeFromFolder = async (
|
|||||||
version: parsed.version ?? '1.0.0',
|
version: parsed.version ?? '1.0.0',
|
||||||
apiVersion,
|
apiVersion,
|
||||||
author: parsed.author ?? 'Unknown',
|
author: parsed.author ?? 'Unknown',
|
||||||
|
authorId:
|
||||||
|
typeof parsed.authorId === 'number' &&
|
||||||
|
Number.isSafeInteger(parsed.authorId) &&
|
||||||
|
parsed.authorId > 0
|
||||||
|
? parsed.authorId
|
||||||
|
: undefined,
|
||||||
description: parsed.description ?? '',
|
description: parsed.description ?? '',
|
||||||
nsfw: parsed.nsfw === true,
|
nsfw: parsed.nsfw === true,
|
||||||
scriptUrl,
|
scriptUrl,
|
||||||
@@ -523,6 +532,7 @@ export const reloadThemes = async () => {
|
|||||||
preview: theme.preview,
|
preview: theme.preview,
|
||||||
version: theme.version,
|
version: theme.version,
|
||||||
author: theme.author,
|
author: theme.author,
|
||||||
|
authorId: theme.authorId,
|
||||||
apiVersion: theme.apiVersion,
|
apiVersion: theme.apiVersion,
|
||||||
description: theme.description,
|
description: theme.description,
|
||||||
nsfw: theme.nsfw,
|
nsfw: theme.nsfw,
|
||||||
|
|||||||
+198
-103
@@ -163,6 +163,7 @@
|
|||||||
ChevronLeft,
|
ChevronLeft,
|
||||||
ChevronRight,
|
ChevronRight,
|
||||||
Clock,
|
Clock,
|
||||||
|
Ellipsis,
|
||||||
ExternalLink,
|
ExternalLink,
|
||||||
Flag,
|
Flag,
|
||||||
Globe,
|
Globe,
|
||||||
@@ -421,6 +422,14 @@
|
|||||||
return ownedWorkshopThemeNames.includes(theme.name.trim().toLowerCase());
|
return ownedWorkshopThemeNames.includes(theme.name.trim().toLowerCase());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const themeAuthorAvatarUrl = (theme: Theme) => {
|
||||||
|
if (theme.authorId && theme.authorId > 0) {
|
||||||
|
return `https://a.ez-pp.farm/${theme.authorId}`;
|
||||||
|
}
|
||||||
|
const author = theme.author.trim();
|
||||||
|
return author ? `https://a.ez-pp.farm/${encodeURIComponent(author)}` : undefined;
|
||||||
|
};
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
let loadedUserId: number | undefined;
|
let loadedUserId: number | undefined;
|
||||||
return currentUser.subscribe((user) => {
|
return currentUser.subscribe((user) => {
|
||||||
@@ -505,6 +514,29 @@
|
|||||||
await config.value<string>('theme').set(theme.name);
|
await config.value<string>('theme').set(theme.name);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const uninstallInstalledTheme = async (theme: Theme) => {
|
||||||
|
try {
|
||||||
|
const deleteResult = await deleteTheme(theme);
|
||||||
|
if (deleteResult) {
|
||||||
|
sileo.success({
|
||||||
|
title: 'Theme uninstalled',
|
||||||
|
description: `"${theme.name}" was removed from your library.`,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
sileo.error({
|
||||||
|
title: 'Could not uninstall theme',
|
||||||
|
description: 'The theme files could not be removed.',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
sileo.error({
|
||||||
|
title: 'Could not uninstall theme',
|
||||||
|
description: err instanceof Error ? err.message : String(err),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const updateInstalledTheme = async (theme: Theme) => {
|
const updateInstalledTheme = async (theme: Theme) => {
|
||||||
const wasActive = $active_custom_theme?.folder_name === theme.folder_name;
|
const wasActive = $active_custom_theme?.folder_name === theme.folder_name;
|
||||||
const updateResult = await downloadTheme(theme, true);
|
const updateResult = await downloadTheme(theme, true);
|
||||||
@@ -3911,6 +3943,28 @@
|
|||||||
{#each filteredThemes as theme, index (theme.folder_name)}
|
{#each filteredThemes as theme, index (theme.folder_name)}
|
||||||
{@const isActive =
|
{@const isActive =
|
||||||
$active_custom_theme?.folder_name === theme.folder_name}
|
$active_custom_theme?.folder_name === theme.folder_name}
|
||||||
|
{@const canEditTheme =
|
||||||
|
theme.status === 'installed' && Boolean(theme.definition)}
|
||||||
|
{@const canRestoreTheme =
|
||||||
|
theme.status === 'installed' && (theme.backups?.length ?? 0) > 0}
|
||||||
|
{@const canUpdateTheme =
|
||||||
|
theme.status === 'installed' && theme.updateAvailable}
|
||||||
|
{@const canReportTheme =
|
||||||
|
Boolean($currentUser && ownedWorkshopLoaded) &&
|
||||||
|
!isOwnInstalledTheme(theme) &&
|
||||||
|
theme.status === 'installed' &&
|
||||||
|
theme.name !== 'Default' &&
|
||||||
|
theme.folder_name !== 'default'}
|
||||||
|
{@const canUninstallTheme =
|
||||||
|
(theme.status === 'installed' || theme.status === 'deleting') &&
|
||||||
|
!isActive &&
|
||||||
|
theme.name !== 'Default'}
|
||||||
|
{@const hasThemeMenu =
|
||||||
|
canEditTheme ||
|
||||||
|
canRestoreTheme ||
|
||||||
|
canUpdateTheme ||
|
||||||
|
canReportTheme ||
|
||||||
|
canUninstallTheme}
|
||||||
<div
|
<div
|
||||||
class="group flex flex-col overflow-hidden rounded-xl border bg-theme-900/30 {isActive
|
class="group flex flex-col overflow-hidden rounded-xl border bg-theme-900/30 {isActive
|
||||||
? 'border-primary/60 ring-1 ring-primary/15'
|
? 'border-primary/60 ring-1 ring-primary/15'
|
||||||
@@ -3925,7 +3979,7 @@
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="relative h-36 w-full shrink-0 overflow-hidden bg-theme-950/60"
|
class="relative aspect-video w-full shrink-0 overflow-hidden bg-theme-950/60"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="h-full w-full {$reduceAnimations
|
class="h-full w-full {$reduceAnimations
|
||||||
@@ -3966,17 +4020,37 @@
|
|||||||
<div
|
<div
|
||||||
class="pointer-events-none absolute inset-0 bg-gradient-to-t from-theme-950/75 via-transparent to-transparent"
|
class="pointer-events-none absolute inset-0 bg-gradient-to-t from-theme-950/75 via-transparent to-transparent"
|
||||||
></div>
|
></div>
|
||||||
|
<div
|
||||||
|
class="absolute top-1.5 left-1.5 flex max-w-[calc(100%-4.5rem)] flex-wrap items-center gap-1"
|
||||||
|
>
|
||||||
{#if isActive}
|
{#if isActive}
|
||||||
<Badge class="absolute top-1.5 left-1.5 text-[9px]">In use</Badge>
|
<Badge class="text-[9px]">In use</Badge>
|
||||||
{/if}
|
{/if}
|
||||||
{#if theme.name !== 'Default' && theme.folder_name !== 'default' && theme.apiVersion}
|
{#if theme.name !== 'Default' && theme.folder_name !== 'default' && theme.apiVersion}
|
||||||
<Badge
|
<Badge
|
||||||
variant="secondary"
|
variant="secondary"
|
||||||
class="absolute top-1.5 right-1.5 bg-black/50 px-1.5 py-0 text-[9px] backdrop-blur-sm"
|
class="bg-black/50 px-1.5 py-0 text-[9px] backdrop-blur-sm"
|
||||||
>
|
>
|
||||||
API {theme.apiVersion.startsWith('2') ? '2.0' : '1.0'}
|
API {theme.apiVersion.startsWith('2') ? '2.0' : '1.0'}
|
||||||
</Badge>
|
</Badge>
|
||||||
{/if}
|
{/if}
|
||||||
|
</div>
|
||||||
|
<div class="absolute top-1.5 right-1.5 flex items-center gap-1">
|
||||||
|
{#if theme.nsfw}
|
||||||
|
<Badge
|
||||||
|
variant="destructive"
|
||||||
|
class="px-1.5 py-0 text-[9px]"
|
||||||
|
title="Adult content"
|
||||||
|
>
|
||||||
|
18+
|
||||||
|
</Badge>
|
||||||
|
{/if}
|
||||||
|
<span
|
||||||
|
class="rounded-md bg-black/60 px-1.5 py-0.5 text-[9px] font-medium text-white/90 backdrop-blur-sm"
|
||||||
|
>
|
||||||
|
v{theme.version}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
{#if theme.nsfw && !revealedNsfw.includes(theme.name)}
|
{#if theme.nsfw && !revealedNsfw.includes(theme.name)}
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
@@ -3992,58 +4066,74 @@
|
|||||||
{:else if theme.nsfw}
|
{:else if theme.nsfw}
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
class="absolute bottom-1.5 left-1.5 z-10 flex items-center gap-1 rounded-full bg-black/60 px-1.5 py-0.5 text-[8px] font-medium text-white/80 backdrop-blur-sm hover:bg-black/75 hover:text-white"
|
class="absolute right-1.5 bottom-10 z-10 flex items-center gap-1 rounded-full bg-black/60 px-1.5 py-0.5 text-[8px] font-medium text-white/80 backdrop-blur-sm hover:bg-black/75 hover:text-white"
|
||||||
onclick={() => toggleNsfwPreview(theme.name)}
|
onclick={() => toggleNsfwPreview(theme.name)}
|
||||||
>
|
>
|
||||||
<ThemeIcon name="eye-off" set={iconSet} class="size-3" />
|
<ThemeIcon name="eye-off" set={iconSet} class="size-3" />
|
||||||
Hide preview
|
Hide preview
|
||||||
</button>
|
</button>
|
||||||
{/if}
|
{/if}
|
||||||
{#if theme.nsfw}
|
<div
|
||||||
<Badge
|
class="absolute right-2 bottom-2 left-2 flex items-center justify-between gap-2"
|
||||||
variant="destructive"
|
|
||||||
class="absolute right-1.5 bottom-1.5 px-1.5 py-0 text-[9px]"
|
|
||||||
title="Adult content"
|
|
||||||
>
|
>
|
||||||
18+
|
<div class="flex min-w-0 items-center gap-1.5">
|
||||||
</Badge>
|
<Avatar.Root
|
||||||
{/if}
|
class="size-5 shrink-0 border border-white/20 bg-theme-800"
|
||||||
</div>
|
>
|
||||||
<div class="flex flex-1 flex-col gap-1.5 p-2.5">
|
<Avatar.Image
|
||||||
<div class="flex items-start justify-between gap-1.5">
|
src={themeAuthorAvatarUrl(theme)}
|
||||||
<div class="min-w-0">
|
alt={theme.author || 'Unknown author'}
|
||||||
|
class="object-cover"
|
||||||
|
/>
|
||||||
|
<Avatar.Fallback
|
||||||
|
class="text-[9px] font-bold text-white/80 uppercase"
|
||||||
|
>
|
||||||
|
{theme.author.trim().charAt(0) || '?'}
|
||||||
|
</Avatar.Fallback>
|
||||||
|
</Avatar.Root>
|
||||||
<span
|
<span
|
||||||
class="block truncate text-[13px] leading-tight font-semibold"
|
class="truncate text-[11px] font-semibold text-white/95 drop-shadow-sm"
|
||||||
>
|
>
|
||||||
|
{theme.author || 'Unknown author'}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<span
|
||||||
|
class="shrink-0 text-[9px] {theme.updateAvailable
|
||||||
|
? 'text-primary'
|
||||||
|
: 'text-muted-foreground/90'}"
|
||||||
|
>
|
||||||
|
{theme.updateAvailable ? 'Update available' : 'Installed'}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="flex flex-1 flex-col gap-2 p-3">
|
||||||
|
<h3 class="truncate text-[13px] font-bold text-theme-50">
|
||||||
{theme.name}
|
{theme.name}
|
||||||
</span>
|
</h3>
|
||||||
<span
|
|
||||||
class="mt-0.5 block truncate text-[10px] text-muted-foreground"
|
|
||||||
>
|
|
||||||
by {theme.author}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<span
|
|
||||||
class="shrink-0 rounded-full bg-theme-800/50 px-1.5 py-0.5 text-[9px] whitespace-nowrap tabular-nums text-muted-foreground"
|
|
||||||
>
|
|
||||||
{#if theme.updateAvailable && theme.availableVersion}
|
|
||||||
v{theme.version} <span class="text-primary">→</span>
|
|
||||||
v{theme.availableVersion}
|
|
||||||
{:else}
|
|
||||||
v{theme.version}
|
|
||||||
{/if}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
{#if theme.description}
|
{#if theme.description}
|
||||||
<p
|
<p
|
||||||
class="line-clamp-2 text-[10px] leading-snug text-muted-foreground"
|
class="line-clamp-2 text-[10px] leading-relaxed text-muted-foreground"
|
||||||
>
|
>
|
||||||
{theme.description}
|
{theme.description}
|
||||||
</p>
|
</p>
|
||||||
{/if}
|
{/if}
|
||||||
<div class="mt-auto flex items-center gap-1 pt-0.5">
|
<div
|
||||||
|
class="mt-auto flex items-center justify-between gap-2 border-t border-theme-800/40 pt-2.5"
|
||||||
|
>
|
||||||
|
<span class="min-w-0 truncate text-[9px] text-muted-foreground">
|
||||||
|
{#if theme.updateAvailable && theme.availableVersion}
|
||||||
|
<span class="text-primary"
|
||||||
|
>v{theme.availableVersion} available</span
|
||||||
|
>
|
||||||
|
{:else if isActive}
|
||||||
|
Active theme
|
||||||
|
{:else}
|
||||||
|
Installed
|
||||||
|
{/if}
|
||||||
|
</span>
|
||||||
|
<div class="flex shrink-0 items-center gap-1">
|
||||||
<Button
|
<Button
|
||||||
class="relative h-8 min-w-0 flex-1 overflow-hidden px-2 text-xs {theme.status ===
|
class="relative h-7 min-w-0 max-w-44 overflow-hidden px-2.5 text-xs {theme.status ===
|
||||||
'downloading' || theme.status === 'extracting'
|
'downloading' || theme.status === 'extracting'
|
||||||
? 'disabled:bg-primary disabled:opacity-100'
|
? 'disabled:bg-primary disabled:opacity-100'
|
||||||
: ''}"
|
: ''}"
|
||||||
@@ -4089,70 +4179,78 @@
|
|||||||
/>
|
/>
|
||||||
</span>
|
</span>
|
||||||
</Button>
|
</Button>
|
||||||
{#if theme.status === 'installed' && theme.definition}
|
{#if hasThemeMenu}
|
||||||
|
<DropdownMenu.Root>
|
||||||
|
<DropdownMenu.Trigger>
|
||||||
|
{#snippet child({ props })}
|
||||||
<Button
|
<Button
|
||||||
|
{...props}
|
||||||
variant="secondary"
|
variant="secondary"
|
||||||
size="icon"
|
size="icon"
|
||||||
class="size-7 shrink-0"
|
class="size-7 shrink-0 text-muted-foreground hover:text-white"
|
||||||
title="Edit theme"
|
title="More theme actions"
|
||||||
|
aria-label={`More actions for ${theme.name}`}
|
||||||
|
>
|
||||||
|
<Ellipsis class="size-3.5" />
|
||||||
|
</Button>
|
||||||
|
{/snippet}
|
||||||
|
</DropdownMenu.Trigger>
|
||||||
|
<DropdownMenu.Content
|
||||||
|
align="end"
|
||||||
|
class="w-48 border-theme-700 bg-theme-950 text-theme-50"
|
||||||
|
>
|
||||||
|
{#if canEditTheme}
|
||||||
|
<DropdownMenu.Item
|
||||||
|
class="gap-2 text-[11px]"
|
||||||
onclick={() => openThemeEditor(theme)}
|
onclick={() => openThemeEditor(theme)}
|
||||||
>
|
>
|
||||||
<ThemeIcon name="edit" set={iconSet} class="size-3.5" />
|
<ThemeIcon name="edit" set={iconSet} class="size-3.5" />
|
||||||
</Button>
|
Edit theme
|
||||||
|
</DropdownMenu.Item>
|
||||||
{/if}
|
{/if}
|
||||||
{#if theme.status === 'installed' && (theme.backups?.length ?? 0) > 0}
|
{#if canRestoreTheme}
|
||||||
<Button
|
<DropdownMenu.Item
|
||||||
variant="secondary"
|
class="gap-2 text-[11px]"
|
||||||
size="icon"
|
onclick={() =>
|
||||||
class="size-7 shrink-0"
|
requestThemeRestore(theme, theme.backups![0])}
|
||||||
title="Restore previous version ({new Date(
|
|
||||||
theme.backups![0].createdAt
|
|
||||||
).toLocaleDateString()})"
|
|
||||||
onclick={() => requestThemeRestore(theme, theme.backups![0])}
|
|
||||||
>
|
>
|
||||||
<ThemeIcon name="history" set={iconSet} class="size-3.5" />
|
<ThemeIcon
|
||||||
</Button>
|
name="history"
|
||||||
|
set={iconSet}
|
||||||
|
class="size-3.5"
|
||||||
|
/>
|
||||||
|
Restore previous version
|
||||||
|
</DropdownMenu.Item>
|
||||||
{/if}
|
{/if}
|
||||||
{#if theme.status === 'installed' && theme.updateAvailable}
|
{#if canUpdateTheme}
|
||||||
<Button
|
<DropdownMenu.Item
|
||||||
variant="secondary"
|
class="gap-2 text-[11px]"
|
||||||
size="icon"
|
|
||||||
class="size-7 shrink-0"
|
|
||||||
title={`Update theme${theme.availableVersion ? ` to v${theme.availableVersion}` : ''}`}
|
|
||||||
onclick={() => updateInstalledTheme(theme)}
|
onclick={() => updateInstalledTheme(theme)}
|
||||||
>
|
>
|
||||||
<ThemeIcon name="download" set={iconSet} class="size-3.5" />
|
<ThemeIcon
|
||||||
</Button>
|
name="download"
|
||||||
|
set={iconSet}
|
||||||
|
class="size-3.5"
|
||||||
|
/>
|
||||||
|
Update theme
|
||||||
|
</DropdownMenu.Item>
|
||||||
{/if}
|
{/if}
|
||||||
{#if (theme.status === 'installed' || theme.status === 'deleting') && !isActive && theme.name !== 'Default'}
|
{#if canReportTheme}
|
||||||
<Button
|
<DropdownMenu.Item
|
||||||
variant="destructive"
|
class="gap-2 text-[11px]"
|
||||||
size="icon"
|
disabled={installedReportLoading}
|
||||||
class="size-7 shrink-0"
|
onclick={() => void openInstalledReport(theme)}
|
||||||
title="Uninstall theme"
|
>
|
||||||
|
<Flag class="size-3.5" />
|
||||||
|
Report theme
|
||||||
|
</DropdownMenu.Item>
|
||||||
|
{/if}
|
||||||
|
{#if canUninstallTheme}
|
||||||
|
<DropdownMenu.Separator class="my-1 bg-theme-800" />
|
||||||
|
<DropdownMenu.Item
|
||||||
|
class="gap-2 text-[11px] text-red-300 data-[highlighted]:bg-red-500/15 data-[highlighted]:text-red-200"
|
||||||
disabled={theme.status !== 'installed'}
|
disabled={theme.status !== 'installed'}
|
||||||
onclick={async () => {
|
onclick={() => void uninstallInstalledTheme(theme)}
|
||||||
try {
|
|
||||||
const deleteResult = await deleteTheme(theme);
|
|
||||||
if (deleteResult) {
|
|
||||||
sileo.success({
|
|
||||||
title: 'Yaay!',
|
|
||||||
description: 'Theme uninstalled successfully!',
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
sileo.error({
|
|
||||||
title: 'Uhhm..',
|
|
||||||
description: 'Failed to uninstall theme.',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
console.log(err);
|
|
||||||
sileo.error({
|
|
||||||
title: 'Uhhm..',
|
|
||||||
description: 'Failed to uninstall theme.',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
{#if theme.status === 'deleting'}
|
{#if theme.status === 'deleting'}
|
||||||
<ThemeIcon
|
<ThemeIcon
|
||||||
@@ -4160,27 +4258,24 @@
|
|||||||
set={iconSet}
|
set={iconSet}
|
||||||
class="size-3.5 animate-spin"
|
class="size-3.5 animate-spin"
|
||||||
/>
|
/>
|
||||||
|
Uninstalling...
|
||||||
{:else}
|
{:else}
|
||||||
<ThemeIcon name="trash" set={iconSet} class="size-3.5" />
|
<ThemeIcon
|
||||||
|
name="trash"
|
||||||
|
set={iconSet}
|
||||||
|
class="size-3.5"
|
||||||
|
/>
|
||||||
|
Uninstall theme
|
||||||
{/if}
|
{/if}
|
||||||
</Button>
|
</DropdownMenu.Item>
|
||||||
{/if}
|
{/if}
|
||||||
{#if $currentUser && ownedWorkshopLoaded && !isOwnInstalledTheme(theme) && theme.status === 'installed' && theme.name !== 'Default' && theme.folder_name !== 'default'}
|
</DropdownMenu.Content>
|
||||||
<Button
|
</DropdownMenu.Root>
|
||||||
variant="secondary"
|
|
||||||
size="icon"
|
|
||||||
class="size-7 shrink-0 text-muted-foreground hover:bg-amber-500/15 hover:text-amber-300"
|
|
||||||
title="Report theme"
|
|
||||||
aria-label={`Report ${theme.name}`}
|
|
||||||
disabled={installedReportLoading}
|
|
||||||
onclick={() => void openInstalledReport(theme)}
|
|
||||||
>
|
|
||||||
<Flag class="size-3.5" />
|
|
||||||
</Button>
|
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
{/key}
|
{/key}
|
||||||
|
|||||||
Reference in new issue
Block a user