Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions include/wups/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
19 changes: 18 additions & 1 deletion include/wups/config_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 14 additions & 1 deletion libraries/libwups/config_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Loading