Skip to content

Commit

Permalink
Track Steam's favorite/hidden state by default
Browse files Browse the repository at this point in the history
  • Loading branch information
Aemony committed Feb 5, 2024
1 parent a892074 commit 29f3d84
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 48 deletions.
26 changes: 13 additions & 13 deletions include/stores/Steam/app_record.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,19 +217,6 @@ struct app_record_s {
AppType type = AppType::Unknown; // Steam
};

// Struct used to hold custom SKIF metadata about the game
struct custom_metadata_s {
std::string name;
int cpu_type = 0; // 0 = Common, 1 = x86, 2 = x64, 0xFFFF = Any
int instant_play = 0; // 0 = use global default, 1 = always instant play, 2 = never instant play
int auto_stop = 0; // 0 = use global default, 1 = stop on injection, 2 = stop on game exit, 3 = never stop
int uses = 0; // Number of times game has been launched
std::string used = ""; // Unix timestamp (in string) of when the game was last used
std::string used_formatted = ""; // Friendly human-readable representation of the Unix timestamp
int hidden = 0; // Visibility
int pinned = 0; // Is app pinned? (0 = no; 1 = yes; 99 = Special K)
} skif;

struct extended_config_s {
struct vac_config_s {
uint32_t vacmacmodulecache = 0;
Expand Down Expand Up @@ -420,6 +407,19 @@ struct app_record_s {
std::string ImGuiPushID = "";
std::string ImGuiLabelAndID = "";

// Struct used to hold custom SKIF metadata about the game
struct custom_metadata_s {
std::string name;
int cpu_type = 0; // 0 = Common, 1 = x86, 2 = x64, 0xFFFF = Any
int instant_play = 0; // 0 = use global default, 1 = always instant play, 2 = never instant play
int auto_stop = 0; // 0 = use global default, 1 = stop on injection, 2 = stop on game exit, 3 = never stop
int uses = 0; // Number of times game has been launched
std::string used = ""; // Unix timestamp (in string) of when the game was last used
std::string used_formatted = ""; // Friendly human-readable representation of the Unix timestamp
int hidden = -1; // Is app hidden? (-1 = unset; 0 = no; 1 = yes)
int pinned = -1; // Is app pinned? (-1 = unset; 0 = no; 1 = yes; 99 = Special K)
} skif;

struct {
struct {
std::string launch_option = ""; // Holds the custom launch option set in the Steam client
Expand Down
62 changes: 29 additions & 33 deletions src/tabs/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1772,15 +1772,15 @@ DrawGameContextMenu (app_record_s* pApp)

ImGui::ItemSize (ImVec2 (ImGui::CalcTextSize (ICON_FA_GEAR).x, ImGui::GetTextLineHeight()));

ImGui::ItemSize (ImVec2 (ImGui::CalcTextSize ((pApp->skif.pinned > 0) ? ICON_FA_HEART_CRACK : ICON_FA_HEART).x, ImGui::GetTextLineHeight()));
ImGui::ItemSize (ImVec2 (ImGui::CalcTextSize ((pApp->skif.pinned > 0 || (pApp->skif.pinned == -1 && pApp->steam.shared.favorite == 1)) ? ICON_FA_HEART_CRACK : ICON_FA_HEART).x, ImGui::GetTextLineHeight()));

//if (pApp->store == app_record_s::Store::Steam || desktopShortcutPossible || pApp->store == app_record_s::Store::Custom)
ImGui::Separator ( );

if (desktopShortcutPossible)
ImGui::ItemSize (ImVec2 (ImGui::CalcTextSize (ICON_FA_PAPERCLIP).x, ImGui::GetTextLineHeight()));

ImGui::ItemSize (ImVec2 (ImGui::CalcTextSize ((pApp->skif.hidden == 1) ? ICON_FA_EYE : ICON_FA_EYE_SLASH).x, ImGui::GetTextLineHeight()));
ImGui::ItemSize (ImVec2 (ImGui::CalcTextSize ((pApp->skif.hidden == 1 || (pApp->skif.hidden == -1 && pApp->steam.shared.hidden == 1)) ? ICON_FA_EYE : ICON_FA_EYE_SLASH).x, ImGui::GetTextLineHeight()));

if (pApp->store == app_record_s::Store::Custom)
ImGui::ItemSize (ImVec2 (ImGui::CalcTextSize (ICON_FA_TRASH).x, ImGui::GetTextLineHeight()));
Expand All @@ -1795,9 +1795,9 @@ DrawGameContextMenu (app_record_s* pApp)
constexpr char* labelPin = "Favorite";
constexpr char* labelUnpin = "Unfavorite";

if (ImGui::Selectable ((pApp->skif.pinned > 0) ? labelUnpin : labelPin, false, ImGuiSelectableFlags_SpanAllColumns))
if (ImGui::Selectable ((pApp->skif.pinned > 0 || (pApp->skif.pinned == -1 && pApp->steam.shared.favorite == 1)) ? labelUnpin : labelPin, false, ImGuiSelectableFlags_SpanAllColumns))
{
pApp->skif.pinned = (pApp->skif.pinned > 0) ? 0 : 1;
pApp->skif.pinned = (pApp->skif.pinned > 0 || (pApp->skif.pinned == -1 && pApp->steam.shared.favorite == 1)) ? 0 : 1;

UpdateJsonMetaData ( pApp, true);

Expand Down Expand Up @@ -1845,9 +1845,9 @@ DrawGameContextMenu (app_record_s* pApp)
constexpr char* labelHide = "Hide";
constexpr char* labelUnhide = "Unhide";

if (ImGui::Selectable ((pApp->skif.hidden == 1) ? labelUnhide : labelHide, false, ImGuiSelectableFlags_SpanAllColumns))
if (ImGui::Selectable ((pApp->skif.hidden == 1 || (pApp->skif.hidden == -1 && pApp->steam.shared.hidden == 1)) ? labelUnhide : labelHide, false, ImGuiSelectableFlags_SpanAllColumns))
{
pApp->skif.hidden = (pApp->skif.hidden == 1) ? 0 : 1;
pApp->skif.hidden = (pApp->skif.hidden == 1 || (pApp->skif.hidden == -1 && pApp->steam.shared.hidden == 1)) ? 0 : 1;

UpdateJsonMetaData ( pApp, true);

Expand All @@ -1871,7 +1871,7 @@ DrawGameContextMenu (app_record_s* pApp)

ImGui::TextColored (
ImColor (245, 66, 66, 255),
(pApp->skif.pinned > 0) ? ICON_FA_HEART_CRACK : ICON_FA_HEART
(pApp->skif.pinned > 0 || (pApp->skif.pinned == -1 && pApp->steam.shared.favorite == 1)) ? ICON_FA_HEART_CRACK : ICON_FA_HEART
);

//if (pApp->store == app_record_s::Store::Steam || desktopShortcutPossible || pApp->store == app_record_s::Store::Custom)
Expand All @@ -1885,7 +1885,7 @@ DrawGameContextMenu (app_record_s* pApp)

ImGui::TextColored (
ImColor (200, 200, 200, 255),
(pApp->skif.hidden == 1) ? ICON_FA_EYE : ICON_FA_EYE_SLASH
(pApp->skif.hidden == 1 || (pApp->skif.hidden == -1 && pApp->steam.shared.hidden == 1)) ? ICON_FA_EYE : ICON_FA_EYE_SLASH
);

if (pApp->store == app_record_s::Store::Custom)
Expand Down Expand Up @@ -2109,21 +2109,17 @@ DrawGameContextMenu (app_record_s* pApp)
SKIF_Util_SetClipboardData (SK_UTF8ToWideChar(pApp->skif.name));
}

if (pApp->skif.cpu_type != 0)
{
if (ImGui::MenuItem ("CPU Architecture", std::to_string (pApp->skif.cpu_type).c_str()))
SKIF_Util_SetClipboardData ( std::to_wstring(pApp->skif.cpu_type));
}

if (ImGui::MenuItem ("Visibility", (pApp->skif.hidden) ? "Hidden" : "Visible"))
SKIF_Util_SetClipboardData ( (pApp->skif.hidden) ? L"Hidden" : L"Visible");
if (ImGui::MenuItem ("Uses", std::to_string (pApp->skif.uses).c_str()))
SKIF_Util_SetClipboardData ( std::to_wstring(pApp->skif.uses));
SKIF_ImGui_SetHoverTip ("The number of times this game has been launched.");
if (ImGui::MenuItem ("Last Used", pApp->skif.used_formatted.c_str()))
SKIF_Util_SetClipboardData ( SK_UTF8ToWideChar(pApp->skif.used));
if (ImGui::MenuItem ("Favorited", std::to_string (pApp->skif.pinned).c_str()))
SKIF_Util_SetClipboardData ( std::to_wstring(pApp->skif.pinned));
if (ImGui::MenuItem ("CPU Architecture", std::to_string (pApp->skif.cpu_type).c_str()))
SKIF_Util_SetClipboardData ( std::to_wstring(pApp->skif.cpu_type));
if (ImGui::MenuItem ("Favorited", std::to_string (pApp->skif.pinned).c_str()))
SKIF_Util_SetClipboardData ( std::to_wstring(pApp->skif.pinned));
if (ImGui::MenuItem ("Hidden", std::to_string (pApp->skif.hidden).c_str()))
SKIF_Util_SetClipboardData ( std::to_wstring(pApp->skif.hidden));

ImGui::PopID ( );

Expand All @@ -2141,10 +2137,10 @@ DrawGameContextMenu (app_record_s* pApp)
SKIF_Util_SetClipboardData ( pApp->steam.manifest_path);
if (ImGui::MenuItem ("CPU Architecture", std::to_string ((int)pApp->common_config.cpu_type).c_str()))
SKIF_Util_SetClipboardData ( std::to_wstring((int)pApp->common_config.cpu_type));
if (ImGui::MenuItem ("Visibility", (pApp->steam.shared.hidden) ? "Hidden" : "Visible"))
SKIF_Util_SetClipboardData ( (pApp->steam.shared.hidden) ? L"Hidden" : L"Visible");
if (ImGui::MenuItem ("Favorited", std::to_string (pApp->steam.shared.favorite).c_str()))
SKIF_Util_SetClipboardData ( std::to_wstring(pApp->steam.shared.favorite));
if (ImGui::MenuItem ("Favorited", std::to_string (pApp->steam.shared.favorite).c_str()))
SKIF_Util_SetClipboardData ( std::to_wstring(pApp->steam.shared.favorite));
if (ImGui::MenuItem ("Hidden", std::to_string (pApp->steam.shared.hidden).c_str()))
SKIF_Util_SetClipboardData ( std::to_wstring(pApp->steam.shared.hidden));
ImGui::PopID ( );
}

Expand Down Expand Up @@ -4573,10 +4569,10 @@ SKIF_UI_Tab_DrawLibrary (void)
std::string keyName = "";
int keyCPU = 0;
int keyAutoStop = 0;
int keyHidden = app.second.steam.shared.hidden; // will be 1 for hidden Steam games; 0 for the rest
int keyHidden = -1; // will be 1 for hidden Steam games; 0 for the rest
int keyUses = 0;
std::string keyUsed = "";
int keyPinned = app.second.steam.shared.favorite; // will be 1 for favorited Steam games; 0 for the rest
int keyPinned = -1; // will be 1 for favorited Steam games; 0 for the rest

// Special K defaults to pinned
if (isSpecialK)
Expand Down Expand Up @@ -4667,7 +4663,7 @@ SKIF_UI_Tab_DrawLibrary (void)
}

// Hide any... uhm... hidden... games...
if (app.second.skif.hidden == 1 && ! _registry._LibraryHidden)
if (! _registry._LibraryHidden && (app.second.skif.hidden == 1 || (app.second.skif.hidden == -1 && app.second.steam.shared.hidden == 1)))
{
PLOG_DEBUG << "App ID " << app.second.id << " (" << app.second.store_utf8 << ") has been hidden; ignoring!";

Expand All @@ -4677,7 +4673,7 @@ SKIF_UI_Tab_DrawLibrary (void)

// Hide all non-hidden games if we are in "hidden mode", lol?
// Except for Special K, obviously
else if (app.second.skif.hidden == 0 && _registry._LibraryHidden && ! isSpecialK)
else if (_registry._LibraryHidden && ! isSpecialK && (app.second.skif.hidden == 0 || (app.second.skif.hidden == -1 && app.second.steam.shared.hidden == 0)))
{
app.second.id = 0;
continue;
Expand Down Expand Up @@ -5610,7 +5606,7 @@ SKIF_UI_Tab_DrawLibrary (void)
continue;

// Separate pinned from unpinned
if (app.second.skif.pinned > 0)
if (app.second.skif.pinned > 0 || (app.second.skif.pinned == -1 && app.second.steam.shared.favorite == 1))
pinned++;
else if (pinned > 0)
{
Expand Down Expand Up @@ -7592,13 +7588,13 @@ SKIF_UI_Tab_DrawLibrary (void)

if (cached_hidden_load)
{
cached_hidden = (bool)pApp->skif.hidden;
cached_hidden = (pApp->skif.hidden == 1 || (pApp->skif.hidden == -1 && pApp->steam.shared.hidden == 1));
cached_hidden_load = false;
}

if (cached_pinned_load)
{
cached_pinned = (pApp->skif.pinned > 0);
cached_pinned = (pApp->skif.pinned > 0 || (pApp->skif.pinned == -1 && pApp->steam.shared.favorite == 1));
cached_pinned_load = false;
}

Expand Down Expand Up @@ -7833,11 +7829,11 @@ SKIF_UI_Tab_DrawLibrary (void)
ImGui::SameLine ( );
ImGui::Spacing ( );
ImGui::SameLine ( );
ImGui::Checkbox ("Hide game###HideInLibrary", &cached_hidden);
ImGui::Checkbox ("Hidden###HideInLibrary", &cached_hidden);
ImGui::SameLine ( );
ImGui::Spacing ( );
ImGui::SameLine ( );
ImGui::Checkbox ("Pin game###PinInLibrary", &cached_pinned);
ImGui::Checkbox ("Favorite###PinInLibrary", &cached_pinned);
ImGui::TreePop ( );

ImGui::TreePop ( );
Expand All @@ -7862,13 +7858,13 @@ SKIF_UI_Tab_DrawLibrary (void)
pApp->skif.auto_stop = cached_auto_stop;
pApp->skif.instant_play = cached_instant_play;

if ((int)cached_hidden != pApp->skif.hidden)
if (cached_hidden != (pApp->skif.hidden == 1 || (pApp->skif.hidden == -1 && pApp->steam.shared.hidden == 1)))
{
repopulate = true;
pApp->skif.hidden = (int)cached_hidden;
}

if ((int)cached_pinned != pApp->skif.pinned)
if (cached_pinned != (pApp->skif.pinned > 0 || (pApp->skif.pinned == -1 && pApp->steam.shared.favorite == 1)))
{
resort = true;
pApp->skif.pinned = (int)cached_pinned;
Expand Down
5 changes: 3 additions & 2 deletions src/utility/games.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,9 @@ SKIF_GamingCollection::SortApps (std::vector <std::pair <std::string, app_record
[]( const std::pair <std::string, app_record_s>& a,
const std::pair <std::string, app_record_s>& b ) -> int
{
return a.second.skif.pinned >
b.second.skif.pinned;
// Use the highest value between SKIF's pinned value, or 0 / Steam's pinned value if SKIF's is unset
return std::max (a.second.skif.pinned, (a.second.skif.pinned == -1) ? a.second.steam.shared.favorite : 0) >
std::max (b.second.skif.pinned, (b.second.skif.pinned == -1) ? b.second.steam.shared.favorite : 0);
}
);
}
Expand Down

0 comments on commit 29f3d84

Please sign in to comment.