fix(hardcover): handle bookerly/githubsync label lambda anchor variants in SettingsActivity.cpp

This commit is contained in:
justin committed 2026-04-22 18:22:36 -07:00
1 parent b5e96d7ead
commit e4650ac046
1 file changed
+21 -6
+21 -6
View File
@@ -269,21 +269,36 @@ def patch_settings_cpp(repo_dir):
if 'Hardcover Progress' not in content: if 'Hardcover Progress' not in content:
if 'selectedCategoryIndex == 4' in content: if 'selectedCategoryIndex == 4' in content:
# Lambda already patched by darkmode/smallerfonts - insert after last key check. # Lambda already patched by another plugin - insert before the closing return.
# Exact closing from real patched file:
closing = ( closing = (
' }\n' ' }\n'
' return std::string(I18N.get(settings[index].nameId));\n' ' return std::string(I18N.get(settings[index].nameId));\n'
' }, nullptr, nullptr,' ' }, nullptr, nullptr,'
) )
closing_bookerly = (
' }\n'
' return std::string(I18N.get(settings[index].nameId));\n'
' }, nullptr, nullptr,'
)
for last_key_line in [ for last_key_line in [
' if (s.key && std::string(s.key) == "smallerFontsMode") return "Smaller Fonts";\n', ' if (s.key && std::string(s.key) == "smallerFontsMode") return "Smaller Fonts";\n',
' if (s.key && std::string(s.key) == "darkModeState") return "Dark Mode";\n', ' if (s.key && std::string(s.key) == "darkModeState") return "Dark Mode";\n',
' s.action == SettingAction::GitHubSync) return "GitHub Sync";\n',
' s.action == SettingAction::BookerlyInstalled) return "Bookerly Plugin";\n',
]: ]:
anchor = last_key_line + closing for cl in [closing, closing_bookerly]:
if anchor in content: anchor = last_key_line + cl
content = content.replace(anchor, last_key_line + hardcover_label_line + closing) if anchor in content:
break content = content.replace(anchor, last_key_line + hardcover_label_line + cl)
break
else:
continue
break
else:
for cl in [closing, closing_bookerly]:
if cl in content:
content = content.replace(cl, hardcover_label_line + cl, 1)
break
else: else:
# No other plugin has patched the lambda yet - create it from scratch. # No other plugin has patched the lambda yet - create it from scratch.
# Exact line from real unpatched file (6 leading spaces): # Exact line from real unpatched file (6 leading spaces):