chore: use folder name as identification

This commit is contained in:
2026-05-03 15:24:31 +02:00
parent eaf6f5976d
commit 56608a64fc
2 changed files with 22 additions and 8 deletions
+15 -1
View File
@@ -8,6 +8,7 @@ import zip from 'jszip';
import { SemVer } from 'semver'; import { SemVer } from 'semver';
export type Theme = { export type Theme = {
folder_name: string;
name: string; name: string;
version: string; version: string;
author: string; author: string;
@@ -40,6 +41,7 @@ export const getDownloadableThemes = async () => {
if (downloadableThemes.data) { if (downloadableThemes.data) {
for (const theme of downloadableThemes.data) { for (const theme of downloadableThemes.data) {
themes.push({ themes.push({
folder_name: `${toSafeName(theme.name)}-${generateRandomString(16)}`,
name: theme.name, name: theme.name,
version: theme.version, version: theme.version,
author: theme.author, author: theme.author,
@@ -61,6 +63,7 @@ export const getDownloadableThemes = async () => {
export const getThemes = async (): Promise<Theme[]> => { export const getThemes = async (): Promise<Theme[]> => {
const themes: Theme[] = []; const themes: Theme[] = [];
themes.push({ themes.push({
folder_name: 'default',
author: 'EZPPFarm', author: 'EZPPFarm',
name: 'Default', name: 'Default',
version: '1.0.0', version: '1.0.0',
@@ -91,6 +94,7 @@ export const getThemes = async (): Promise<Theme[]> => {
const scriptFile = await path.join(folderPath, themeFolder.name, theme.entry); const scriptFile = await path.join(folderPath, themeFolder.name, theme.entry);
if (await fs.exists(scriptFile)) { if (await fs.exists(scriptFile)) {
themes.push({ themes.push({
folder_name: themeFolder.name,
name: theme.name, name: theme.name,
version: theme.version, version: theme.version,
author: theme.author, author: theme.author,
@@ -284,7 +288,7 @@ export const deleteTheme = async (themeToUninstall: Theme) => {
if (themeToUninstall.status !== 'installed') return false; if (themeToUninstall.status !== 'installed') return false;
const baseThemeFolder = await path.join(await path.homeDir(), '.ezpplauncher', 'themes'); const baseThemeFolder = await path.join(await path.homeDir(), '.ezpplauncher', 'themes');
if (!(await fs.exists(baseThemeFolder))) return false; if (!(await fs.exists(baseThemeFolder))) return false;
const themeFolder = await path.join(baseThemeFolder, toSafeName(themeToUninstall.name)); const themeFolder = await path.join(baseThemeFolder, themeToUninstall.folder_name);
if (!(await fs.exists(themeFolder))) return false; if (!(await fs.exists(themeFolder))) return false;
await fs.remove(themeFolder, { recursive: true }); await fs.remove(themeFolder, { recursive: true });
const downloadableThemes = await getDownloadableThemes(); const downloadableThemes = await getDownloadableThemes();
@@ -293,9 +297,11 @@ export const deleteTheme = async (themeToUninstall: Theme) => {
for (const theme of downloadableThemes) { for (const theme of downloadableThemes) {
if (theme.name === themeToUninstall.name) { if (theme.name === themeToUninstall.name) {
const themeIndex = reloadedThemes.findIndex((t) => t.name === theme.name); const themeIndex = reloadedThemes.findIndex((t) => t.name === theme.name);
if (themeIndex) {
reloadedThemes.splice(themeIndex, 1); reloadedThemes.splice(themeIndex, 1);
reloadedThemes.push(theme); reloadedThemes.push(theme);
} }
}
const installedTheme = reloadedThemes.find((t) => t.name === theme.name); const installedTheme = reloadedThemes.find((t) => t.name === theme.name);
if (installedTheme) { if (installedTheme) {
@@ -308,6 +314,7 @@ export const deleteTheme = async (themeToUninstall: Theme) => {
} }
} }
} }
return reloadedThemes.sort((a, b) => { return reloadedThemes.sort((a, b) => {
if (a.name === 'Default') return -1; if (a.name === 'Default') return -1;
if (b.name === 'Default') return 1; if (b.name === 'Default') return 1;
@@ -331,3 +338,10 @@ export const toSafeName = (name: string) => {
.replace(/[. ]+$/g, '_') .replace(/[. ]+$/g, '_')
); );
}; };
const generateRandomString = (length: number) => {
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
return Array.from({ length }, () =>
characters.charAt(Math.floor(Math.random() * characters.length))
).join('');
};
+5 -5
View File
@@ -1535,10 +1535,10 @@
> >
<ScrollContainer class="pt-8" topOffset={45}> <ScrollContainer class="pt-8" topOffset={45}>
<div class="grid w-full gap-1 grid-cols-3 p-3 pr-5"> <div class="grid w-full gap-1 grid-cols-3 p-3 pr-5">
{#each $custom_themes as theme (theme.name)} {#each $custom_themes as theme (theme.folder_name)}
<div <div
class="group overflow-hidden rounded-3xl border {$active_custom_theme && class="group overflow-hidden rounded-3xl border {$active_custom_theme &&
$active_custom_theme.name === theme.name $active_custom_theme.folder_name === theme.folder_name
? 'border-primary' ? 'border-primary'
: 'border-theme-800'} bg-theme-950 transition hover:border-white/20 h-[295px]" : 'border-theme-800'} bg-theme-950 transition hover:border-white/20 h-[295px]"
> >
@@ -1559,7 +1559,7 @@
<Button <Button
class="w-full" class="w-full"
disabled={($active_custom_theme && disabled={($active_custom_theme &&
$active_custom_theme.name === theme.name) || $active_custom_theme.folder_name === theme.folder_name) ||
theme.status === 'downloading' || theme.status === 'downloading' ||
theme.status === 'extracting'} theme.status === 'extracting'}
onclick={async () => { onclick={async () => {
@@ -1584,7 +1584,7 @@
} }
}} }}
> >
{#if $active_custom_theme && $active_custom_theme.name === theme.name} {#if $active_custom_theme && $active_custom_theme.folder_name === theme.folder_name}
Theme in use Theme in use
{:else if theme.status !== 'installed'} {:else if theme.status !== 'installed'}
{#if theme.status === 'downloading'} {#if theme.status === 'downloading'}
@@ -1624,7 +1624,7 @@
<CloudDownload /> <CloudDownload />
</Button> </Button>
{/if} {/if}
{#if theme.status === 'installed' && $active_custom_theme && $active_custom_theme.name !== theme.name && theme.name !== 'Default'} {#if theme.status === 'installed' && $active_custom_theme && $active_custom_theme.folder_name !== theme.folder_name && theme.name !== 'Default'}
<Button <Button
class="min-w-[40px]" class="min-w-[40px]"
size="icon" size="icon"