Closed p-sam closed 5 years ago
Would this matter when the profile-selector applet is eventually supported?
yes, for applications that have the user be preselected before launch
As in, just use profile-selector without accountGetPreselectedUser().
Well you would have to select it two times
Also, most of the games i used as donor title would do that
accountGetActiveUser does the same thing though.
From what I could try, accountGetActiveUser would return account_selected = false, and not the preselected user, so what you would be suggest is for hb to call the playerSelect applet "again" (once in hb, but effectively shown twice for the user), to populate the userId return of accountGetActiveUser ?
Code? AFAIK accountGetActiveUser works fine with preselected-user...
So I ran the following code on my end :
bool account_selected = false;
u128 userID = 0;
Result rc = accountInitialize();
if (R_FAILED(rc)) {
printf("accountInitialize() failed: 0x%x\n", rc);
}
if(R_SUCCEEDED(rc)) {
rc = accountGetActiveUser(&userID, &account_selected);
if (R_FAILED(rc)) {
printf("accountGetActiveUser() failed: 0x%x\n", rc);
}
else if(!account_selected) {
printf("accountGetActiveUser: No user is currently selected.\n");
} else {
printf("accountGetActiveUser: Current userID is %lx%lx\n", (u64)(userID>>64), (u64)userID);
}
rc = accountGetPreselectedUser(&userID);
if (R_FAILED(rc)) {
printf("accountGetPreselectedUser() failed: 0x%x\n", rc);
} else {
printf("accountGetPreselectedUser: Current userID is %lx%lx\n", (u64)(userID>>64), (u64)userID);
}
}
accountExit();
and here's what is outputted: (%userid% is my first user id here, irrelevant to the case)
accountGetActiveUser: No user is currently selected.
accountGetPreselectedUser: Current userID is %userid%
accountGetActiveUser: No user is currently selected.
accountGetPreselectedUser() failed: 0x480
So it exhibits the behavior I described, but it didn't match with your last comment, so I tried calling accountGetPreselectedUser before accountGetActiveUser, which leads to significant result changes:
accountGetPreselectedUser: Current userID is %userid%
accountGetActiveUser: Current userID is %userid%
accountGetPreselectedUser() failed: 0x480
accountGetActiveUser: Current userID is %userid%
That means that issue can be closed, because there is no need then to try to keep around a reference to a userID we can obtain by calling accountGetPreselectedUser first. At best we can directly obtain the userID from that call, and else it will be returned via accountGetActiveUser anyway. However, I'd add a note of that behavior on accountGetActiveUser header comment on libnx below of :
/// An user is only selected when the user-account selection applet was used to select an user at least once before.
Since from what I gather, it would only work if accountGetPreselectedUser was called at least once before (once in the process? or in the nro hb? I have not tested yet).
Closing as the issue does not belong in hbloader anymore.
switch-examples/account/ works fine AFAIK when nothing account-related was done previously besides applet user-preselect (unless that changed with a newer sysver?).
If i'm not mistaken, the current example would just print "No user is currently selected"
Works on v2.x :|
I see, I'm on 7.x right now, which may explain the diff behavior
2a0d4a7713b0b2af2cece59596854bab7e0c55e3 https://github.com/switchbrew/libnx/commit/773111b3f2fa4a54ead4e7ee9cfefbd786799b7d
👍
When using hb over an app which makes you choose the user before launch, you retrieve the userID with accountGetPreselectedUser. However subsequent calls will fail as it can only be retrieved once per process, meaning if you would return to hbmenu and launch again an nro, you would not be able to get it unless you quit game and run it again. I wanted to discuss here the possible approach to making it available to hb. Would adding a ConfigEntry with that userid (if app) be something we can add to hbloader?
hb would then try to retrieve that config entry, and if not present launch playerSelectApplet and get the current active user