diff --git a/src/common/bridge.js b/src/common/bridge.js index 261ad4b..58bdcae 100644 --- a/src/common/bridge.js +++ b/src/common/bridge.js @@ -1,8 +1,21 @@ // DSHWatch bridge: @system.interconnect wrapper. // Sends/receives JSON envelopes to the DSHWatch phone APP over the Vela BLE channel. -// Protocol per DSHWatch_Server/docs/PROTOCOL.md. +// The interconnect module is loaded lazily (guarded) so the app can still render +// on simulators/environments where the system module is unavailable. -import interconnect from '@system.interconnect' +let interconnectModule = null; +let interconnectTried = false; + +function loadInterconnect() { + if (interconnectTried) return interconnectModule; + interconnectTried = true; + try { + interconnectModule = require('@system.interconnect'); + } catch (e) { + interconnectModule = null; + } + return interconnectModule; +} let conn = null let seq = 0 @@ -10,6 +23,8 @@ const listeners = new Set() let currentStatus = '未连接' function getConn() { + const interconnect = loadInterconnect(); + if (!interconnect) return null; if (!conn) { try { conn = interconnect.instance() @@ -29,7 +44,6 @@ function getConn() { emit('status', currentStatus) } conn.onmessage = (data) => { - // interconnect 回调: data.data 是手机端发来的内容 let msg = data && data.data !== undefined ? data.data : data if (typeof msg === 'string') { try { msg = JSON.parse(msg) } catch (e) { return }