Skip to content

Commit

Permalink
Implement new Switch.Profile() constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
TooTallNate committed Mar 18, 2024
1 parent 70ebcd5 commit d30e385
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/rude-kangaroos-push.md
@@ -0,0 +1,5 @@
---
"nxjs-runtime": patch
---

Implement `new Switch.Profile()` constructor
1 change: 1 addition & 0 deletions packages/runtime/src/$.ts
Expand Up @@ -45,6 +45,7 @@ export interface Init {
accountProfileInit(c: ClassOf<Profile>): void;
accountCurrentProfile(): Profile | null;
accountSelectProfile(): Profile | null;
accountProfileNew(uid: ProfileUid): Profile;
accountProfiles(): Profile[];

// applet.c
Expand Down
19 changes: 15 additions & 4 deletions packages/runtime/src/switch/profile.ts
@@ -1,5 +1,5 @@
import { $ } from '../$';
import { assertInternalConstructor, proto } from '../utils';
import { proto } from '../utils';

let init = false;

Expand Down Expand Up @@ -31,10 +31,21 @@ export class Profile {
declare readonly image: ArrayBuffer;

/**
* @ignore
* Creates a new `Profile` instance from the given profile UID.
*
* @example
*
* ```typescript
* const profile = new Switch.Profile([
* 0x10005d4864d166b7n,
* 0x965b8cb028cd8a81n,
* ]);
* console.log(profile.nickname);
* ```
*/
constructor() {
assertInternalConstructor(arguments);
constructor(uid: ProfileUid) {
_init();
return proto($.accountProfileNew(uid), Profile);
}
}
$.accountProfileInit(Profile);
Expand Down
15 changes: 14 additions & 1 deletion source/account.c
Expand Up @@ -91,7 +91,7 @@ static JSValue nx_account_select_profile(JSContext *ctx, JSValueConst this_val,
Result rc = pselShowUserSelector(&uid, &settings);
if (R_FAILED(rc))
{
if (rc == 0x27C /* ResultCancelledByUser*/)
if (rc == 0x27C /* ResultCancelledByUser */)
{
return JS_NULL;
}
Expand All @@ -101,6 +101,18 @@ static JSValue nx_account_select_profile(JSContext *ctx, JSValueConst this_val,
return profile_new(ctx, uid);
}

static JSValue nx_account_profile_new(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
AccountUid uid;
if (
JS_ToBigInt64(ctx, (int64_t*)&uid.uid[0], JS_GetPropertyUint32(ctx, argv[0], 0)) ||
JS_ToBigInt64(ctx, (int64_t*)&uid.uid[1], JS_GetPropertyUint32(ctx, argv[0], 1)))
{
return JS_EXCEPTION;
}
return profile_new(ctx, uid);
}

static JSValue nx_account_profiles(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
Result rc;
Expand Down Expand Up @@ -217,6 +229,7 @@ static const JSCFunctionListEntry function_list[] = {
JS_CFUNC_DEF("accountProfileInit", 1, nx_account_profile_init),
JS_CFUNC_DEF("accountCurrentProfile", 0, nx_account_current_profile),
JS_CFUNC_DEF("accountSelectProfile", 0, nx_account_select_profile),
JS_CFUNC_DEF("accountProfileNew", 0, nx_account_profile_new),
JS_CFUNC_DEF("accountProfiles", 0, nx_account_profiles),
};

Expand Down

0 comments on commit d30e385

Please sign in to comment.