Skip to content

Commit

Permalink
Fix Ignore any third-party theme that uses "default" as ID (fix #4226)
Browse files Browse the repository at this point in the history
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 Mar 1, 2024
1 parent 73fe809 commit 7111683
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
26 changes: 22 additions & 4 deletions src/app/commands/cmd_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1336,7 +1336,7 @@ class OptionsWindow : public app::gen::Options {

auto theme = skin::SkinTheme::get(this);
auto userFolder = userThemeFolder();
auto folders = themeFolders();
auto folders = themeFolders({skin::SkinTheme::kThemesFolderName});
std::sort(folders.begin(), folders.end());
const auto& selectedPath = theme->path();

Expand Down Expand Up @@ -1377,7 +1377,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 @@ -1409,6 +1410,8 @@ class OptionsWindow : public app::gen::Options {
extensionsList()->addChild(sep);
for (auto e : App::instance()->extensions()) {
if (e->category() == category) {
if (isExtensionADuplicatedDefaultTheme(e))
continue;
ExtensionItem* item = new ExtensionItem(e);
extensionsList()->addChild(item);
hasItems = true;
Expand Down Expand Up @@ -1741,9 +1744,10 @@ class OptionsWindow : public app::gen::Options {
return base::normalize_path(rf.defaultFilename());
}

static base::paths themeFolders() {
static base::paths themeFolders(const std::vector<std::string> filenames) {
ResourceFinder rf;
rf.includeDataDir(skin::SkinTheme::kThemesFolderName);
for (auto& fn : filenames)
rf.includeUserDir(fn.c_str());

base::paths paths;
while (rf.next())
Expand All @@ -1766,6 +1770,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 =
themeFolders({"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 7111683

Please sign in to comment.