const bridgeMod = require('../utils/euv-bridge');
let wasmGlue = null;
try {
wasmGlue = require('../utils/euv_wasm_glue');
} catch (_e) {}
Page({
state: {
bridge: null,
canvas: null
},
build() {
const devInfo = (typeof hmSetting !== 'undefined' && hmSetting.getDeviceInfo) ? hmSetting.getDeviceInfo() : {};
const w = Number(devInfo.width || 480);
const h = Number(devInfo.height || 480);
const shape = devInfo.screenShape === 0 ? 'squircle' : 'round';
if (typeof hmUI !== 'undefined' && hmUI.createWidget) {
this.state.canvas = hmUI.createWidget(hmUI.widget.CANVAS, { x: 0, y: 0, w, h });
}
this.state.bridge = bridgeMod.createWearableBridge({}, wasmGlue);
if (this.state.canvas) {
this.state.bridge.mount(this.state.canvas, { shape, width: w, height: h, dpr: 2.0 });
}
if (typeof hmApp !== 'undefined' && hmApp.registerSpinEvent) {
hmApp.registerSpinEvent((_key, degree) => {
if (this.state.bridge && degree) {
this.state.bridge.dispatchCrown(degree / 30.0, 0);
}
return true;
});
}
if (typeof hmApp !== 'undefined' && hmApp.registerKeyEvent) {
hmApp.registerKeyEvent((key, action) => {
if (action === 1 && this.state.bridge) {
this.state.bridge.dispatchGesture(4);
}
return false;
});
}
},
onDestroy() {
if (this.state.bridge) {
this.state.bridge.dispatchLifecycle(4);
this.state.bridge.destroy();
this.state.bridge = null;
}
}
});