From 508cc5e03e6157cd4ae7b40bbb47baf79985b3ab Mon Sep 17 00:00:00 2001 From: Maschell Date: Sun, 3 Mar 2024 17:55:30 +0100 Subject: [PATCH] Only update storage at application end if the value actually changed --- src/main.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 1e35468..9323a70 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -89,20 +89,28 @@ DEINITIALIZE_PLUGIN() { } } +SwipSwapAudioMode sAudioModeAtStart; +bool sDoSwapAtStart; + // Called whenever an application was started. ON_APPLICATION_START() { initLogging(); + sAudioModeAtStart = gCurAudioMode; + sDoSwapAtStart = gDoScreenSwap; } ON_APPLICATION_REQUESTS_EXIT() { - if (WUPSStorageAPI::Store(AUDIO_MODE_CONFIG_STRING, gCurAudioMode) != WUPS_STORAGE_ERROR_SUCCESS) { - DEBUG_FUNCTION_LINE_ERR("Failed to store screen mode to storage"); - } - if (WUPSStorageAPI::Store(SWAP_SCREENS_CONFIG_STRING, gDoScreenSwap) != WUPS_STORAGE_ERROR_SUCCESS) { - DEBUG_FUNCTION_LINE_ERR("Failed to store screen mode to storage"); - } - if (WUPSStorageAPI::SaveStorage() != WUPS_STORAGE_ERROR_SUCCESS) { - DEBUG_FUNCTION_LINE_ERR("Failed to save storage"); + if (sAudioModeAtStart != gCurAudioMode || sDoSwapAtStart != gDoScreenSwap) { + if (WUPSStorageAPI::Store(AUDIO_MODE_CONFIG_STRING, gCurAudioMode) != WUPS_STORAGE_ERROR_SUCCESS) { + DEBUG_FUNCTION_LINE_ERR("Failed to store screen mode to storage"); + } + + if (WUPSStorageAPI::Store(SWAP_SCREENS_CONFIG_STRING, gDoScreenSwap) != WUPS_STORAGE_ERROR_SUCCESS) { + DEBUG_FUNCTION_LINE_ERR("Failed to store screen mode to storage"); + } + if (WUPSStorageAPI::SaveStorage() != WUPS_STORAGE_ERROR_SUCCESS) { + DEBUG_FUNCTION_LINE_ERR("Failed to save storage"); + } } deinitLogging();