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
+17 -3
View File
@@ -8,6 +8,7 @@ import zip from 'jszip';
import { SemVer } from 'semver';
export type Theme = {
folder_name: string;
name: string;
version: string;
author: string;
@@ -40,6 +41,7 @@ export const getDownloadableThemes = async () => {
if (downloadableThemes.data) {
for (const theme of downloadableThemes.data) {
themes.push({
folder_name: `${toSafeName(theme.name)}-${generateRandomString(16)}`,
name: theme.name,
version: theme.version,
author: theme.author,
@@ -61,6 +63,7 @@ export const getDownloadableThemes = async () => {
export const getThemes = async (): Promise<Theme[]> => {
const themes: Theme[] = [];
themes.push({
folder_name: 'default',
author: 'EZPPFarm',
name: 'Default',
version: '1.0.0',
@@ -91,6 +94,7 @@ export const getThemes = async (): Promise<Theme[]> => {
const scriptFile = await path.join(folderPath, themeFolder.name, theme.entry);
if (await fs.exists(scriptFile)) {
themes.push({
folder_name: themeFolder.name,
name: theme.name,
version: theme.version,
author: theme.author,
@@ -284,7 +288,7 @@ export const deleteTheme = async (themeToUninstall: Theme) => {
if (themeToUninstall.status !== 'installed') return false;
const baseThemeFolder = await path.join(await path.homeDir(), '.ezpplauncher', 'themes');
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;
await fs.remove(themeFolder, { recursive: true });
const downloadableThemes = await getDownloadableThemes();
@@ -293,8 +297,10 @@ export const deleteTheme = async (themeToUninstall: Theme) => {
for (const theme of downloadableThemes) {
if (theme.name === themeToUninstall.name) {
const themeIndex = reloadedThemes.findIndex((t) => t.name === theme.name);
reloadedThemes.splice(themeIndex, 1);
reloadedThemes.push(theme);
if (themeIndex) {
reloadedThemes.splice(themeIndex, 1);
reloadedThemes.push(theme);
}
}
const installedTheme = reloadedThemes.find((t) => t.name === theme.name);
@@ -308,6 +314,7 @@ export const deleteTheme = async (themeToUninstall: Theme) => {
}
}
}
return reloadedThemes.sort((a, b) => {
if (a.name === 'Default') return -1;
if (b.name === 'Default') return 1;
@@ -331,3 +338,10 @@ export const toSafeName = (name: string) => {
.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}>
<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
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-theme-800'} bg-theme-950 transition hover:border-white/20 h-[295px]"
>
@@ -1559,7 +1559,7 @@
<Button
class="w-full"
disabled={($active_custom_theme &&
$active_custom_theme.name === theme.name) ||
$active_custom_theme.folder_name === theme.folder_name) ||
theme.status === 'downloading' ||
theme.status === 'extracting'}
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
{:else if theme.status !== 'installed'}
{#if theme.status === 'downloading'}
@@ -1624,7 +1624,7 @@
<CloudDownload />
</Button>
{/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
class="min-w-[40px]"
size="icon"