mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-31 06:41:03 +00:00
feat: using theme name for folder instead themeid
This commit is contained in:
@@ -38,23 +38,56 @@ export const normalizePath = (str: string) =>
|
||||
export const addTrailingSlash = (str: string) =>
|
||||
str.endsWith("/") ? str : `${str}/`;
|
||||
|
||||
export const getThemePath = (themeId: string) =>
|
||||
path.join(THEMES_PATH, themeId);
|
||||
const sanitizeFolderName = (name: string): string => {
|
||||
return name
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9-_\s]/g, "")
|
||||
.replace(/\s+/g, "-")
|
||||
.replace(/-+/g, "-")
|
||||
.replace(/^-|-$/g, "");
|
||||
};
|
||||
|
||||
export const getThemeSoundPath = (themeId: string): string | null => {
|
||||
const themeDir = getThemePath(themeId);
|
||||
export const getThemePath = (themeId: string, themeName?: string): string => {
|
||||
if (themeName) {
|
||||
const sanitizedName = sanitizeFolderName(themeName);
|
||||
if (sanitizedName) {
|
||||
return path.join(THEMES_PATH, sanitizedName);
|
||||
}
|
||||
}
|
||||
return path.join(THEMES_PATH, themeId);
|
||||
};
|
||||
|
||||
export const getThemeSoundPath = (
|
||||
themeId: string,
|
||||
themeName?: string
|
||||
): string | null => {
|
||||
const themeDir = getThemePath(themeId, themeName);
|
||||
const legacyThemeDir = themeName ? path.join(THEMES_PATH, themeId) : null;
|
||||
|
||||
const checkDir = (dir: string): string | null => {
|
||||
if (!fs.existsSync(dir)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const formats = ["wav", "mp3", "ogg", "m4a"];
|
||||
|
||||
for (const format of formats) {
|
||||
const soundPath = path.join(dir, `achievement.${format}`);
|
||||
if (fs.existsSync(soundPath)) {
|
||||
return soundPath;
|
||||
}
|
||||
}
|
||||
|
||||
if (!fs.existsSync(themeDir)) {
|
||||
return null;
|
||||
};
|
||||
|
||||
const soundPath = checkDir(themeDir);
|
||||
if (soundPath) {
|
||||
return soundPath;
|
||||
}
|
||||
|
||||
const formats = ["wav", "mp3", "ogg", "m4a"];
|
||||
|
||||
for (const format of formats) {
|
||||
const soundPath = path.join(themeDir, `achievement.${format}`);
|
||||
if (fs.existsSync(soundPath)) {
|
||||
return soundPath;
|
||||
}
|
||||
if (legacyThemeDir) {
|
||||
return checkDir(legacyThemeDir);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user