Skip to content

Commit

Permalink
Fix Ignore any third-party theme that uses "default" as ID (fix asepr…
Browse files Browse the repository at this point in the history
…ite#4226)

This fix hides user themes whose name is the same as the default,
that is, "aseprite-theme" and are present in the user folders (i.e.
'extensions' and 'data/themes' folders).
  • Loading branch information
Gasparoken committed Apr 10, 2024
1 parent 571a396 commit 5d49a03
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
31 changes: 30 additions & 1 deletion src/app/commands/cmd_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1382,7 +1382,8 @@ class OptionsWindow : public app::gen::Options {
if (!ext->isEnabled())
continue;

if (ext->themes().empty())
if (ext->themes().empty() ||
isExtensionADuplicatedDefaultTheme(ext))
continue;

if (first) {
Expand Down Expand Up @@ -1414,6 +1415,9 @@ class OptionsWindow : public app::gen::Options {
extensionsList()->addChild(sep);
for (auto e : App::instance()->extensions()) {
if (e->category() == category) {
if (category == Extension::Category::Themes &&
isExtensionADuplicatedDefaultTheme(e))
continue;
ExtensionItem* item = new ExtensionItem(e);
extensionsList()->addChild(item);
hasItems = true;
Expand Down Expand Up @@ -1756,6 +1760,17 @@ class OptionsWindow : public app::gen::Options {
return paths;
}

static base::paths createUserDirPaths(const base::paths dirNames) {
ResourceFinder rf;
for (auto& fn : dirNames)
rf.includeUserDir(fn.c_str());

base::paths paths;
while (rf.next())
paths.push_back(base::normalize_path(rf.filename()));
return paths;
}

void updateCategoryVisibility() {
bool visibleCategories[int(Extension::Category::Max)];
for (auto& v : visibleCategories)
Expand All @@ -1771,6 +1786,20 @@ class OptionsWindow : public app::gen::Options {
}
}

// Function to determine if the input extension is the default theme
static bool isExtensionADuplicatedDefaultTheme(const Extension* e) {
if (!e->isDefaultTheme())
return false;
auto userThemePaths =
createUserDirPaths({"extensions", skin::SkinTheme::kThemesFolderName});
for (auto& p : userThemePaths) {
// Has the user path (p) the same path of the extension (e->path())?
if (std::strncmp(e->path().c_str(), p.c_str(), p.size()) == 0)
return true;
}
return false;
}

#ifdef _WIN32
void onTabletAPIChange() {
if (tabletApiWindowsPointer()->isSelected()) {
Expand Down
5 changes: 3 additions & 2 deletions src/app/extensions.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2020-2023 Igara Studio S.A.
// Copyright (C) 2020-2024 Igara Studio S.A.
// Copyright (C) 2017-2018 David Capello
//
// This program is distributed under the terms of
Expand Down Expand Up @@ -54,6 +54,8 @@ namespace app {
Max
};

bool isDefaultTheme() const;

class DitheringMatrixInfo {
public:
DitheringMatrixInfo();
Expand Down Expand Up @@ -150,7 +152,6 @@ namespace app {
void uninstall(const DeletePluginPref delPref);
void uninstallFiles(const std::string& path,
const DeletePluginPref delPref);
bool isDefaultTheme() const;
void updateCategory(const Category newCategory);
#ifdef ENABLE_SCRIPTING
void initScripts();
Expand Down

0 comments on commit 5d49a03

Please sign in to comment.