fix (lockscreen) add plugin back to Plugins list
This commit is contained in:
1 parent
ad280e6d5e
commit
0fa657544c
1 file changed
+75
-88
+75
-88
@@ -142,7 +142,7 @@ def patch_settings_cpp(repo_dir):
|
|||||||
path = find_first("SettingsActivity.cpp", repo_dir)
|
path = find_first("SettingsActivity.cpp", repo_dir)
|
||||||
content = read_file(path)
|
content = read_file(path)
|
||||||
|
|
||||||
if '"LockscreenPlugin.h"' in content and "lockscreenPinHash" in content and '"lockscreenMode") return "Lockscreen"' in content:
|
if '"LockscreenPlugin.h"' in content and 'lockscreenPinHash' in content and '"lockscreenMode") return "Lockscreen"' in content:
|
||||||
print(" SettingsActivity.cpp already patched, skipping.")
|
print(" SettingsActivity.cpp already patched, skipping.")
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -166,62 +166,32 @@ def patch_settings_cpp(repo_dir):
|
|||||||
changed = True
|
changed = True
|
||||||
|
|
||||||
if 'pluginsSettings.clear()' not in content:
|
if 'pluginsSettings.clear()' not in content:
|
||||||
content = content.replace(
|
result = content.replace(
|
||||||
' systemSettings.clear();\n',
|
' systemSettings.clear();\n',
|
||||||
' systemSettings.clear();\n'
|
' systemSettings.clear();\n pluginsSettings.clear();\n'
|
||||||
' pluginsSettings.clear();\n'
|
|
||||||
' for (const auto& setting : getSettingsList()) {\n'
|
|
||||||
' if (setting.key && std::string(setting.key) == "lockscreenMode") {\n'
|
|
||||||
' pluginsSettings.push_back(setting);\n'
|
|
||||||
' }\n'
|
|
||||||
' }\n'
|
|
||||||
)
|
)
|
||||||
changed = True
|
if 'pluginsSettings.clear()' in result:
|
||||||
elif 'pluginsSettings.push_back' not in content:
|
content = result
|
||||||
content = content.replace(
|
changed = True
|
||||||
' pluginsSettings.clear();\n',
|
|
||||||
' pluginsSettings.clear();\n'
|
lockscreen_push = (
|
||||||
' for (const auto& setting : getSettingsList()) {\n'
|
' pluginsSettings.push_back(SettingInfo::Enum(\n'
|
||||||
' if (setting.key && std::string(setting.key) == "lockscreenMode") {\n'
|
' StrId::STR_NONE_OPT, &CrossPointSettings::lockscreenMode,\n'
|
||||||
' pluginsSettings.push_back(setting);\n'
|
' {StrId::STR_NONE_OPT, StrId::STR_NONE_OPT},\n'
|
||||||
' }\n'
|
' "lockscreenMode", StrId::STR_NONE_OPT\n'
|
||||||
' }\n'
|
' ));\n'
|
||||||
)
|
)
|
||||||
changed = True
|
|
||||||
elif '"lockscreenMode") {\n pluginsSettings.push_back' not in content:
|
if '"lockscreenMode", StrId::STR_NONE_OPT' not in content:
|
||||||
content = content.replace(
|
for anchor in [
|
||||||
' for (const auto& setting : getSettingsList()) {\n'
|
' selectedCategoryIndex = 0;\n selectedSettingIndex = 0;',
|
||||||
' if (setting.key && std::string(setting.key) == "lockscreenMode") {\n'
|
' selectedCategoryIndex = 0;',
|
||||||
' pluginsSettings.push_back(setting);\n'
|
' currentSettings = &displaySettings;',
|
||||||
' }\n'
|
]:
|
||||||
' }\n'
|
if anchor in content:
|
||||||
'\n'
|
content = content.replace(anchor, lockscreen_push + anchor, 1)
|
||||||
' for (const auto& setting : getSettingsList()) {',
|
changed = True
|
||||||
' for (const auto& setting : getSettingsList()) {\n'
|
break
|
||||||
' if (setting.key && std::string(setting.key) == "lockscreenMode") {\n'
|
|
||||||
' pluginsSettings.push_back(setting);\n'
|
|
||||||
' }\n'
|
|
||||||
' }\n'
|
|
||||||
'\n'
|
|
||||||
' for (const auto& setting : getSettingsList()) {'
|
|
||||||
)
|
|
||||||
# If pluginsSettings.push_back exists from another plugin but not lockscreen,
|
|
||||||
# append after the existing population loop
|
|
||||||
if '"lockscreenMode") {\n pluginsSettings.push_back' not in content:
|
|
||||||
import re
|
|
||||||
content = re.sub(
|
|
||||||
r'( pluginsSettings\.clear\(\);(\n for.*?push_back.*?\n \}\n)*)',
|
|
||||||
lambda m: m.group(0) +
|
|
||||||
' for (const auto& setting : getSettingsList()) {\n'
|
|
||||||
' if (setting.key && std::string(setting.key) == "lockscreenMode") {\n'
|
|
||||||
' pluginsSettings.push_back(setting);\n'
|
|
||||||
' }\n'
|
|
||||||
' }\n',
|
|
||||||
content,
|
|
||||||
count=1,
|
|
||||||
flags=re.DOTALL
|
|
||||||
)
|
|
||||||
changed = True
|
|
||||||
|
|
||||||
if 'case 4:' not in content:
|
if 'case 4:' not in content:
|
||||||
content = content.replace(
|
content = content.replace(
|
||||||
@@ -271,32 +241,35 @@ def patch_settings_cpp(repo_dir):
|
|||||||
)
|
)
|
||||||
changed = True
|
changed = True
|
||||||
elif '"lockscreenMode") return "Lockscreen"' not in content:
|
elif '"lockscreenMode") return "Lockscreen"' not in content:
|
||||||
for s_decl in [
|
import re
|
||||||
' const auto& s = settings[index];\n',
|
result = re.sub(
|
||||||
' const auto& s = settings[index];\n',
|
r'( if \(selectedCategoryIndex == 4\) \{.*?)( \})',
|
||||||
]:
|
lambda m: m.group(1) + ' if (s.key && std::string(s.key) == "lockscreenMode") return "Lockscreen";\n' + m.group(2),
|
||||||
if s_decl in content:
|
content,
|
||||||
indent = s_decl[:len(s_decl) - len(s_decl.lstrip())]
|
count=1,
|
||||||
content = content.replace(
|
flags=re.DOTALL,
|
||||||
s_decl,
|
)
|
||||||
s_decl + indent + 'if (s.key && std::string(s.key) == "lockscreenMode") return "Lockscreen";\n',
|
if result != content:
|
||||||
1
|
content = result
|
||||||
)
|
changed = True
|
||||||
break
|
|
||||||
changed = True
|
|
||||||
|
|
||||||
if 'LockscreenPlugin::modeName' not in content:
|
if 'LockscreenPlugin::modeName' not in content:
|
||||||
content = content.replace(
|
import re
|
||||||
' } else {\n'
|
lockscreen_value = (
|
||||||
' valueText = I18N.get(setting.enumValues[value]);\n'
|
' if (setting.type == SettingType::ENUM &&\n'
|
||||||
' }',
|
' setting.key && std::string(setting.key) == "lockscreenMode") {\n'
|
||||||
' } else if (setting.key && std::string(setting.key) == "lockscreenMode") {\n'
|
' valueText = LockscreenPlugin::modeName(static_cast<LockscreenMode>(SETTINGS.lockscreenMode));\n'
|
||||||
' valueText = LockscreenPlugin::modeName(static_cast<LockscreenMode>(value));\n'
|
' } else '
|
||||||
' } else {\n'
|
|
||||||
' valueText = I18N.get(setting.enumValues[value]);\n'
|
|
||||||
' }'
|
|
||||||
)
|
)
|
||||||
changed = True
|
result = re.sub(
|
||||||
|
r'( if \(setting\.type == SettingType::(?:ACTION|TOGGLE|ENUM))',
|
||||||
|
lockscreen_value + r'\1',
|
||||||
|
content,
|
||||||
|
count=1,
|
||||||
|
)
|
||||||
|
if result != content:
|
||||||
|
content = result
|
||||||
|
changed = True
|
||||||
|
|
||||||
if 'lockscreenPinHash' not in content:
|
if 'lockscreenPinHash' not in content:
|
||||||
content = content.replace(
|
content = content.replace(
|
||||||
@@ -328,6 +301,7 @@ def patch_settings_cpp(repo_dir):
|
|||||||
else:
|
else:
|
||||||
print(" SettingsActivity.cpp already patched, skipping.")
|
print(" SettingsActivity.cpp already patched, skipping.")
|
||||||
|
|
||||||
|
|
||||||
def patch_web_server(repo_dir):
|
def patch_web_server(repo_dir):
|
||||||
path = find_first("CrossPointWebServer.cpp", repo_dir)
|
path = find_first("CrossPointWebServer.cpp", repo_dir)
|
||||||
content = read_file(path)
|
content = read_file(path)
|
||||||
@@ -411,18 +385,31 @@ def patch_main_cpp(repo_dir):
|
|||||||
' }\n'
|
' }\n'
|
||||||
)
|
)
|
||||||
|
|
||||||
content = content.replace(
|
anchor = ' RECENT_BOOKS.loadFromFile();\n\n if (HalSystem::isRebootFromPanic())'
|
||||||
' RECENT_BOOKS.loadFromFile();\n'
|
if anchor in content:
|
||||||
'\n'
|
content = content.replace(
|
||||||
' if (HalSystem::isRebootFromPanic())',
|
anchor,
|
||||||
' RECENT_BOOKS.loadFromFile();\n'
|
' RECENT_BOOKS.loadFromFile();\n' + lockscreen_block + '\n if (HalSystem::isRebootFromPanic())'
|
||||||
+ lockscreen_block
|
)
|
||||||
+ '\n'
|
else:
|
||||||
' if (HalSystem::isRebootFromPanic())'
|
idx = content.find('RECENT_BOOKS')
|
||||||
)
|
print(' DIAG main.cpp around RECENT_BOOKS:', repr(content[max(0,idx-50):idx+300]))
|
||||||
|
import re
|
||||||
|
m = re.search(r'RECENT_BOOKS\.loadFromFile\(\);.*?\n(\s*\n)*(\s*if)', content, re.DOTALL)
|
||||||
|
if m:
|
||||||
|
actual_anchor = content[m.start():m.end()]
|
||||||
|
content = content.replace(actual_anchor, ' RECENT_BOOKS.loadFromFile();\n' + lockscreen_block + '\n' + content[m.end()-len(m.group(2)):m.end()])
|
||||||
|
print(' main.cpp lockscreen block inserted via regex.')
|
||||||
|
else:
|
||||||
|
print(' WARNING: could not find RECENT_BOOKS anchor in main.cpp')
|
||||||
|
|
||||||
write_file(path, content)
|
write_file(path, content)
|
||||||
print(" main.cpp patched.")
|
has_block = "LockscreenActivity lockAct" in content
|
||||||
|
has_sleep = "enterDeepSleep" in content
|
||||||
|
if has_block:
|
||||||
|
idx2 = content.find("LockscreenActivity lockAct")
|
||||||
|
print(" DIAG lockscreen block context:", repr(content[max(0,idx2-200):idx2+50]))
|
||||||
|
print(f" main.cpp patched. lockscreen_block={has_block} enterDeepSleep={has_sleep}")
|
||||||
|
|
||||||
|
|
||||||
def patch_settings_html(repo_dir):
|
def patch_settings_html(repo_dir):
|
||||||
|
|||||||
Reference in new issue
Block a user