rvis-aiui-kit 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -19,4 +19,4 @@ import glass3 from 'rvis-aiui-kit';
19
19
  }
20
20
  ```
21
21
 
22
- Available component exports: `rvis-aiui-kit/image`, `rvis-aiui-kit/list`, `rvis-aiui-kit/markdown`, `rvis-aiui-kit/model-list`, `rvis-aiui-kit/paragraph`, `rvis-aiui-kit/table`.
22
+ Available component exports: `rvis-aiui-kit/image`, `rvis-aiui-kit/list`, `rvis-aiui-kit/markdown`, `rvis-aiui-kit/model-list`, `rvis-aiui-kit/paragraph`, `rvis-aiui-kit/status-bar`, `rvis-aiui-kit/table`.
@@ -0,0 +1,139 @@
1
+ <script def>
2
+ {
3
+ "component": true
4
+ }
5
+ </script>
6
+
7
+ <script setup>
8
+ import glass3 from 'rvis-aiui-kit';
9
+
10
+ function logError(error) {
11
+ if (error && error.code === 'CALL_DISPOSED') return;
12
+ console.error('[Status Bar]', error);
13
+ }
14
+
15
+ export default {
16
+ properties: {
17
+ title: {
18
+ type: String,
19
+ value: ''
20
+ }
21
+ },
22
+
23
+ data: {
24
+ dateText: '',
25
+ timeText: '',
26
+ batteryText: '--%',
27
+ active: false,
28
+ clockTimer: null,
29
+ powerObserveRequestId: ''
30
+ },
31
+
32
+ methods: {
33
+ updateTime() {
34
+ const now = new Date();
35
+ const hours = now.getHours();
36
+ const minutes = now.getMinutes();
37
+ this.setData({
38
+ dateText: `${now.getMonth() + 1}/${now.getDate()}`,
39
+ timeText: `${hours < 10 ? '0' : ''}${hours}:${minutes < 10 ? '0' : ''}${minutes}`
40
+ });
41
+ },
42
+
43
+ updateBattery(event) {
44
+ if (!this.data.active) return;
45
+ if (event.eventType === 'invalidated') {
46
+ this.data.powerObserveRequestId = '';
47
+ this.setData({ batteryText: '--%' });
48
+ return;
49
+ }
50
+
51
+ const power = event.eventType === 'snapshot'
52
+ ? event.snapshot && event.snapshot.power
53
+ : event.patch && event.patch.power;
54
+ if (!power) return;
55
+
56
+ this.setData({
57
+ batteryText: power.levelPercent === undefined
58
+ ? '--%'
59
+ : `${power.levelPercent}%`
60
+ });
61
+ },
62
+
63
+ observePower() {
64
+ glass3.deviceContext.observe(
65
+ { domains: ['power'] },
66
+ { onEvent: event => this.updateBattery(event) }
67
+ ).then(result => {
68
+ if (this.data.active) {
69
+ this.data.powerObserveRequestId = result.requestId;
70
+ return;
71
+ }
72
+
73
+ glass3.deviceContext.stopObserve({
74
+ requestId: result.requestId
75
+ }).catch(logError);
76
+ }).catch(logError);
77
+ }
78
+ },
79
+
80
+ lifetimes: {
81
+ attached() {
82
+ this.data.active = true;
83
+ this.updateTime();
84
+ this.data.clockTimer = setInterval(() => this.updateTime(), 1000);
85
+ this.observePower();
86
+ },
87
+
88
+ detached() {
89
+ this.data.active = false;
90
+
91
+ if (this.data.clockTimer !== null) {
92
+ clearInterval(this.data.clockTimer);
93
+ this.data.clockTimer = null;
94
+ }
95
+ if (this.data.powerObserveRequestId) {
96
+ glass3.deviceContext.stopObserve({
97
+ requestId: this.data.powerObserveRequestId
98
+ }).catch(logError);
99
+ this.data.powerObserveRequestId = '';
100
+ }
101
+ }
102
+ }
103
+ };
104
+ </script>
105
+
106
+ <page>
107
+ <view class="status-bar">
108
+ <text class="status-text">{{ title }}</text>
109
+ <view class="status-right">
110
+ <text class="status-text">{{ dateText }}</text>
111
+ <text class="status-text">{{ timeText }}</text>
112
+ <text class="status-text">{{ batteryText }}</text>
113
+ </view>
114
+ </view>
115
+ </page>
116
+
117
+ <style>
118
+ .status-bar {
119
+ display: flex;
120
+ flex-direction: row;
121
+ align-items: center;
122
+ justify-content: space-between;
123
+ width: 480px;
124
+ height: 20px;
125
+ }
126
+
127
+ .status-right {
128
+ display: flex;
129
+ flex-direction: row;
130
+ align-items: center;
131
+ gap: 10px;
132
+ }
133
+
134
+ .status-text {
135
+ color: #40ff5e;
136
+ font-size: 14px;
137
+ line-height: 20px;
138
+ }
139
+ </style>
@@ -0,0 +1,45 @@
1
+ # Status Bar 组件
2
+
3
+ 标准 Glass3 HUD 状态栏,左侧显示应用标题,右侧显示本地月/日、时间和实时电量。
4
+
5
+ 组件会在 `attached` 时启动时钟和 `power` 订阅,在 `detached` 时清理计时器并停止订阅。
6
+
7
+ ## 注册与使用
8
+
9
+ ```json
10
+ {
11
+ "usingComponents": {
12
+ "rvis-status-bar": "rvis-aiui-kit/status-bar"
13
+ }
14
+ }
15
+ ```
16
+
17
+ ```html
18
+ <rvis-status-bar title="应用名称"></rvis-status-bar>
19
+ ```
20
+
21
+ 属性:
22
+
23
+ - `title: String`,默认 `''`,显示在状态栏左侧。
24
+
25
+ 组件固定为 `480px × 20px`,使用 `14px / 20px` 的绿色文本;页面负责将它放在全屏绘制区域的 `(0, 0)`。
26
+
27
+ ## Host 消息转发
28
+
29
+ Ink 当前只把 Host 消息交给 Page,不会直接调用自定义组件的 `onMessage`。使用该组件的页面必须把消息转发到与组件共享的 `glass3` 单例:
30
+
31
+ ```js
32
+ import glass3 from 'rvis-aiui-kit';
33
+
34
+ export default {
35
+ onMessage(messageEvent) {
36
+ glass3.handleMessage(messageEvent);
37
+ },
38
+
39
+ onUnload() {
40
+ glass3.dispose();
41
+ }
42
+ };
43
+ ```
44
+
45
+ 除这条 Page 级消息入口外,时间刷新、电量显示、订阅和清理逻辑均由组件管理。电量不可读时显示 `--%`。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rvis-aiui-kit",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "RVIS AIUI components and Glass3 extension SDK.",
5
5
  "type": "module",
6
6
  "main": "./sdk/index.js",
@@ -18,6 +18,7 @@
18
18
  "./markdown": "./components/markdown/index",
19
19
  "./model-list": "./components/model-list/index",
20
20
  "./paragraph": "./components/paragraph/index",
21
+ "./status-bar": "./components/status-bar/index",
21
22
  "./table": "./components/table/index"
22
23
  }
23
24
  },