mirror of
https://github.com/switchbrew/libnx.git
synced 2025-08-05 07:59:24 +02:00
Cache the preselected user in accountInitialize. Get/set the preselected userID in env, so that accountGetPreselectedUser() is usable multiple times. Renamed accountGetActiveUser to accountGetLastOpenedUser. Improved docs.
This commit is contained in:
parent
4fa878f4b1
commit
773111b3f2
@ -10,6 +10,7 @@
|
||||
|
||||
#define ACC_USER_LIST_SIZE 8
|
||||
|
||||
/// Profile
|
||||
typedef struct {
|
||||
Service s;
|
||||
} AccountProfile;
|
||||
@ -46,9 +47,8 @@ Result accountGetUserCount(s32* user_count);
|
||||
*/
|
||||
Result accountListAllUsers(u128* userIDs, size_t max_userIDs, size_t *actual_total);
|
||||
|
||||
/// Get the userID for the currently active user. The output userID is only valid when the output account_selected==1, otherwise no user is currently selected.
|
||||
/// An user is only selected when the user-account selection applet was used to select an user at least once before.
|
||||
Result accountGetActiveUser(u128 *userID, bool *account_selected);
|
||||
/// Get the userID for the last opened user. The output userID is only valid when the output account_selected==1.
|
||||
Result accountGetLastOpenedUser(u128 *userID, bool *account_selected);
|
||||
|
||||
/// Get an AccountProfile for the specified userID.
|
||||
Result accountGetProfile(AccountProfile* out, u128 userID);
|
||||
@ -64,6 +64,7 @@ Result accountProfileLoadImage(AccountProfile* profile, void* buf, size_t len, s
|
||||
|
||||
void accountProfileClose(AccountProfile* profile);
|
||||
|
||||
/// Gets the userID which was selected by the profile-selector applet (if any), prior to launching the currently running Application title. This can only be used once under the current process, under an Application title.
|
||||
/// Gets the userID which was selected by the profile-selector applet (if any), prior to launching the currently running Application title.
|
||||
/// This gets the cached PreselectedUser loaded during accountInitialize, when PreselectedUser is available.
|
||||
Result accountGetPreselectedUser(u128 *userID);
|
||||
|
||||
|
@ -5,16 +5,23 @@
|
||||
#include "services/acc.h"
|
||||
#include "services/sm.h"
|
||||
#include "services/applet.h"
|
||||
#include "runtime/env.h"
|
||||
#include "runtime/hosversion.h"
|
||||
|
||||
static Service g_accSrv;
|
||||
static u64 g_refCnt;
|
||||
static u128 g_accPreselectedUserID;
|
||||
static bool g_accPreselectedUserInitialized;
|
||||
|
||||
static Result _accountInitializeApplicationInfo(void);
|
||||
|
||||
static Result _accountGetPreselectedUser(u128 *userID);
|
||||
|
||||
Result accountInitialize(void)
|
||||
{
|
||||
Result rc=0;
|
||||
Result rc2=0;
|
||||
u128 *userIdEnv = envGetUserIdStorage();
|
||||
|
||||
atomicIncrement64(&g_refCnt);
|
||||
|
||||
@ -27,6 +34,18 @@ Result accountInitialize(void)
|
||||
if (R_SUCCEEDED(rc)) rc = _accountInitializeApplicationInfo();
|
||||
}
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
rc2 = _accountGetPreselectedUser(&g_accPreselectedUserID);
|
||||
if (R_SUCCEEDED(rc2)) {
|
||||
g_accPreselectedUserInitialized = true;
|
||||
if (userIdEnv) *userIdEnv = g_accPreselectedUserID;
|
||||
}
|
||||
else if (userIdEnv) {
|
||||
g_accPreselectedUserID = *userIdEnv;
|
||||
if (g_accPreselectedUserID) g_accPreselectedUserInitialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (R_FAILED(rc)) accountExit();
|
||||
|
||||
return rc;
|
||||
@ -179,7 +198,7 @@ Result accountListAllUsers(u128* userIDs, size_t max_userIDs, size_t *actual_tot
|
||||
return rc;
|
||||
}
|
||||
|
||||
Result accountGetActiveUser(u128 *userID, bool *account_selected)
|
||||
Result accountGetLastOpenedUser(u128 *userID, bool *account_selected)
|
||||
{
|
||||
IpcCommand c;
|
||||
ipcInitialize(&c);
|
||||
@ -370,7 +389,7 @@ void accountProfileClose(AccountProfile* profile) {
|
||||
serviceClose(&profile->s);
|
||||
}
|
||||
|
||||
Result accountGetPreselectedUser(u128 *userID) {
|
||||
static Result _accountGetPreselectedUser(u128 *userID) {
|
||||
Result rc=0;
|
||||
AppletStorage storage;
|
||||
s64 tmpsize=0;
|
||||
@ -405,3 +424,11 @@ Result accountGetPreselectedUser(u128 *userID) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
Result accountGetPreselectedUser(u128 *userID) {
|
||||
if (!g_accPreselectedUserInitialized) return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
|
||||
|
||||
*userID = g_accPreselectedUserID;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user