assistsx-js 0.1.29 → 0.1.31

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.
@@ -38,11 +38,19 @@ export type AccessibilityEventListener = (event: AccessibilityEvent) => void;
38
38
  export interface WebFloatingWindowOptions {
39
39
  initialWidth?: number;
40
40
  initialHeight?: number;
41
+ /** Initial window X position (default 0) */
42
+ initialX?: number;
43
+ /** Initial window Y position (default 0) */
44
+ initialY?: number;
41
45
  minWidth?: number;
42
46
  minHeight?: number;
43
47
  maxWidth?: number;
44
48
  maxHeight?: number;
45
49
  initialCenter?: boolean;
50
+ /** Whether to show top operation area (title bar, close button, etc.) */
51
+ showTopOperationArea?: boolean;
52
+ /** Whether to show bottom operation area (zoom, back/forward/refresh, etc.) */
53
+ showBottomOperationArea?: boolean;
46
54
  }
47
55
  export declare const callbacks: Map<string, (data: string) => void>;
48
56
  export declare const accessibilityEventListeners: AccessibilityEventListener[];
package/dist/AssistsX.js CHANGED
@@ -240,17 +240,21 @@ export class AssistsX {
240
240
  return data.value;
241
241
  }
242
242
  static async loadWebViewOverlay(url, options = {}) {
243
- const { initialWidth, initialHeight, minWidth, minHeight, maxWidth, maxHeight, initialCenter, timeout, } = options;
243
+ const { initialWidth, initialHeight, initialX, initialY, minWidth, minHeight, maxWidth, maxHeight, initialCenter, showTopOperationArea, showBottomOperationArea, timeout, } = options;
244
244
  const response = await this.asyncCall(CallMethod.loadWebViewOverlay, {
245
245
  args: {
246
246
  url,
247
247
  initialWidth,
248
248
  initialHeight,
249
+ initialX,
250
+ initialY,
249
251
  minWidth,
250
252
  minHeight,
251
253
  maxWidth,
252
254
  maxHeight,
253
255
  initialCenter,
256
+ showTopOperationArea,
257
+ showBottomOperationArea,
254
258
  },
255
259
  timeout,
256
260
  });
@@ -203,17 +203,21 @@ export class AssistsXAsync {
203
203
  return data.value;
204
204
  }
205
205
  static async loadWebViewOverlay(url, options = {}) {
206
- const { initialWidth, initialHeight, minWidth, minHeight, maxWidth, maxHeight, initialCenter, timeout, } = options;
206
+ const { initialWidth, initialHeight, initialX, initialY, minWidth, minHeight, maxWidth, maxHeight, initialCenter, showTopOperationArea, showBottomOperationArea, timeout, } = options;
207
207
  const response = await this.asyncCall(CallMethod.loadWebViewOverlay, {
208
208
  args: {
209
209
  url,
210
210
  initialWidth,
211
211
  initialHeight,
212
+ initialX,
213
+ initialY,
212
214
  minWidth,
213
215
  minHeight,
214
216
  maxWidth,
215
217
  maxHeight,
216
218
  initialCenter,
219
+ showTopOperationArea,
220
+ showBottomOperationArea,
217
221
  },
218
222
  timeout,
219
223
  });
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Bar utils (status bar, nav bar, action bar) method constants.
3
+ * Matches BarUtilsCallMethod in Kotlin.
4
+ */
5
+ export declare const BarUtilsCallMethod: {
6
+ readonly getStatusBarHeight: "getStatusBarHeight";
7
+ readonly setStatusBarVisibility: "setStatusBarVisibility";
8
+ readonly isStatusBarVisible: "isStatusBarVisible";
9
+ readonly setStatusBarLightMode: "setStatusBarLightMode";
10
+ readonly isStatusBarLightMode: "isStatusBarLightMode";
11
+ readonly setStatusBarColor: "setStatusBarColor";
12
+ readonly transparentStatusBar: "transparentStatusBar";
13
+ readonly getActionBarHeight: "getActionBarHeight";
14
+ readonly getNavBarHeight: "getNavBarHeight";
15
+ readonly setNavBarVisibility: "setNavBarVisibility";
16
+ readonly isNavBarVisible: "isNavBarVisible";
17
+ readonly setNavBarColor: "setNavBarColor";
18
+ readonly getNavBarColor: "getNavBarColor";
19
+ readonly isSupportNavBar: "isSupportNavBar";
20
+ readonly setNavBarLightMode: "setNavBarLightMode";
21
+ readonly isNavBarLightMode: "isNavBarLightMode";
22
+ readonly transparentNavBar: "transparentNavBar";
23
+ };
24
+ export type BarUtilsCallMethodType = (typeof BarUtilsCallMethod)[keyof typeof BarUtilsCallMethod];
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Bar utils (status bar, nav bar, action bar) method constants.
3
+ * Matches BarUtilsCallMethod in Kotlin.
4
+ */
5
+ export const BarUtilsCallMethod = {
6
+ // Status bar
7
+ getStatusBarHeight: "getStatusBarHeight",
8
+ setStatusBarVisibility: "setStatusBarVisibility",
9
+ isStatusBarVisible: "isStatusBarVisible",
10
+ setStatusBarLightMode: "setStatusBarLightMode",
11
+ isStatusBarLightMode: "isStatusBarLightMode",
12
+ setStatusBarColor: "setStatusBarColor",
13
+ transparentStatusBar: "transparentStatusBar",
14
+ // ActionBar
15
+ getActionBarHeight: "getActionBarHeight",
16
+ // Nav bar
17
+ getNavBarHeight: "getNavBarHeight",
18
+ setNavBarVisibility: "setNavBarVisibility",
19
+ isNavBarVisible: "isNavBarVisible",
20
+ setNavBarColor: "setNavBarColor",
21
+ getNavBarColor: "getNavBarColor",
22
+ isSupportNavBar: "isSupportNavBar",
23
+ setNavBarLightMode: "setNavBarLightMode",
24
+ isNavBarLightMode: "isNavBarLightMode",
25
+ transparentNavBar: "transparentNavBar",
26
+ };
@@ -0,0 +1,41 @@
1
+ export declare class BarUtils {
2
+ private asyncCall;
3
+ private errorMessage;
4
+ /** Get status bar height in px. */
5
+ getStatusBarHeight(timeout?: number): Promise<number>;
6
+ /** Set status bar visibility. */
7
+ setStatusBarVisibility(isVisible?: boolean, timeout?: number): Promise<void>;
8
+ /** Check if status bar is visible. */
9
+ isStatusBarVisible(timeout?: number): Promise<boolean>;
10
+ /** Set status bar light mode (light content on dark background). */
11
+ setStatusBarLightMode(isLightMode?: boolean, timeout?: number): Promise<void>;
12
+ /** Check if status bar is in light mode. */
13
+ isStatusBarLightMode(timeout?: number): Promise<boolean>;
14
+ /** Set status bar color. color: Android color int (e.g. 0xff0000). isDecor: whether to apply to decor. */
15
+ setStatusBarColor(color: number, options?: {
16
+ isDecor?: boolean;
17
+ }, timeout?: number): Promise<void>;
18
+ /** Make status bar transparent. */
19
+ transparentStatusBar(timeout?: number): Promise<void>;
20
+ /** Get action bar height in px. */
21
+ getActionBarHeight(timeout?: number): Promise<number>;
22
+ /** Get navigation bar height in px. */
23
+ getNavBarHeight(timeout?: number): Promise<number>;
24
+ /** Set navigation bar visibility. */
25
+ setNavBarVisibility(isVisible?: boolean, timeout?: number): Promise<void>;
26
+ /** Check if navigation bar is visible. */
27
+ isNavBarVisible(timeout?: number): Promise<boolean>;
28
+ /** Set navigation bar color. color: Android color int. */
29
+ setNavBarColor(color: number, timeout?: number): Promise<void>;
30
+ /** Get current navigation bar color. */
31
+ getNavBarColor(timeout?: number): Promise<number>;
32
+ /** Check if device supports navigation bar. */
33
+ isSupportNavBar(timeout?: number): Promise<boolean>;
34
+ /** Set navigation bar light mode. */
35
+ setNavBarLightMode(isLightMode?: boolean, timeout?: number): Promise<void>;
36
+ /** Check if navigation bar is in light mode. */
37
+ isNavBarLightMode(timeout?: number): Promise<boolean>;
38
+ /** Make navigation bar transparent. */
39
+ transparentNavBar(timeout?: number): Promise<void>;
40
+ }
41
+ export declare const barUtils: BarUtils;
@@ -0,0 +1,205 @@
1
+ /**
2
+ * Bar utils (status bar, nav bar, action bar) for WebView.
3
+ * Requires Activity context on native side. Matches BarUtilsJavascriptInterface.kt.
4
+ */
5
+ import { CallResponse } from "../CallResponse";
6
+ import { decodeBase64UTF8, generateUUID } from "../Utils";
7
+ import { BarUtilsCallMethod } from "./BarUtilsCallMethod";
8
+ const callbacks = new Map();
9
+ if (typeof window !== "undefined" && !window.assistsxBarUtilsCallback) {
10
+ window.assistsxBarUtilsCallback = (data) => {
11
+ let callbackId;
12
+ try {
13
+ const json = decodeBase64UTF8(data);
14
+ const response = JSON.parse(json);
15
+ callbackId = response.callbackId;
16
+ if (callbackId) {
17
+ const callback = callbacks.get(callbackId);
18
+ if (callback) {
19
+ callback(json);
20
+ }
21
+ }
22
+ }
23
+ catch (e) {
24
+ console.error("BarUtils callback error:", e);
25
+ }
26
+ finally {
27
+ if (callbackId) {
28
+ callbacks.delete(callbackId);
29
+ }
30
+ }
31
+ };
32
+ }
33
+ export class BarUtils {
34
+ async asyncCall(method, args, timeout = 30) {
35
+ const uuid = generateUUID();
36
+ const params = {
37
+ method,
38
+ arguments: args !== null && args !== void 0 ? args : undefined,
39
+ callbackId: uuid,
40
+ };
41
+ const promise = new Promise((resolve) => {
42
+ callbacks.set(uuid, (data) => {
43
+ resolve(data);
44
+ });
45
+ setTimeout(() => {
46
+ callbacks.delete(uuid);
47
+ resolve(JSON.stringify(new CallResponse(-1, { message: "Timeout" }, uuid)));
48
+ }, timeout * 1000);
49
+ });
50
+ window.assistsxBarUtils.call(JSON.stringify(params));
51
+ const promiseResult = await promise;
52
+ if (typeof promiseResult === "string") {
53
+ const responseData = JSON.parse(promiseResult);
54
+ const data = responseData.code !== 0 && responseData.message != null
55
+ ? { message: responseData.message }
56
+ : responseData.data;
57
+ return new CallResponse(responseData.code, data, responseData.callbackId);
58
+ }
59
+ throw new Error("BarUtils call failed");
60
+ }
61
+ errorMessage(res, fallback) {
62
+ const d = res.getDataOrNull();
63
+ if (d &&
64
+ typeof d === "object" &&
65
+ typeof d.message === "string") {
66
+ return d.message;
67
+ }
68
+ if (typeof d === "string")
69
+ return d;
70
+ return fallback;
71
+ }
72
+ // --- Status bar ---
73
+ /** Get status bar height in px. */
74
+ async getStatusBarHeight(timeout) {
75
+ const res = await this.asyncCall(BarUtilsCallMethod.getStatusBarHeight, undefined, timeout);
76
+ if (!res.isSuccess()) {
77
+ throw new Error(this.errorMessage(res, "getStatusBarHeight failed"));
78
+ }
79
+ return res.getData().height;
80
+ }
81
+ /** Set status bar visibility. */
82
+ async setStatusBarVisibility(isVisible = true, timeout) {
83
+ const res = await this.asyncCall(BarUtilsCallMethod.setStatusBarVisibility, { isVisible }, timeout);
84
+ if (!res.isSuccess()) {
85
+ throw new Error(this.errorMessage(res, "setStatusBarVisibility failed"));
86
+ }
87
+ }
88
+ /** Check if status bar is visible. */
89
+ async isStatusBarVisible(timeout) {
90
+ const res = await this.asyncCall(BarUtilsCallMethod.isStatusBarVisible, undefined, timeout);
91
+ if (!res.isSuccess()) {
92
+ throw new Error(this.errorMessage(res, "isStatusBarVisible failed"));
93
+ }
94
+ return res.getData().visible;
95
+ }
96
+ /** Set status bar light mode (light content on dark background). */
97
+ async setStatusBarLightMode(isLightMode = true, timeout) {
98
+ const res = await this.asyncCall(BarUtilsCallMethod.setStatusBarLightMode, { isLightMode }, timeout);
99
+ if (!res.isSuccess()) {
100
+ throw new Error(this.errorMessage(res, "setStatusBarLightMode failed"));
101
+ }
102
+ }
103
+ /** Check if status bar is in light mode. */
104
+ async isStatusBarLightMode(timeout) {
105
+ const res = await this.asyncCall(BarUtilsCallMethod.isStatusBarLightMode, undefined, timeout);
106
+ if (!res.isSuccess()) {
107
+ throw new Error(this.errorMessage(res, "isStatusBarLightMode failed"));
108
+ }
109
+ return res.getData().isLightMode;
110
+ }
111
+ /** Set status bar color. color: Android color int (e.g. 0xff0000). isDecor: whether to apply to decor. */
112
+ async setStatusBarColor(color, options, timeout) {
113
+ var _a;
114
+ const res = await this.asyncCall(BarUtilsCallMethod.setStatusBarColor, { color, isDecor: (_a = options === null || options === void 0 ? void 0 : options.isDecor) !== null && _a !== void 0 ? _a : false }, timeout);
115
+ if (!res.isSuccess()) {
116
+ throw new Error(this.errorMessage(res, "setStatusBarColor failed"));
117
+ }
118
+ }
119
+ /** Make status bar transparent. */
120
+ async transparentStatusBar(timeout) {
121
+ const res = await this.asyncCall(BarUtilsCallMethod.transparentStatusBar, undefined, timeout);
122
+ if (!res.isSuccess()) {
123
+ throw new Error(this.errorMessage(res, "transparentStatusBar failed"));
124
+ }
125
+ }
126
+ // --- ActionBar ---
127
+ /** Get action bar height in px. */
128
+ async getActionBarHeight(timeout) {
129
+ const res = await this.asyncCall(BarUtilsCallMethod.getActionBarHeight, undefined, timeout);
130
+ if (!res.isSuccess()) {
131
+ throw new Error(this.errorMessage(res, "getActionBarHeight failed"));
132
+ }
133
+ return res.getData().height;
134
+ }
135
+ // --- Nav bar ---
136
+ /** Get navigation bar height in px. */
137
+ async getNavBarHeight(timeout) {
138
+ const res = await this.asyncCall(BarUtilsCallMethod.getNavBarHeight, undefined, timeout);
139
+ if (!res.isSuccess()) {
140
+ throw new Error(this.errorMessage(res, "getNavBarHeight failed"));
141
+ }
142
+ return res.getData().height;
143
+ }
144
+ /** Set navigation bar visibility. */
145
+ async setNavBarVisibility(isVisible = true, timeout) {
146
+ const res = await this.asyncCall(BarUtilsCallMethod.setNavBarVisibility, { isVisible }, timeout);
147
+ if (!res.isSuccess()) {
148
+ throw new Error(this.errorMessage(res, "setNavBarVisibility failed"));
149
+ }
150
+ }
151
+ /** Check if navigation bar is visible. */
152
+ async isNavBarVisible(timeout) {
153
+ const res = await this.asyncCall(BarUtilsCallMethod.isNavBarVisible, undefined, timeout);
154
+ if (!res.isSuccess()) {
155
+ throw new Error(this.errorMessage(res, "isNavBarVisible failed"));
156
+ }
157
+ return res.getData().visible;
158
+ }
159
+ /** Set navigation bar color. color: Android color int. */
160
+ async setNavBarColor(color, timeout) {
161
+ const res = await this.asyncCall(BarUtilsCallMethod.setNavBarColor, { color }, timeout);
162
+ if (!res.isSuccess()) {
163
+ throw new Error(this.errorMessage(res, "setNavBarColor failed"));
164
+ }
165
+ }
166
+ /** Get current navigation bar color. */
167
+ async getNavBarColor(timeout) {
168
+ const res = await this.asyncCall(BarUtilsCallMethod.getNavBarColor, undefined, timeout);
169
+ if (!res.isSuccess()) {
170
+ throw new Error(this.errorMessage(res, "getNavBarColor failed"));
171
+ }
172
+ return res.getData().color;
173
+ }
174
+ /** Check if device supports navigation bar. */
175
+ async isSupportNavBar(timeout) {
176
+ const res = await this.asyncCall(BarUtilsCallMethod.isSupportNavBar, undefined, timeout);
177
+ if (!res.isSuccess()) {
178
+ throw new Error(this.errorMessage(res, "isSupportNavBar failed"));
179
+ }
180
+ return res.getData().support;
181
+ }
182
+ /** Set navigation bar light mode. */
183
+ async setNavBarLightMode(isLightMode = true, timeout) {
184
+ const res = await this.asyncCall(BarUtilsCallMethod.setNavBarLightMode, { isLightMode }, timeout);
185
+ if (!res.isSuccess()) {
186
+ throw new Error(this.errorMessage(res, "setNavBarLightMode failed"));
187
+ }
188
+ }
189
+ /** Check if navigation bar is in light mode. */
190
+ async isNavBarLightMode(timeout) {
191
+ const res = await this.asyncCall(BarUtilsCallMethod.isNavBarLightMode, undefined, timeout);
192
+ if (!res.isSuccess()) {
193
+ throw new Error(this.errorMessage(res, "isNavBarLightMode failed"));
194
+ }
195
+ return res.getData().isLightMode;
196
+ }
197
+ /** Make navigation bar transparent. */
198
+ async transparentNavBar(timeout) {
199
+ const res = await this.asyncCall(BarUtilsCallMethod.transparentNavBar, undefined, timeout);
200
+ if (!res.isSuccess()) {
201
+ throw new Error(this.errorMessage(res, "transparentNavBar failed"));
202
+ }
203
+ }
204
+ }
205
+ export const barUtils = new BarUtils();
package/dist/index.d.ts CHANGED
@@ -24,3 +24,5 @@ export * from "./imageutils/image-utils";
24
24
  export * from "./gallery/gallery";
25
25
  export * from "./mlkit/mlkit";
26
26
  export * from "./mlkit/MlkitCallMethod";
27
+ export * from "./barutils/bar-utils";
28
+ export * from "./barutils/BarUtilsCallMethod";
package/dist/index.js CHANGED
@@ -24,3 +24,5 @@ export * from "./imageutils/image-utils";
24
24
  export * from "./gallery/gallery";
25
25
  export * from "./mlkit/mlkit";
26
26
  export * from "./mlkit/MlkitCallMethod";
27
+ export * from "./barutils/bar-utils";
28
+ export * from "./barutils/BarUtilsCallMethod";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "assistsx-js",
3
- "version": "0.1.29",
3
+ "version": "0.1.31",
4
4
  "description": "assistsx-js自动化开发SDK",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
package/src/AssistsX.ts CHANGED
@@ -44,11 +44,19 @@ export type AccessibilityEventListener = (event: AccessibilityEvent) => void;
44
44
  export interface WebFloatingWindowOptions {
45
45
  initialWidth?: number;
46
46
  initialHeight?: number;
47
+ /** Initial window X position (default 0) */
48
+ initialX?: number;
49
+ /** Initial window Y position (default 0) */
50
+ initialY?: number;
47
51
  minWidth?: number;
48
52
  minHeight?: number;
49
53
  maxWidth?: number;
50
54
  maxHeight?: number;
51
55
  initialCenter?: boolean;
56
+ /** Whether to show top operation area (title bar, close button, etc.) */
57
+ showTopOperationArea?: boolean;
58
+ /** Whether to show bottom operation area (zoom, back/forward/refresh, etc.) */
59
+ showBottomOperationArea?: boolean;
52
60
  }
53
61
 
54
62
  // 回调函数存储对象
@@ -336,11 +344,15 @@ export class AssistsX {
336
344
  const {
337
345
  initialWidth,
338
346
  initialHeight,
347
+ initialX,
348
+ initialY,
339
349
  minWidth,
340
350
  minHeight,
341
351
  maxWidth,
342
352
  maxHeight,
343
353
  initialCenter,
354
+ showTopOperationArea,
355
+ showBottomOperationArea,
344
356
  timeout,
345
357
  } = options;
346
358
  const response = await this.asyncCall(CallMethod.loadWebViewOverlay, {
@@ -348,11 +360,15 @@ export class AssistsX {
348
360
  url,
349
361
  initialWidth,
350
362
  initialHeight,
363
+ initialX,
364
+ initialY,
351
365
  minWidth,
352
366
  minHeight,
353
367
  maxWidth,
354
368
  maxHeight,
355
369
  initialCenter,
370
+ showTopOperationArea,
371
+ showBottomOperationArea,
356
372
  },
357
373
  timeout,
358
374
  });
@@ -354,11 +354,15 @@ export class AssistsXAsync {
354
354
  const {
355
355
  initialWidth,
356
356
  initialHeight,
357
+ initialX,
358
+ initialY,
357
359
  minWidth,
358
360
  minHeight,
359
361
  maxWidth,
360
362
  maxHeight,
361
363
  initialCenter,
364
+ showTopOperationArea,
365
+ showBottomOperationArea,
362
366
  timeout,
363
367
  } = options;
364
368
  const response = await this.asyncCall(CallMethod.loadWebViewOverlay, {
@@ -366,11 +370,15 @@ export class AssistsXAsync {
366
370
  url,
367
371
  initialWidth,
368
372
  initialHeight,
373
+ initialX,
374
+ initialY,
369
375
  minWidth,
370
376
  minHeight,
371
377
  maxWidth,
372
378
  maxHeight,
373
379
  initialCenter,
380
+ showTopOperationArea,
381
+ showBottomOperationArea,
374
382
  },
375
383
  timeout,
376
384
  });
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Bar utils (status bar, nav bar, action bar) method constants.
3
+ * Matches BarUtilsCallMethod in Kotlin.
4
+ */
5
+ export const BarUtilsCallMethod = {
6
+ // Status bar
7
+ getStatusBarHeight: "getStatusBarHeight",
8
+ setStatusBarVisibility: "setStatusBarVisibility",
9
+ isStatusBarVisible: "isStatusBarVisible",
10
+ setStatusBarLightMode: "setStatusBarLightMode",
11
+ isStatusBarLightMode: "isStatusBarLightMode",
12
+ setStatusBarColor: "setStatusBarColor",
13
+ transparentStatusBar: "transparentStatusBar",
14
+
15
+ // ActionBar
16
+ getActionBarHeight: "getActionBarHeight",
17
+
18
+ // Nav bar
19
+ getNavBarHeight: "getNavBarHeight",
20
+ setNavBarVisibility: "setNavBarVisibility",
21
+ isNavBarVisible: "isNavBarVisible",
22
+ setNavBarColor: "setNavBarColor",
23
+ getNavBarColor: "getNavBarColor",
24
+ isSupportNavBar: "isSupportNavBar",
25
+ setNavBarLightMode: "setNavBarLightMode",
26
+ isNavBarLightMode: "isNavBarLightMode",
27
+ transparentNavBar: "transparentNavBar",
28
+ } as const;
29
+
30
+ export type BarUtilsCallMethodType =
31
+ (typeof BarUtilsCallMethod)[keyof typeof BarUtilsCallMethod];
@@ -0,0 +1,357 @@
1
+ /**
2
+ * Bar utils (status bar, nav bar, action bar) for WebView.
3
+ * Requires Activity context on native side. Matches BarUtilsJavascriptInterface.kt.
4
+ */
5
+ import { CallResponse } from "../CallResponse";
6
+ import { decodeBase64UTF8, generateUUID } from "../Utils";
7
+ import { BarUtilsCallMethod } from "./BarUtilsCallMethod";
8
+
9
+ const callbacks: Map<string, (data: string) => void> = new Map();
10
+
11
+ if (typeof window !== "undefined" && !(window as any).assistsxBarUtilsCallback) {
12
+ (window as any).assistsxBarUtilsCallback = (data: string) => {
13
+ let callbackId: string | undefined;
14
+ try {
15
+ const json = decodeBase64UTF8(data);
16
+ const response = JSON.parse(json);
17
+ callbackId = response.callbackId;
18
+ if (callbackId) {
19
+ const callback = callbacks.get(callbackId);
20
+ if (callback) {
21
+ callback(json);
22
+ }
23
+ }
24
+ } catch (e) {
25
+ console.error("BarUtils callback error:", e);
26
+ } finally {
27
+ if (callbackId) {
28
+ callbacks.delete(callbackId);
29
+ }
30
+ }
31
+ };
32
+ }
33
+
34
+ export class BarUtils {
35
+ private async asyncCall(
36
+ method: string,
37
+ args?: Record<string, unknown>,
38
+ timeout: number = 30
39
+ ): Promise<CallResponse> {
40
+ const uuid = generateUUID();
41
+ const params = {
42
+ method,
43
+ arguments: args ?? undefined,
44
+ callbackId: uuid,
45
+ };
46
+ const promise = new Promise<string>((resolve) => {
47
+ callbacks.set(uuid, (data: string) => {
48
+ resolve(data);
49
+ });
50
+ setTimeout(() => {
51
+ callbacks.delete(uuid);
52
+ resolve(
53
+ JSON.stringify(
54
+ new CallResponse(-1, { message: "Timeout" }, uuid)
55
+ )
56
+ );
57
+ }, timeout * 1000);
58
+ });
59
+ (window as any).assistsxBarUtils.call(JSON.stringify(params));
60
+ const promiseResult = await promise;
61
+ if (typeof promiseResult === "string") {
62
+ const responseData = JSON.parse(promiseResult);
63
+ const data =
64
+ responseData.code !== 0 && responseData.message != null
65
+ ? { message: responseData.message }
66
+ : responseData.data;
67
+ return new CallResponse(
68
+ responseData.code,
69
+ data,
70
+ responseData.callbackId
71
+ );
72
+ }
73
+ throw new Error("BarUtils call failed");
74
+ }
75
+
76
+ private errorMessage(res: CallResponse, fallback: string): string {
77
+ const d = res.getDataOrNull();
78
+ if (
79
+ d &&
80
+ typeof d === "object" &&
81
+ typeof (d as { message?: string }).message === "string"
82
+ ) {
83
+ return (d as { message: string }).message;
84
+ }
85
+ if (typeof d === "string") return d;
86
+ return fallback;
87
+ }
88
+
89
+ // --- Status bar ---
90
+
91
+ /** Get status bar height in px. */
92
+ async getStatusBarHeight(timeout?: number): Promise<number> {
93
+ const res = await this.asyncCall(
94
+ BarUtilsCallMethod.getStatusBarHeight,
95
+ undefined,
96
+ timeout
97
+ );
98
+ if (!res.isSuccess()) {
99
+ throw new Error(this.errorMessage(res, "getStatusBarHeight failed"));
100
+ }
101
+ return (res.getData() as { height: number }).height;
102
+ }
103
+
104
+ /** Set status bar visibility. */
105
+ async setStatusBarVisibility(
106
+ isVisible: boolean = true,
107
+ timeout?: number
108
+ ): Promise<void> {
109
+ const res = await this.asyncCall(
110
+ BarUtilsCallMethod.setStatusBarVisibility,
111
+ { isVisible },
112
+ timeout
113
+ );
114
+ if (!res.isSuccess()) {
115
+ throw new Error(
116
+ this.errorMessage(res, "setStatusBarVisibility failed")
117
+ );
118
+ }
119
+ }
120
+
121
+ /** Check if status bar is visible. */
122
+ async isStatusBarVisible(timeout?: number): Promise<boolean> {
123
+ const res = await this.asyncCall(
124
+ BarUtilsCallMethod.isStatusBarVisible,
125
+ undefined,
126
+ timeout
127
+ );
128
+ if (!res.isSuccess()) {
129
+ throw new Error(
130
+ this.errorMessage(res, "isStatusBarVisible failed")
131
+ );
132
+ }
133
+ return (res.getData() as { visible: boolean }).visible;
134
+ }
135
+
136
+ /** Set status bar light mode (light content on dark background). */
137
+ async setStatusBarLightMode(
138
+ isLightMode: boolean = true,
139
+ timeout?: number
140
+ ): Promise<void> {
141
+ const res = await this.asyncCall(
142
+ BarUtilsCallMethod.setStatusBarLightMode,
143
+ { isLightMode },
144
+ timeout
145
+ );
146
+ if (!res.isSuccess()) {
147
+ throw new Error(
148
+ this.errorMessage(res, "setStatusBarLightMode failed")
149
+ );
150
+ }
151
+ }
152
+
153
+ /** Check if status bar is in light mode. */
154
+ async isStatusBarLightMode(timeout?: number): Promise<boolean> {
155
+ const res = await this.asyncCall(
156
+ BarUtilsCallMethod.isStatusBarLightMode,
157
+ undefined,
158
+ timeout
159
+ );
160
+ if (!res.isSuccess()) {
161
+ throw new Error(
162
+ this.errorMessage(res, "isStatusBarLightMode failed")
163
+ );
164
+ }
165
+ return (res.getData() as { isLightMode: boolean }).isLightMode;
166
+ }
167
+
168
+ /** Set status bar color. color: Android color int (e.g. 0xff0000). isDecor: whether to apply to decor. */
169
+ async setStatusBarColor(
170
+ color: number,
171
+ options?: { isDecor?: boolean },
172
+ timeout?: number
173
+ ): Promise<void> {
174
+ const res = await this.asyncCall(
175
+ BarUtilsCallMethod.setStatusBarColor,
176
+ { color, isDecor: options?.isDecor ?? false },
177
+ timeout
178
+ );
179
+ if (!res.isSuccess()) {
180
+ throw new Error(
181
+ this.errorMessage(res, "setStatusBarColor failed")
182
+ );
183
+ }
184
+ }
185
+
186
+ /** Make status bar transparent. */
187
+ async transparentStatusBar(timeout?: number): Promise<void> {
188
+ const res = await this.asyncCall(
189
+ BarUtilsCallMethod.transparentStatusBar,
190
+ undefined,
191
+ timeout
192
+ );
193
+ if (!res.isSuccess()) {
194
+ throw new Error(
195
+ this.errorMessage(res, "transparentStatusBar failed")
196
+ );
197
+ }
198
+ }
199
+
200
+ // --- ActionBar ---
201
+
202
+ /** Get action bar height in px. */
203
+ async getActionBarHeight(timeout?: number): Promise<number> {
204
+ const res = await this.asyncCall(
205
+ BarUtilsCallMethod.getActionBarHeight,
206
+ undefined,
207
+ timeout
208
+ );
209
+ if (!res.isSuccess()) {
210
+ throw new Error(
211
+ this.errorMessage(res, "getActionBarHeight failed")
212
+ );
213
+ }
214
+ return (res.getData() as { height: number }).height;
215
+ }
216
+
217
+ // --- Nav bar ---
218
+
219
+ /** Get navigation bar height in px. */
220
+ async getNavBarHeight(timeout?: number): Promise<number> {
221
+ const res = await this.asyncCall(
222
+ BarUtilsCallMethod.getNavBarHeight,
223
+ undefined,
224
+ timeout
225
+ );
226
+ if (!res.isSuccess()) {
227
+ throw new Error(
228
+ this.errorMessage(res, "getNavBarHeight failed")
229
+ );
230
+ }
231
+ return (res.getData() as { height: number }).height;
232
+ }
233
+
234
+ /** Set navigation bar visibility. */
235
+ async setNavBarVisibility(
236
+ isVisible: boolean = true,
237
+ timeout?: number
238
+ ): Promise<void> {
239
+ const res = await this.asyncCall(
240
+ BarUtilsCallMethod.setNavBarVisibility,
241
+ { isVisible },
242
+ timeout
243
+ );
244
+ if (!res.isSuccess()) {
245
+ throw new Error(
246
+ this.errorMessage(res, "setNavBarVisibility failed")
247
+ );
248
+ }
249
+ }
250
+
251
+ /** Check if navigation bar is visible. */
252
+ async isNavBarVisible(timeout?: number): Promise<boolean> {
253
+ const res = await this.asyncCall(
254
+ BarUtilsCallMethod.isNavBarVisible,
255
+ undefined,
256
+ timeout
257
+ );
258
+ if (!res.isSuccess()) {
259
+ throw new Error(
260
+ this.errorMessage(res, "isNavBarVisible failed")
261
+ );
262
+ }
263
+ return (res.getData() as { visible: boolean }).visible;
264
+ }
265
+
266
+ /** Set navigation bar color. color: Android color int. */
267
+ async setNavBarColor(color: number, timeout?: number): Promise<void> {
268
+ const res = await this.asyncCall(
269
+ BarUtilsCallMethod.setNavBarColor,
270
+ { color },
271
+ timeout
272
+ );
273
+ if (!res.isSuccess()) {
274
+ throw new Error(
275
+ this.errorMessage(res, "setNavBarColor failed")
276
+ );
277
+ }
278
+ }
279
+
280
+ /** Get current navigation bar color. */
281
+ async getNavBarColor(timeout?: number): Promise<number> {
282
+ const res = await this.asyncCall(
283
+ BarUtilsCallMethod.getNavBarColor,
284
+ undefined,
285
+ timeout
286
+ );
287
+ if (!res.isSuccess()) {
288
+ throw new Error(
289
+ this.errorMessage(res, "getNavBarColor failed")
290
+ );
291
+ }
292
+ return (res.getData() as { color: number }).color;
293
+ }
294
+
295
+ /** Check if device supports navigation bar. */
296
+ async isSupportNavBar(timeout?: number): Promise<boolean> {
297
+ const res = await this.asyncCall(
298
+ BarUtilsCallMethod.isSupportNavBar,
299
+ undefined,
300
+ timeout
301
+ );
302
+ if (!res.isSuccess()) {
303
+ throw new Error(
304
+ this.errorMessage(res, "isSupportNavBar failed")
305
+ );
306
+ }
307
+ return (res.getData() as { support: boolean }).support;
308
+ }
309
+
310
+ /** Set navigation bar light mode. */
311
+ async setNavBarLightMode(
312
+ isLightMode: boolean = true,
313
+ timeout?: number
314
+ ): Promise<void> {
315
+ const res = await this.asyncCall(
316
+ BarUtilsCallMethod.setNavBarLightMode,
317
+ { isLightMode },
318
+ timeout
319
+ );
320
+ if (!res.isSuccess()) {
321
+ throw new Error(
322
+ this.errorMessage(res, "setNavBarLightMode failed")
323
+ );
324
+ }
325
+ }
326
+
327
+ /** Check if navigation bar is in light mode. */
328
+ async isNavBarLightMode(timeout?: number): Promise<boolean> {
329
+ const res = await this.asyncCall(
330
+ BarUtilsCallMethod.isNavBarLightMode,
331
+ undefined,
332
+ timeout
333
+ );
334
+ if (!res.isSuccess()) {
335
+ throw new Error(
336
+ this.errorMessage(res, "isNavBarLightMode failed")
337
+ );
338
+ }
339
+ return (res.getData() as { isLightMode: boolean }).isLightMode;
340
+ }
341
+
342
+ /** Make navigation bar transparent. */
343
+ async transparentNavBar(timeout?: number): Promise<void> {
344
+ const res = await this.asyncCall(
345
+ BarUtilsCallMethod.transparentNavBar,
346
+ undefined,
347
+ timeout
348
+ );
349
+ if (!res.isSuccess()) {
350
+ throw new Error(
351
+ this.errorMessage(res, "transparentNavBar failed")
352
+ );
353
+ }
354
+ }
355
+ }
356
+
357
+ export const barUtils = new BarUtils();
package/src/global.d.ts CHANGED
@@ -43,6 +43,10 @@ declare global {
43
43
  call(method: string): string | null;
44
44
  };
45
45
  assistsxMlkitCallback: (data: string) => void;
46
+ assistsxBarUtils: {
47
+ call(method: string): string | null;
48
+ };
49
+ assistsxBarUtilsCallback: (data: string) => void;
46
50
  }
47
51
  }
48
52
 
package/src/index.ts CHANGED
@@ -23,4 +23,6 @@ export * from "./ime/ime";
23
23
  export * from "./imageutils/image-utils";
24
24
  export * from "./gallery/gallery";
25
25
  export * from "./mlkit/mlkit";
26
- export * from "./mlkit/MlkitCallMethod";
26
+ export * from "./mlkit/MlkitCallMethod";
27
+ export * from "./barutils/bar-utils";
28
+ export * from "./barutils/BarUtilsCallMethod";