Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

feat(native): a native build names its device when it connects

esenginee02284dede6a
diff --git a/CHANGELOG.md b/CHANGELOG.md
index efaa2ff02..fe95a024d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,7 @@ published separately; it ships inside the editor.
### Added
+- A native development build names its device to the editor — `macOS · Mac16,10`, `Android · Pixel 8` — as web and mini-game builds already did.
- A desktop (native) development build connects to the editor like a web or mini-game one — log, profiler, the world, content status, pause and step; its renderer cannot capture frames yet and says so. The native host gained a `ws://` client for it.
- Profiling a connected development build, the Profiler shows which content revision it runs, the one its next launch starts on, and a hot update it has found but not applied; `device_update_status` answers the same for an agent.
- The build's size report shows the start screen on its own line — the markup and any logo inlined into index.html, which is on screen before anything else loads.
diff --git a/desktop b/desktop
index 52aeac925..922145ec6 160000
--- a/desktop
+++ b/desktop
@@ -1 +1 @@
-Subproject commit 52aeac925b56e6911c6eba8393c052a17819aab1
+Subproject commit 922145ec6ced6a65c0c7495a6a81d1dd4e412c66
diff --git a/native/CMakeLists.txt b/native/CMakeLists.txt
index c92b5b771..8a8e6bc89 100644
--- a/native/CMakeLists.txt
+++ b/native/CMakeLists.txt
@@ -326,6 +326,7 @@ if(ESTELLA_QUICKJS_DIR)
# a phone's keyboard IS one, so there is nothing here for it to be.
$<$<BOOL:${ESTELLA_DESKTOP}>:host/media/text_edit.cpp>
host/bindings/NetBindings.cpp
+ host/bindings/DeviceBindings.cpp
host/net/WsClient.cpp
host/bindings/TextEditorBindings.cpp
host/bindings/AotBindings.cpp
diff --git a/native/host/Bindings.hpp b/native/host/Bindings.hpp
index 9a61bb971..9d8dd6491 100644
--- a/native/host/Bindings.hpp
+++ b/native/host/Bindings.hpp
@@ -58,6 +58,7 @@ void registerSteamBindings(HostState& h, JSValue global);
/** es_fetch over the platform's native networking. */
void registerNetBindings(HostState& h, JSValue global);
+void registerDeviceBindings(HostState& h, JSValue global);
/** es_aot_* — the compiled systems a shipped build loads, and the naming a
* host does for them. Absent on the web, where the module shares the engine's
diff --git a/native/host/Runtime.cpp b/native/host/Runtime.cpp
index d586b56a2..bf1d2b59d 100644
--- a/native/host/Runtime.cpp
+++ b/native/host/Runtime.cpp
@@ -425,6 +425,7 @@ void initRuntime(HostState& h) {
registerAotBindings(h, global);
#endif
registerNetBindings(h, global);
+ registerDeviceBindings(h, global);
registerTextEditorBindings(h, global);
// The generated halves: per-component accessors, then the engine's binding
diff --git a/native/host/bindings/DeviceBindings.cpp b/native/host/bindings/DeviceBindings.cpp
new file mode 100644
index 000000000..09afcedfb
--- /dev/null
+++ b/native/host/bindings/DeviceBindings.cpp
@@ -0,0 +1,66 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file DeviceBindings.cpp
+ * @brief es_deviceName: what a person would call this device in a list — the
+ * name a development build gives the editor when it connects.
+ */
+#include "Bindings.hpp"
+
+#include <string>
+
+#if defined(__ANDROID__)
+# include <sys/system_properties.h>
+#elif defined(__APPLE__)
+# include <TargetConditionals.h>
+# include <sys/sysctl.h>
+# include <sys/utsname.h>
+#elif defined(_WIN32)
+# ifndef WIN32_LEAN_AND_MEAN
+# define WIN32_LEAN_AND_MEAN
+# endif
+# include <windows.h>
+#else
+# include <fstream>
+#endif
+
+namespace eshost {
+namespace {
+
+std::string deviceName() {
+#if defined(__ANDROID__)
+ char model[PROP_VALUE_MAX] = {0};
+ __system_property_get("ro.product.model", model);
+ return std::string("Android · ") + model;
+#elif defined(__APPLE__) && TARGET_OS_IPHONE
+ utsname u{};
+ uname(&u);
+ return std::string("iOS · ") + u.machine;
+#elif defined(__APPLE__)
+ char model[128] = {0};
+ size_t len = sizeof model;
+ sysctlbyname("hw.model", model, &len, nullptr, 0);
+ return std::string("macOS · ") + model;
+#elif defined(_WIN32)
+ char name[MAX_COMPUTERNAME_LENGTH + 1] = {0};
+ DWORD len = sizeof name;
+ GetComputerNameA(name, &len);
+ return std::string("Windows · ") + name;
+#else
+ std::string product;
+ std::ifstream("/sys/devices/virtual/dmi/id/product_name") >> product;
+ return "Linux" + (product.empty() ? std::string() : " · " + product);
+#endif
+}
+
+JSValue js_deviceName(JSContext* ctx, JSValueConst, int, JSValueConst*) {
+ return JS_NewString(ctx, deviceName().c_str());
+}
+
+} // namespace
+
+void registerDeviceBindings(HostState& h, JSValue global) {
+ bindGlobal(h, global, "es_deviceName", js_deviceName, 0);
+}
+
+} // namespace eshost
diff --git a/sdk/etc/index.native.api.md b/sdk/etc/index.native.api.md
index aba9aa5f9..3f477783e 100644
--- a/sdk/etc/index.native.api.md
+++ b/sdk/etc/index.native.api.md
@@ -5217,6 +5217,7 @@ value: string
## NativeBridge — interface @beta
```
audio: NativeAudioBridge | undefined
+deviceName: (() => string) | undefined
devicePixelRatio: () => number
fetch: (url: string, options?: PlatformRequestOptions) => Promise<NativeFetchResult>
fileExists: (path: string) => Promise<boolean>
@@ -5290,6 +5291,7 @@ es_audioStop: ((voiceId: number) => void) | undefined
es_audioSuspendAll: (() => void) | undefined
es_audioUnload: ((bufferId: number) => void) | undefined
es_audioVoiceState: ((voiceId: number) => { playing: boolean; currentTime: number; } | null) | undefined
+es_deviceName: (() => string) | undefined
es_devicePixelRatio: (() => number) | undefined
es_fetch: ((request: { url: string; method?: string; headers?: Record<string, string>; body?: string | ArrayBuffer; responseType?: string; }, callback: (result: { ok: boolean; status: number; statusText: string; headers: Record<string, string>; arrayBuffer?: ArrayBuffer; text?: string; error?: string; }) => void) => void) | undefined
es_getStorageItem: ((key: string) => string | null) | undefined
@@ -5353,6 +5355,7 @@ createImage: () => PlatformImage
createSocket: (options: PlatformSocketOptions) => PlatformSocket
createTextEditor: () => PlatformTextEditor | null
createVideoBackend: (ctx: VideoBackendContext) => PlatformVideoBackend
+deviceName: () => string
devicePixelRatio: () => number
fetch: (url: string, options?: PlatformRequestOptions) => Promise<PlatformResponse>
fileExists: (path: string) => Promise<boolean>
diff --git a/sdk/src/platform/native/adapter.ts b/sdk/src/platform/native/adapter.ts
index 26b8f0042..b18411dda 100644
--- a/sdk/src/platform/native/adapter.ts
+++ b/sdk/src/platform/native/adapter.ts
@@ -278,6 +278,10 @@ export class NativePlatformAdapter implements PlatformAdapter {
return () => { live = false; };
}
+ deviceName(): string {
+ return this.bridge_.deviceName?.() ?? '';
+ }
+
createSocket(options: PlatformSocketOptions): PlatformSocket {
const socket = this.bridge_.socket;
if (!socket) throw new Error('this native host carries no socket client');
diff --git a/sdk/src/platform/native/bridge.ts b/sdk/src/platform/native/bridge.ts
index 1b6aed8af..9b69a5708 100644
--- a/sdk/src/platform/native/bridge.ts
+++ b/sdk/src/platform/native/bridge.ts
@@ -226,6 +226,9 @@ export interface NativeBridge {
* Null backend. See {@link NativeAudioBridge}. */
audio?: NativeAudioBridge;
+ /** What the device is called in a list (system and model), when the host says. */
+ deviceName?(): string;
+
/** `ws://` sockets, on a host that carries the client. Absent → `createSocket`
* is unavailable, as it is on a host with no network. */
socket?: NativeSocketBridge;
diff --git a/sdk/src/platform/native/hostBridge.ts b/sdk/src/platform/native/hostBridge.ts
index 0461300e6..375f5b44f 100644
--- a/sdk/src/platform/native/hostBridge.ts
+++ b/sdk/src/platform/native/hostBridge.ts
@@ -106,6 +106,9 @@ export interface NativeHostBindings {
}) => void,
): void;
+ /** What the device is called in a list: its system and model. */
+ es_deviceName?(): string;
+
/** The host's `ws://` client: events arrive on the JS thread, `close` last. */
es_wsOpen?(url: string, onEvent: (event: NativeSocketEvent) => void): number;
es_wsSend?(id: number, data: string | ArrayBuffer): boolean;
@@ -195,6 +198,7 @@ export function createHostBridge(
},
fileExists: (path) => Promise.resolve(bindings.es_readAsset(path) != null),
fetch: (url, options) => hostFetch(bindings, url, options),
+ ...(bindings.es_deviceName ? { deviceName: () => bindings.es_deviceName!() } : {}),
...(bindings.es_wsOpen && bindings.es_wsSend && bindings.es_wsClose ? {
socket: {
open: (url, onEvent) => {
diff --git a/sdk/tests/native-host-bridge.test.ts b/sdk/tests/native-host-bridge.test.ts
index 56df6dfc1..4e8b2d812 100644
--- a/sdk/tests/native-host-bridge.test.ts
+++ b/sdk/tests/native-host-bridge.test.ts
@@ -325,3 +325,24 @@ describe('a CDN image on a native build', () => {
expect(load).toHaveBeenCalledWith('assets/hero.png');
});
});
+
+describe('the host bridge names its device and carries its socket client', () => {
+ it('passes both through when the host binds them', () => {
+ const opened: string[] = [];
+ const bridge = createHostBridge(hostScope({
+ es_deviceName: () => 'Android · Pixel 8',
+ es_wsOpen: (url: string) => { opened.push(url); return 7; },
+ es_wsSend: () => true,
+ es_wsClose: () => {},
+ }) as never);
+ expect(bridge.deviceName?.()).toBe('Android · Pixel 8');
+ bridge.socket!.open('ws://editor:1/', () => {});
+ expect(opened).toEqual(['ws://editor:1/']);
+ });
+
+ it('leaves both out on a host that binds neither', () => {
+ const bridge = createHostBridge(hostScope() as never);
+ expect(bridge.deviceName).toBeUndefined();
+ expect(bridge.socket).toBeUndefined();
+ });
+});
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index 9b1683a53..182098da6 100644
--- a/tools/releaseNotes.mjs
+++ b/tools/releaseNotes.mjs
@@ -1132,4 +1132,6 @@ export const NOTED = {
{ note: 'A desktop (native) development build connects to the editor like a web or mini-game one — log, profiler, the world, content status, pause and step; its renderer cannot capture frames yet and says so. The native host gained a `ws://` client for it.' },
'fix(android): a native Android app can reach the network':
{ note: 'A native Android app can reach the network: its manifest never asked for it, so a remote group\'s assets, hot updates and the debug channel all failed on Android. A development build also allows plain http (a LAN CDN); a shipping build is held to https, and the export warns when its CDN is http.' },
+ 'feat(native): a native build names its device when it connects':
+ { note: 'A native development build names its device to the editor — `macOS · Mac16,10`, `Android · Pixel 8` — as web and mini-game builds already did.' },
};