Skip to content

Commit

Permalink
Add Switch.version.emummc to determine if Atmosphère is running fro…
Browse files Browse the repository at this point in the history
…m emuMMC or sysMMC
  • Loading branch information
TooTallNate committed Jun 24, 2024
1 parent 1b5d56e commit b526c8e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/red-rocks-teach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"nxjs-runtime": patch
---

Add `Switch.version.emummc` to determine if Atmosphère is running from emuMMC or sysMMC
4 changes: 4 additions & 0 deletions packages/runtime/src/switch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ export interface Versions {
*/
ams: string | undefined;
cairo: string;
/**
* `true` if the Switch is running Atmosphère from emuMMC, `false` if running sysMMC, or `undefined` if not running Atmosphère.
*/
emummc: boolean | undefined;
freetype2: string;
harfbuzz: string;
hos: string;
Expand Down
24 changes: 24 additions & 0 deletions source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,29 @@ static JSValue nx_version_get_ams(JSContext *ctx, JSValueConst this_val, int arg
return JS_NewString(ctx, version_str);
}

static JSValue nx_version_get_emummc(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv)
{
if (!hosversionIsAtmosphere())
{
return JS_UNDEFINED;
}

nx_context_t *nx_ctx = JS_GetContextOpaque(ctx);
if (!nx_ctx->spl_initialized)
{
nx_ctx->spl_initialized = true;
splInitialize();
}

u64 is_emummc;
Result rc = splGetConfig((SplConfigItem)65007, &is_emummc);
if (R_FAILED(rc))
{
return nx_throw_libnx_error(ctx, rc, "splGetConfig(ExosphereEmummcType)");
}
return JS_NewBool(ctx, is_emummc ? true : false);
}

int nx_module_set_import_meta(JSContext *ctx, JSValueConst func_val,
const char *url, JS_BOOL is_main)
{
Expand Down Expand Up @@ -632,6 +655,7 @@ int main(int argc, char *argv[])
JSValue version_obj = JS_NewObject(ctx);
NX_DEF_GET_(version_obj, "ams", nx_version_get_ams, JS_PROP_C_W_E);
JS_SetPropertyStr(ctx, version_obj, "cairo", JS_NewString(ctx, cairo_version_string()));
NX_DEF_GET_(version_obj, "emummc", nx_version_get_emummc, JS_PROP_C_W_E);
JS_SetPropertyStr(ctx, version_obj, "freetype2", JS_NewString(ctx, FREETYPE_VERSION_STR));
JS_SetPropertyStr(ctx, version_obj, "harfbuzz", JS_NewString(ctx, HB_VERSION_STRING));
u32 hos_version = hosversionGet();
Expand Down

0 comments on commit b526c8e

Please sign in to comment.