<template>
<div class="watch-root">
<canvas
id="euv-blueos-canvas"
class="watch-canvas"
ontouchstart="onTouchStart"
ontouchmove="onTouchMove"
ontouchend="onTouchEnd"
ontouchcancel="onTouchCancel"
></canvas>
</div>
</template>
<style>
.watch-root {
width: 466px;
height: 466px;
background-color: #09090b;
}
.watch-canvas {
width: 466px;
height: 466px;
}
</style>
<script>
import rotary from '@blueos.rotary';
import vibrator from '@blueos.vibrator';
import display from '@blueos.display';
import storage from '@system.storage';
import router from '@system.router';
import euvWasmGlue from '../../common/euv_wasm_glue.js';
import createWearableBridge from '../../common/euv-bridge.js';
export default {
private: {
bridge: null
},
onReady() {
const canvas = this.$element('euv-blueos-canvas');
this.bridge = createWearableBridge({ vibrator, storage, router }, euvWasmGlue);
const boot = (info) => {
const w = Number((info && info.width) || 466);
const h = Number((info && info.height) || 466);
const shape = w === h ? 'round' : 'squircle';
this.bridge.mount(canvas, { shape, width: w, height: h, dpr: 2.0 });
};
if (display && typeof display.getInfo === 'function') {
display.getInfo({ success: boot, fail: () => boot(null) });
} else {
boot(null);
}
if (rotary && typeof rotary.subscribe === 'function') {
rotary.subscribe({
callback: (ev) => {
const delta = Number((ev && (ev.delta || ev.step)) || 0);
if (this.bridge && delta !== 0) this.bridge.dispatchCrown(delta, 0);
}
});
}
if (display && typeof display.onAmbientModeChange === 'function') {
display.onAmbientModeChange({
callback: (ev) => {
if (this.bridge) this.bridge.setAmbient(Boolean(ev && ev.ambient));
}
});
}
},
onShow() {
if (this.bridge) this.bridge.dispatchLifecycle(2);
},
onHide() {
if (this.bridge) this.bridge.dispatchLifecycle(3);
},
onDestroy() {
if (rotary && typeof rotary.unsubscribe === 'function') rotary.unsubscribe();
if (this.bridge) {
this.bridge.dispatchLifecycle(4);
this.bridge.destroy();
this.bridge = null;
}
},
onTouchStart(e) {
if (this.bridge) this.bridge.dispatchTouch(0, e);
},
onTouchMove(e) {
if (this.bridge) this.bridge.dispatchTouch(1, e);
},
onTouchEnd(e) {
if (this.bridge) this.bridge.dispatchTouch(2, e);
},
onTouchCancel(e) {
if (this.bridge) this.bridge.dispatchTouch(3, e);
}
};
</script>