Add WUPSConfigAPI_GetMenuOpen() to detect if the config menu is open. (#76)

* Add `WUPSConfigAPI_IsMenuOpen()` to detect if the config menu is open.

* Changed function signature and name to match other functions.

* - Renamed function from `WUPSConfigAPI_GetMenuOpen()` to `WUPSConfigAPI_GetMenuOpen()`.
- Changed result type from `BOOL` to `WUPSConfigAPIMenuStatus` enum.

---------

Co-authored-by: Daniel K. O. (dkosmari) <none@none>
This commit is contained in:
Daniel K. O. 2024-11-28 15:43:24 -03:00 committed by GitHub
parent 74205ee081
commit 1ac579aebb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 37 additions and 2 deletions

View File

@ -294,3 +294,8 @@ typedef struct wups_loader_init_config_args_t {
uint32_t arg_version;
uint32_t plugin_identifier;
} wups_loader_init_config_args_t;
typedef enum WUPSConfigAPIMenuStatus {
WUPSCONFIG_API_MENU_STATUS_CLOSED = 0,
WUPSCONFIG_API_MENU_STATUS_OPENED = 1,
} WUPSConfigAPIMenuStatus;

View File

@ -208,6 +208,23 @@ WUPSConfigAPIStatus WUPSConfigAPI_Item_Destroy(WUPSConfigItemHandle handle);
*/
const char *WUPSConfigAPI_GetStatusStr(WUPSConfigAPIStatus status);
/**
* @brief Checks if the WUPS config menu is open.
*
* Use this function if you want to change the behavior of a function replacement while
* the user is interacting with the WUPS config menu.
*
* @param[out] status Pointer to a variable to write the menu status:
* - `WUPSCONFIG_API_MENU_STATUS_CLOSED`
* - `WUPSCONFIG_API_MENU_STATUS_OPENED`
* @return WUPSConfigAPIStatus The status code indicating the result of the operation:
* - WUPSCONFIG_API_RESULT_SUCCESS: The result was written successfully to the `status` argument.
* - WUPSCONFIG_API_RESULT_INVALID_ARGUMENT: The `status` argument is a null pointer.
* - WUPSCONFIG_API_RESULT_LIB_UNINITIALIZED: The WUPSConfig API is not initialized.
* - WUPSCONFIG_API_RESULT_MODULE_MISSING_EXPORT: The function WUPSConfigAPI_GetMenuOpen was not found in the module.
*/
WUPSConfigAPIStatus WUPSConfigAPI_Menu_GetStatus(WUPSConfigAPIMenuStatus *status);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -13,6 +13,7 @@ static WUPSConfigAPIStatus (*sAPICategoryAddCategory)(WUPSConfigCategoryHandle p
static WUPSConfigAPIStatus (*sAPICategoryAddItem)(WUPSConfigCategoryHandle parentHandle, WUPSConfigItemHandle itemHandle) = nullptr;
static WUPSConfigAPIStatus (*sAPIItemCreateEx)(WUPSConfigAPICreateItemOptions options, WUPSConfigItemHandle *out) = nullptr;
static WUPSConfigAPIStatus (*sAPIItemDestroy)(WUPSConfigItemHandle handle) = nullptr;
static WUPSConfigAPIStatus (*sAPIMenuGetStatus)(WUPSConfigAPIMenuStatus *status) = nullptr;
static WUPSConfigAPIVersion sConfigAPIVersion = WUPS_CONFIG_API_VERSION_ERROR;
@ -101,6 +102,8 @@ extern "C" WUPSConfigAPIStatus WUPSConfigAPI_InitLibrary_Internal(wups_loader_in
WUPS_DEBUG_REPORT("libwups: FindExport WUPSConfigAPI_Item_Destroy failed.\n");
return WUPSCONFIG_API_RESULT_MODULE_MISSING_EXPORT;
}
// This one is allowed to fail.
OSDynLoad_FindExport(sModuleHandle, OS_DYNLOAD_EXPORT_FUNC, "WUPSConfigAPI_Menu_GetStatus", (void **) &sAPIMenuGetStatus);
sConfigLibInitDone = true;
sConfigPluginIdentifier = args.plugin_identifier;
@ -242,4 +245,14 @@ WUPSConfigAPIStatus WUPSConfigAPI_Item_Destroy(WUPSConfigItemHandle handle) {
}
return sAPIItemDestroy(handle);
}
}
WUPSConfigAPIStatus WUPSConfigAPI_Menu_GetStatus(WUPSConfigAPIMenuStatus *out) {
if (sConfigAPIVersion == WUPS_CONFIG_API_VERSION_ERROR) {
return WUPSCONFIG_API_RESULT_LIB_UNINITIALIZED;
}
if (sAPIMenuGetStatus == nullptr) {
return WUPSCONFIG_API_RESULT_MODULE_MISSING_EXPORT;
}
return sAPIMenuGetStatus(out);
}