@polyvharmony/live-scenes-foundation 1.2.0 → 1.3.0-rc.1
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/CHANGELOG.md +4 -0
- package/Index.d.ets +4 -2
- package/Index.js +3 -1
- package/ResourceTable.txt +2 -1
- package/libs/plvclasstransformer.har +0 -0
- package/oh-package.json5 +1 -1
- package/package.json +1 -1
- package/src/main/ets/common/PLVCallback.d.ets +31 -6
- package/src/main/ets/common/PLVCallback.js +85 -27
- package/src/main/ets/common/PLVCommonConstants.d.ets +1 -0
- package/src/main/ets/common/PLVCommonConstants.js +1 -0
- package/src/main/ets/common/PLVCommonEnums.js +16 -16
- package/src/main/ets/common/PLVDeviceUtils.d.ets +7 -0
- package/src/main/ets/common/PLVDeviceUtils.js +28 -1
- package/src/main/ets/common/PLVJSONUtils.d.ets +7 -7
- package/src/main/ets/common/PLVJSONUtils.js +20 -20
- package/src/main/ets/common/PLVNetUtils.d.ets +4 -3
- package/src/main/ets/common/PLVNetUtils.js +20 -14
- package/src/main/ets/common/PLVPreferencesUtils.d.ets +8 -8
- package/src/main/ets/common/PLVPreferencesUtils.js +16 -16
- package/src/main/ets/common/PLVScheduledTask.js +2 -2
- package/src/main/ets/common/PLVSimpleBuffer.d.ets +2 -2
- package/src/main/ets/common/PLVSimpleBuffer.js +6 -6
- package/src/main/ets/common/PLVSparseArray.d.ets +10 -0
- package/src/main/ets/common/PLVSparseArray.js +44 -0
- package/src/main/ets/common/PLVTextUtils.d.ets +2 -1
- package/src/main/ets/common/PLVTextUtils.js +28 -22
- package/src/main/ets/common/PLVTimeUtils.d.ets +1 -1
- package/src/main/ets/common/PLVTimeUtils.js +8 -8
- package/src/main/ets/common/PLVToastUtils.d.ets +2 -2
- package/src/main/ets/common/PLVType.d.ets +1 -0
- package/src/main/ets/common/PLVUACreator.d.ets +1 -1
- package/src/main/ets/common/PLVUACreator.js +6 -6
- package/src/main/ets/common/PLVUtils.d.ets +15 -8
- package/src/main/ets/common/PLVUtils.js +89 -45
- package/src/main/ets/common/PLVWebUtils.d.ets +1 -1
- package/src/main/ets/common/PLVWebUtils.js +22 -22
- package/src/main/ets/common/ui/PLVNodeController.d.ets +41 -0
- package/src/main/ets/common/ui/PLVNodeController.js +103 -0
- package/src/main/ets/modules/log/PLVLogger.d.ets +9 -9
- package/src/main/ets/modules/log/PLVLogger.js +20 -20
- package/src/main/ets/modules/log/PLVXLogFilePrinter.d.ets +1 -1
- package/src/main/ets/modules/log/PLVXLogFilePrinter.js +2 -2
- package/src/main/ets/modules/net/PLVHttpData.d.ets +1 -1
- package/src/main/ets/modules/net/PLVHttpData.js +2 -2
- package/src/main/ets/modules/net/PLVHttpError.d.ets +2 -2
- package/src/main/ets/modules/net/PLVHttpError.js +5 -5
- package/src/main/ets/modules/net/PLVHttpRequest.d.ets +7 -7
- package/src/main/ets/modules/net/PLVHttpRequest.js +31 -31
- package/src/main/ets/modules/net/PLVRequestSetting.js +7 -7
- package/src/main/ets/modules/socket/PLVSocketIO.d.ets +19 -18
- package/src/main/ets/modules/socket/PLVSocketIO.js +70 -53
- package/src/main/ets/modules/web/PLVSimpleWeb.js +3 -3
- package/src/main/ets/modules/web/PLVWebController.d.ets +5 -3
- package/src/main/ets/modules/web/PLVWebController.js +29 -21
- package/src/main/module.json +1 -28
|
@@ -7,7 +7,7 @@ export declare class PLVPreferencesUtils {
|
|
|
7
7
|
* @param value
|
|
8
8
|
* @param preferenceName
|
|
9
9
|
*/
|
|
10
|
-
static put(key: string, value: preferences.ValueType,
|
|
10
|
+
static put(key: string, value: preferences.ValueType, u3?: string): Promise<void>;
|
|
11
11
|
/**
|
|
12
12
|
* 获取缓存值
|
|
13
13
|
* @param key
|
|
@@ -15,44 +15,44 @@ export declare class PLVPreferencesUtils {
|
|
|
15
15
|
* @param preferenceName
|
|
16
16
|
* @returns
|
|
17
17
|
*/
|
|
18
|
-
static get(key: string, defValue: preferences.ValueType,
|
|
18
|
+
static get(key: string, defValue: preferences.ValueType, t3?: string): Promise<preferences.ValueType>;
|
|
19
19
|
/**
|
|
20
20
|
* 获取string类型的缓存值
|
|
21
21
|
* @param key
|
|
22
22
|
* @returns
|
|
23
23
|
*/
|
|
24
|
-
static getString(key: string,
|
|
24
|
+
static getString(key: string, s3?: string): Promise<string>;
|
|
25
25
|
/**
|
|
26
26
|
* 获取number类型的缓存值
|
|
27
27
|
* @param key
|
|
28
28
|
* @returns
|
|
29
29
|
*/
|
|
30
|
-
static getNumber(key: string,
|
|
30
|
+
static getNumber(key: string, r3?: string, defaultValue?: number): Promise<number>;
|
|
31
31
|
/**
|
|
32
32
|
* 获取boolean类型的缓存值
|
|
33
33
|
* @param key
|
|
34
34
|
* @param preferenceName
|
|
35
35
|
* @returns
|
|
36
36
|
*/
|
|
37
|
-
static getBoolean(key: string,
|
|
37
|
+
static getBoolean(key: string, q3?: string): Promise<boolean>;
|
|
38
38
|
/**
|
|
39
39
|
* 检查缓存的Preferences实例中是否包含名为给定Key的存储键值对
|
|
40
40
|
* @param key
|
|
41
41
|
* @param preferenceName
|
|
42
42
|
* @returns
|
|
43
43
|
*/
|
|
44
|
-
static has(key: string,
|
|
44
|
+
static has(key: string, p3?: string): Promise<boolean>;
|
|
45
45
|
/**
|
|
46
46
|
* 删除缓存值
|
|
47
47
|
* @param key
|
|
48
48
|
* @param preferenceName
|
|
49
49
|
* @returns
|
|
50
50
|
*/
|
|
51
|
-
static delete(key: string,
|
|
51
|
+
static delete(key: string, n3?: string): Promise<void>;
|
|
52
52
|
/**
|
|
53
53
|
* 清空缓存
|
|
54
54
|
* @param preferenceName
|
|
55
55
|
* @returns
|
|
56
56
|
*/
|
|
57
|
-
static clear(
|
|
57
|
+
static clear(m3?: string): Promise<void>;
|
|
58
58
|
}
|
|
@@ -3,28 +3,28 @@ const defaultPreferenceName = "PLV_SP_HARMONY_UTILS_PREFERENCES";
|
|
|
3
3
|
export class PLVPreferencesUtils {
|
|
4
4
|
constructor() {
|
|
5
5
|
}
|
|
6
|
-
static async put(key, value,
|
|
7
|
-
await PreferencesUtil.put(key, value,
|
|
6
|
+
static async put(key, value, u3 = defaultPreferenceName) {
|
|
7
|
+
await PreferencesUtil.put(key, value, u3);
|
|
8
8
|
}
|
|
9
|
-
static async get(key, defValue,
|
|
10
|
-
return PreferencesUtil.get(key, defValue,
|
|
9
|
+
static async get(key, defValue, t3 = defaultPreferenceName) {
|
|
10
|
+
return PreferencesUtil.get(key, defValue, t3);
|
|
11
11
|
}
|
|
12
|
-
static async getString(key,
|
|
13
|
-
return (await PreferencesUtil.get(key, "",
|
|
12
|
+
static async getString(key, s3 = defaultPreferenceName) {
|
|
13
|
+
return (await PreferencesUtil.get(key, "", s3));
|
|
14
14
|
}
|
|
15
|
-
static async getNumber(key,
|
|
16
|
-
return (await PreferencesUtil.get(key, defaultValue,
|
|
15
|
+
static async getNumber(key, r3 = defaultPreferenceName, defaultValue = 0) {
|
|
16
|
+
return (await PreferencesUtil.get(key, defaultValue, r3));
|
|
17
17
|
}
|
|
18
|
-
static async getBoolean(key,
|
|
19
|
-
return (await PreferencesUtil.get(key, false,
|
|
18
|
+
static async getBoolean(key, q3 = defaultPreferenceName) {
|
|
19
|
+
return (await PreferencesUtil.get(key, false, q3));
|
|
20
20
|
}
|
|
21
|
-
static async has(key,
|
|
22
|
-
return PreferencesUtil.has(key,
|
|
21
|
+
static async has(key, p3 = defaultPreferenceName) {
|
|
22
|
+
return PreferencesUtil.has(key, p3);
|
|
23
23
|
}
|
|
24
|
-
static async delete(key,
|
|
25
|
-
return PreferencesUtil.delete(key,
|
|
24
|
+
static async delete(key, n3 = defaultPreferenceName) {
|
|
25
|
+
return PreferencesUtil.delete(key, n3);
|
|
26
26
|
}
|
|
27
|
-
static async clear(
|
|
28
|
-
return PreferencesUtil.clear(
|
|
27
|
+
static async clear(m3 = defaultPreferenceName) {
|
|
28
|
+
return PreferencesUtil.clear(m3);
|
|
29
29
|
}
|
|
30
30
|
}
|
|
@@ -22,7 +22,7 @@ export class PLVScheduledTask {
|
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
24
24
|
const now = Date.now();
|
|
25
|
-
const
|
|
25
|
+
const v3 = Math.max(0, this.nextExecutionTime - now);
|
|
26
26
|
this.timerId = setTimeout(async () => {
|
|
27
27
|
try {
|
|
28
28
|
await this.callback();
|
|
@@ -32,7 +32,7 @@ export class PLVScheduledTask {
|
|
|
32
32
|
}
|
|
33
33
|
this.nextExecutionTime = Date.now() + this.period;
|
|
34
34
|
this.scheduleNextExecution();
|
|
35
|
-
},
|
|
35
|
+
}, v3);
|
|
36
36
|
}
|
|
37
37
|
cancel() {
|
|
38
38
|
if (!this.isRunning) {
|
|
@@ -4,8 +4,8 @@ export declare class PLVSimpleBuffer<T> {
|
|
|
4
4
|
private intervalId?;
|
|
5
5
|
private timespan;
|
|
6
6
|
private isRelease;
|
|
7
|
-
constructor(
|
|
7
|
+
constructor(y3?: number);
|
|
8
8
|
observe(callback?: PLVCallback<T[]>): void;
|
|
9
9
|
release(): void;
|
|
10
|
-
push(
|
|
10
|
+
push(x3: T): void;
|
|
11
11
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
const
|
|
1
|
+
const w3 = 500;
|
|
2
2
|
export class PLVSimpleBuffer {
|
|
3
|
-
constructor(
|
|
3
|
+
constructor(y3 = w3) {
|
|
4
4
|
this.buffer = [];
|
|
5
|
-
this.timespan =
|
|
5
|
+
this.timespan = w3;
|
|
6
6
|
this.isRelease = false;
|
|
7
|
-
this.timespan =
|
|
7
|
+
this.timespan = y3;
|
|
8
8
|
}
|
|
9
9
|
observe(callback) {
|
|
10
10
|
if (this.intervalId == undefined) {
|
|
@@ -21,10 +21,10 @@ export class PLVSimpleBuffer {
|
|
|
21
21
|
clearInterval(this.intervalId);
|
|
22
22
|
this.buffer.length = 0;
|
|
23
23
|
}
|
|
24
|
-
push(
|
|
24
|
+
push(x3) {
|
|
25
25
|
if (this.isRelease) {
|
|
26
26
|
return;
|
|
27
27
|
}
|
|
28
|
-
this.buffer.push(
|
|
28
|
+
this.buffer.push(x3);
|
|
29
29
|
}
|
|
30
30
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare class PLVSparseArray<V> {
|
|
2
|
+
private entries;
|
|
3
|
+
set(key: number, value: V): void;
|
|
4
|
+
get(key: number): V | undefined;
|
|
5
|
+
delete(key: number): void;
|
|
6
|
+
size(): number;
|
|
7
|
+
forEach(callback: (key: number, value: V) => void): void;
|
|
8
|
+
forEachReverse(callback: (key: number, value: V) => void): void;
|
|
9
|
+
someReverse(callback: (key: number, value: V) => boolean): boolean;
|
|
10
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export class PLVSparseArray {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.entries = [];
|
|
4
|
+
}
|
|
5
|
+
set(key, value) {
|
|
6
|
+
const h4 = this.entries.findIndex((i4) => i4[0] >= key);
|
|
7
|
+
if (h4 >= 0 && this.entries[h4][0] === key) {
|
|
8
|
+
this.entries[h4][1] = value;
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
this.entries.splice(h4 >= 0 ? h4 : this.entries.length, 0, [key, value]);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
get(key) {
|
|
15
|
+
const f4 = this.entries.find((g4) => g4[0] === key);
|
|
16
|
+
return f4 ? f4[1] : undefined;
|
|
17
|
+
}
|
|
18
|
+
delete(key) {
|
|
19
|
+
this.entries = this.entries.filter((e4) => e4[0] !== key);
|
|
20
|
+
}
|
|
21
|
+
size() {
|
|
22
|
+
return this.entries.length;
|
|
23
|
+
}
|
|
24
|
+
forEach(callback) {
|
|
25
|
+
for (const d4 of this.entries) {
|
|
26
|
+
callback(d4[0], d4[1]);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
forEachReverse(callback) {
|
|
30
|
+
for (let b4 = this.entries.length - 1; b4 >= 0; b4--) {
|
|
31
|
+
const c4 = this.entries[b4];
|
|
32
|
+
callback(c4[0], c4[1]);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
someReverse(callback) {
|
|
36
|
+
for (let z3 = this.entries.length - 1; z3 >= 0; z3--) {
|
|
37
|
+
const a4 = this.entries[z3];
|
|
38
|
+
if (callback(a4[0], a4[1])) {
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -4,6 +4,7 @@ export declare class PLVTextUtils {
|
|
|
4
4
|
static convertSpecialString(input?: string): string;
|
|
5
5
|
static toString(num?: number): string | undefined;
|
|
6
6
|
static toWString(data?: number): string | undefined;
|
|
7
|
-
static
|
|
7
|
+
static toKString(data?: number): string | undefined;
|
|
8
|
+
static fixPic(k4?: string): string;
|
|
8
9
|
static isNumberZero(number?: string): boolean;
|
|
9
10
|
}
|
|
@@ -11,22 +11,22 @@ export class PLVTextUtils {
|
|
|
11
11
|
if (!(input = PLVTextUtils.convertSpecialString(input))) {
|
|
12
12
|
return undefined;
|
|
13
13
|
}
|
|
14
|
-
const
|
|
14
|
+
const l4 = /\[([^\[\]]{1,5})\]/g;
|
|
15
15
|
let match;
|
|
16
|
-
let
|
|
16
|
+
let m4 = 0;
|
|
17
17
|
const result = [];
|
|
18
|
-
while ((match =
|
|
19
|
-
const
|
|
20
|
-
if (match.index >
|
|
21
|
-
const
|
|
22
|
-
result.push(
|
|
18
|
+
while ((match = l4.exec(input)) !== null) {
|
|
19
|
+
const o4 = match[0];
|
|
20
|
+
if (match.index > m4) {
|
|
21
|
+
const p4 = input.slice(m4, match.index);
|
|
22
|
+
result.push(p4);
|
|
23
23
|
}
|
|
24
|
-
result.push(
|
|
25
|
-
|
|
24
|
+
result.push(o4);
|
|
25
|
+
m4 = l4.lastIndex;
|
|
26
26
|
}
|
|
27
|
-
if (
|
|
28
|
-
const
|
|
29
|
-
result.push(
|
|
27
|
+
if (m4 < input.length) {
|
|
28
|
+
const n4 = input.slice(m4);
|
|
29
|
+
result.push(n4);
|
|
30
30
|
}
|
|
31
31
|
return result;
|
|
32
32
|
}
|
|
@@ -51,23 +51,29 @@ export class PLVTextUtils {
|
|
|
51
51
|
}
|
|
52
52
|
return PLVTextUtils.toString(data);
|
|
53
53
|
}
|
|
54
|
-
static
|
|
55
|
-
if (
|
|
56
|
-
return
|
|
54
|
+
static toKString(data) {
|
|
55
|
+
if (data && data > 1000) {
|
|
56
|
+
return (data / 1000).toFixed(1) + 'k';
|
|
57
57
|
}
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
return PLVTextUtils.toString(data);
|
|
59
|
+
}
|
|
60
|
+
static fixPic(k4) {
|
|
61
|
+
if (!k4) {
|
|
62
|
+
return k4 || '';
|
|
63
|
+
}
|
|
64
|
+
if (k4.startsWith('//')) {
|
|
65
|
+
return `http:${k4}`;
|
|
60
66
|
}
|
|
61
|
-
else if (
|
|
62
|
-
return `http://livestatic.videocc.net${
|
|
67
|
+
else if (k4.startsWith('/')) {
|
|
68
|
+
return `http://livestatic.videocc.net${k4}`;
|
|
63
69
|
}
|
|
64
|
-
return
|
|
70
|
+
return k4;
|
|
65
71
|
}
|
|
66
72
|
static isNumberZero(number) {
|
|
67
73
|
if (!number) {
|
|
68
74
|
return true;
|
|
69
75
|
}
|
|
70
|
-
const
|
|
71
|
-
return
|
|
76
|
+
const j4 = parseFloat(number);
|
|
77
|
+
return j4 === 0;
|
|
72
78
|
}
|
|
73
79
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
export class PLVTimeUtils {
|
|
2
|
-
static generateTime(
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
if (
|
|
8
|
-
return `${
|
|
2
|
+
static generateTime(q4, r4) {
|
|
3
|
+
const s4 = Math.floor(q4 / 1000);
|
|
4
|
+
const t4 = s4 % 60;
|
|
5
|
+
const u4 = Math.floor((s4 / 60) % 60);
|
|
6
|
+
const v4 = Math.floor(s4 / 3600);
|
|
7
|
+
if (r4 || v4 > 0) {
|
|
8
|
+
return `${v4.toString().padStart(2, '0')}:${u4.toString().padStart(2, '0')}:${t4.toString().padStart(2, '0')}`;
|
|
9
9
|
}
|
|
10
10
|
else {
|
|
11
|
-
return `${
|
|
11
|
+
return `${u4.toString().padStart(2, '0')}:${t4.toString().padStart(2, '0')}`;
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AxiosResponse } from '@ohos/axios';
|
|
2
2
|
import { PLVHttpData } from '../modules/net/PLVHttpData';
|
|
3
3
|
export type PLVResponseObject = AxiosResponse<object>;
|
|
4
|
+
export type PLVResponseType<T> = AxiosResponse<T>;
|
|
4
5
|
export type PLVResponseData<T> = AxiosResponse<PLVHttpData<T>>;
|
|
5
6
|
export type PLVResponse<T> = PLVResponseData<T> | void;
|
|
6
7
|
export type PLVJSONObject = Record<string, Object | undefined>;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import deviceInfo from '@ohos.deviceInfo';
|
|
2
2
|
export class PLVUACreator {
|
|
3
|
-
static createUA(
|
|
4
|
-
let
|
|
5
|
-
if (
|
|
6
|
-
|
|
3
|
+
static createUA(w4, x4) {
|
|
4
|
+
let y4 = w4;
|
|
5
|
+
if (x4) {
|
|
6
|
+
y4 += `(${x4})`;
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
return
|
|
8
|
+
y4 += ` ohos/${deviceInfo.osFullName} (HarmonyOS ${deviceInfo.osFullName}; ${deviceInfo.brand} ${deviceInfo.productModel};)`;
|
|
9
|
+
return y4;
|
|
10
10
|
}
|
|
11
11
|
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { PLVCallback, PLVCallback2, PLVDisposable } from './PLVCallback';
|
|
1
|
+
import { PLVAvoidAreaChangeListener, PLVCallback, PLVCallback2, PLVDisposable, PLVMediaQueryListener } from './PLVCallback';
|
|
2
2
|
import { common } from '@kit.AbilityKit';
|
|
3
|
-
import { window } from '@kit.ArkUI';
|
|
3
|
+
import { mediaquery, window } from '@kit.ArkUI';
|
|
4
4
|
import { PLVReject, PLVResolve } from './PLVType';
|
|
5
5
|
export default class PLVUtils {
|
|
6
|
+
private static readonly TIMES;
|
|
6
7
|
private constructor();
|
|
7
8
|
static init(context: common.UIAbilityContext, windowStage: window.WindowStage): void;
|
|
8
|
-
static getClassTag(tag?: string | Object,
|
|
9
|
+
static getClassTag(tag?: string | Object, d6?: boolean): string | undefined;
|
|
9
10
|
static retryWhen<T = void>(when: PLVCallback<void, T>, retry: PLVCallback<void, T>): Promise<Awaited<T>>;
|
|
10
|
-
static disposablePromise<T>(promise: Promise<T>,
|
|
11
|
+
static disposablePromise<T>(promise: Promise<T>, c6?: PLVDisposable): Promise<T>;
|
|
11
12
|
static safePromise<T = void>(callback: PLVCallback2<PLVResolve<T>, PLVReject, void>, a6?: PLVDisposable): Promise<T>;
|
|
12
13
|
static retryPromise<T>(w5: number, x5: number, promise: Promise<T>, y5?: PLVDisposable): Promise<T>;
|
|
13
14
|
static delay(delay?: number): Promise<void>;
|
|
@@ -16,10 +17,16 @@ export default class PLVUtils {
|
|
|
16
17
|
static getDeviceId(): string;
|
|
17
18
|
static undefinedToValue<T>(data: T, callback: PLVCallback<T, void>, delay?: number): undefined;
|
|
18
19
|
static copyText(text: string): Promise<void>;
|
|
19
|
-
static
|
|
20
|
+
static listenerOrientation(callback: PLVCallback<mediaquery.MediaQueryResult>): PLVMediaQueryListener;
|
|
21
|
+
static listenerAvoidAreaChange(callback: PLVCallback<window.AvoidAreaOptions>): PLVAvoidAreaChangeListener;
|
|
22
|
+
static changeOrientation(o5: boolean, component?: Object, p5?: window.Window): void;
|
|
20
23
|
static isLandscape(component?: Object): boolean;
|
|
21
|
-
static setWindowFullScreen(isLayoutFullScreen?: boolean, isFullScreen?: boolean, component?: Object,
|
|
24
|
+
static setWindowFullScreen(isLayoutFullScreen?: boolean, isFullScreen?: boolean, component?: Object, h5?: window.Window): Promise<Object[]>;
|
|
25
|
+
static setWindowSystemBarProperties(systemBarProperties?: window.SystemBarProperties): void;
|
|
22
26
|
static startScan(component?: Object): Promise<string>;
|
|
23
|
-
static getVideoRectJS(
|
|
24
|
-
static getExitFullScreenJS(
|
|
27
|
+
static getVideoRectJS(e5: boolean): string;
|
|
28
|
+
static getExitFullScreenJS(c5: boolean): string;
|
|
29
|
+
static colorResourceToHex(resource: Resource): string;
|
|
30
|
+
static colorIntToHex(z4: number, a5?: boolean): string;
|
|
31
|
+
static debounce(func: Function, delay?: number, key?: string): void;
|
|
25
32
|
}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
import { PLVAvoidAreaChangeListener, PLVMediaQueryListener } from './PLVCallback';
|
|
1
2
|
import PLVLogger from '../modules/log/PLVLogger';
|
|
2
3
|
import PLVCommonConstants from './PLVCommonConstants';
|
|
3
4
|
import { AppUtil, DeviceUtil, PasteboardUtil } from '@pura/harmony-utils';
|
|
4
5
|
import ConfigurationConstant from "@ohos.app.ability.ConfigurationConstant";
|
|
6
|
+
import mediaquery from "@ohos.mediaquery";
|
|
5
7
|
import window from "@ohos.window";
|
|
6
8
|
import scanBarcode from "@hms.core.scan.scanBarcode";
|
|
7
9
|
import scanCore from "@hms.core.scan.scanCore";
|
|
10
|
+
import { PLVDeviceUtils } from './PLVDeviceUtils';
|
|
8
11
|
const TAG = '[PLVUtils]';
|
|
9
12
|
export default class PLVUtils {
|
|
10
13
|
constructor() {
|
|
@@ -12,8 +15,8 @@ export default class PLVUtils {
|
|
|
12
15
|
static init(context, windowStage) {
|
|
13
16
|
AppUtil.init(context, windowStage);
|
|
14
17
|
}
|
|
15
|
-
static getClassTag(tag,
|
|
16
|
-
let key =
|
|
18
|
+
static getClassTag(tag, d6 = true) {
|
|
19
|
+
let key = d6 ? '[Anonymous]' : undefined;
|
|
17
20
|
if (typeof tag == 'string') {
|
|
18
21
|
key = tag;
|
|
19
22
|
}
|
|
@@ -39,26 +42,26 @@ export default class PLVUtils {
|
|
|
39
42
|
}
|
|
40
43
|
}
|
|
41
44
|
}
|
|
42
|
-
static async disposablePromise(promise,
|
|
45
|
+
static async disposablePromise(promise, c6) {
|
|
43
46
|
try {
|
|
44
47
|
await promise;
|
|
45
48
|
}
|
|
46
49
|
catch (error) {
|
|
47
50
|
return Promise.reject(error);
|
|
48
51
|
}
|
|
49
|
-
if (
|
|
52
|
+
if (c6?.isDispose()) {
|
|
50
53
|
return Promise.reject(new Error('error'));
|
|
51
54
|
}
|
|
52
55
|
return promise;
|
|
53
56
|
}
|
|
54
57
|
static safePromise(callback, a6) {
|
|
55
|
-
const promise = new Promise(async (
|
|
58
|
+
const promise = new Promise(async (b6, reject) => {
|
|
56
59
|
try {
|
|
57
|
-
await callback(
|
|
60
|
+
await callback(b6, reject);
|
|
58
61
|
}
|
|
59
62
|
catch (err) {
|
|
60
63
|
PLVLogger.printWarn(TAG, 'safePromise catch error', err);
|
|
61
|
-
|
|
64
|
+
reject(err);
|
|
62
65
|
}
|
|
63
66
|
});
|
|
64
67
|
return PLVUtils.disposablePromise(promise, a6);
|
|
@@ -112,40 +115,58 @@ export default class PLVUtils {
|
|
|
112
115
|
static copyText(text) {
|
|
113
116
|
return PasteboardUtil.setDataText(text);
|
|
114
117
|
}
|
|
115
|
-
static
|
|
118
|
+
static listenerOrientation(callback) {
|
|
119
|
+
const listener = mediaquery.matchMediaSync('(orientation: landscape)');
|
|
120
|
+
listener.on('change', callback);
|
|
121
|
+
return new PLVMediaQueryListener(listener, callback);
|
|
122
|
+
}
|
|
123
|
+
static listenerAvoidAreaChange(callback) {
|
|
124
|
+
const t5 = AppUtil.getMainWindow();
|
|
125
|
+
try {
|
|
126
|
+
t5.on('avoidAreaChange', callback);
|
|
127
|
+
}
|
|
128
|
+
catch (u5) {
|
|
129
|
+
PLVLogger.error(TAG, `Failed to enable the listener for system avoid area changes. Cause code: ${u5.code}, message: ${u5.message}`);
|
|
130
|
+
}
|
|
131
|
+
return new PLVAvoidAreaChangeListener(t5, callback);
|
|
132
|
+
}
|
|
133
|
+
static changeOrientation(o5, component, p5) {
|
|
116
134
|
let context = getContext(component);
|
|
117
|
-
let
|
|
118
|
-
s5.setPreferredOrientation(
|
|
135
|
+
let q5 = (s5) => {
|
|
136
|
+
s5.setPreferredOrientation(o5 ? window.Orientation.LANDSCAPE : window.Orientation.PORTRAIT);
|
|
119
137
|
};
|
|
120
|
-
|
|
138
|
+
p5 ? q5(p5) :
|
|
121
139
|
window.getLastWindow(context).then((r5) => {
|
|
122
|
-
|
|
140
|
+
q5(r5);
|
|
123
141
|
});
|
|
124
142
|
}
|
|
125
143
|
static isLandscape(component) {
|
|
126
144
|
let context = getContext(component);
|
|
127
145
|
return context.config.direction === ConfigurationConstant.Direction.DIRECTION_HORIZONTAL;
|
|
128
146
|
}
|
|
129
|
-
static setWindowFullScreen(isLayoutFullScreen = false, isFullScreen = false, component,
|
|
130
|
-
return new Promise((
|
|
147
|
+
static setWindowFullScreen(isLayoutFullScreen = false, isFullScreen = false, component, h5) {
|
|
148
|
+
return new Promise((i5) => {
|
|
131
149
|
let context = getContext(component);
|
|
132
|
-
let
|
|
133
|
-
let
|
|
134
|
-
let
|
|
135
|
-
|
|
150
|
+
let j5 = (l5) => {
|
|
151
|
+
let m5 = l5.getWindowProperties().isLayoutFullScreen;
|
|
152
|
+
let n5 = l5.getWindowProperties().isFullScreen;
|
|
153
|
+
l5.setWindowLayoutFullScreen(isLayoutFullScreen);
|
|
136
154
|
if (canIUse("SystemCapability.Window.SessionManager")) {
|
|
137
|
-
|
|
138
|
-
|
|
155
|
+
l5.setSpecificSystemBarEnabled('status', !isFullScreen);
|
|
156
|
+
i5([m5, n5]);
|
|
139
157
|
}
|
|
140
158
|
};
|
|
141
|
-
|
|
142
|
-
window.getLastWindow(context).then((
|
|
143
|
-
|
|
159
|
+
h5 ? j5(h5) :
|
|
160
|
+
window.getLastWindow(context).then((k5) => {
|
|
161
|
+
j5(k5);
|
|
144
162
|
});
|
|
145
163
|
});
|
|
146
164
|
}
|
|
165
|
+
static setWindowSystemBarProperties(systemBarProperties) {
|
|
166
|
+
PLVDeviceUtils.setWindowSystemBarProperties(systemBarProperties);
|
|
167
|
+
}
|
|
147
168
|
static startScan(component) {
|
|
148
|
-
return new Promise((
|
|
169
|
+
return new Promise((g5) => {
|
|
149
170
|
if (canIUse('SystemCapability.Multimedia.Scan.Core') && canIUse('SystemCapability.Multimedia.Scan.ScanBarcode')) {
|
|
150
171
|
let options = {
|
|
151
172
|
scanTypes: [scanCore.ScanType.ALL],
|
|
@@ -155,7 +176,7 @@ export default class PLVUtils {
|
|
|
155
176
|
try {
|
|
156
177
|
scanBarcode.startScanForResult(getContext(component), options).then((result) => {
|
|
157
178
|
PLVLogger.info(TAG, 'Promise scan result: ' + JSON.stringify(result));
|
|
158
|
-
|
|
179
|
+
g5(result.originalValue);
|
|
159
180
|
}).catch((error) => {
|
|
160
181
|
PLVLogger.error(TAG, 'Promise error: ' + JSON.stringify(error));
|
|
161
182
|
});
|
|
@@ -166,32 +187,55 @@ export default class PLVUtils {
|
|
|
166
187
|
}
|
|
167
188
|
});
|
|
168
189
|
}
|
|
169
|
-
static getVideoRectJS(
|
|
170
|
-
let
|
|
190
|
+
static getVideoRectJS(e5) {
|
|
191
|
+
let f5 = "function getVideoRect() {";
|
|
171
192
|
{
|
|
172
|
-
|
|
173
|
-
|
|
193
|
+
f5 += "let tags = document.getElementsByTagName('video');";
|
|
194
|
+
f5 += "if (tags.length > 0) {";
|
|
174
195
|
{
|
|
175
|
-
|
|
176
|
-
|
|
196
|
+
f5 += "let video = tags[0];";
|
|
197
|
+
f5 += "return {";
|
|
177
198
|
{
|
|
178
|
-
|
|
179
|
-
|
|
199
|
+
f5 += "'width': video.videoWidth,";
|
|
200
|
+
f5 += "'height': video.videoHeight";
|
|
180
201
|
}
|
|
181
|
-
|
|
202
|
+
f5 += "};";
|
|
182
203
|
}
|
|
183
|
-
|
|
184
|
-
|
|
204
|
+
f5 += "}";
|
|
205
|
+
f5 += "return {};";
|
|
206
|
+
}
|
|
207
|
+
f5 += "}";
|
|
208
|
+
f5 += "getVideoRect();";
|
|
209
|
+
return e5 ? PLVCommonConstants.JS_PRE + f5 : f5;
|
|
210
|
+
}
|
|
211
|
+
static getExitFullScreenJS(c5) {
|
|
212
|
+
let d5 = "function exitFullScreen() {";
|
|
213
|
+
d5 += "document.getElementsByTagName('video')[0].webkitExitFullScreen()";
|
|
214
|
+
d5 += "}";
|
|
215
|
+
d5 += "exitFullScreen();";
|
|
216
|
+
return c5 ? PLVCommonConstants.JS_PRE + d5 : d5;
|
|
217
|
+
}
|
|
218
|
+
static colorResourceToHex(resource) {
|
|
219
|
+
return PLVUtils.colorIntToHex(getContext().resourceManager.getColorSync(resource));
|
|
220
|
+
}
|
|
221
|
+
static colorIntToHex(z4, a5 = false) {
|
|
222
|
+
const b5 = z4.toString(16).padStart(8, '0');
|
|
223
|
+
if (a5) {
|
|
224
|
+
return `#${b5.toUpperCase()}`;
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
return `#${b5.substring(2).toUpperCase()}`;
|
|
185
228
|
}
|
|
186
|
-
x4 += "}";
|
|
187
|
-
x4 += "getVideoRect();";
|
|
188
|
-
return w4 ? PLVCommonConstants.JS_PRE + x4 : x4;
|
|
189
229
|
}
|
|
190
|
-
static
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
230
|
+
static debounce(func, delay = 500, key = 'default') {
|
|
231
|
+
if (PLVUtils.TIMES.has(key)) {
|
|
232
|
+
clearTimeout(PLVUtils.TIMES.get(key));
|
|
233
|
+
}
|
|
234
|
+
const timer = setTimeout(() => {
|
|
235
|
+
func();
|
|
236
|
+
PLVUtils.TIMES.delete(key);
|
|
237
|
+
}, delay);
|
|
238
|
+
PLVUtils.TIMES.set(key, timer);
|
|
196
239
|
}
|
|
197
240
|
}
|
|
241
|
+
PLVUtils.TIMES = new Map();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare class PLVWebUtils {
|
|
2
2
|
static toWebViewContent(content?: string, color?: string): string;
|
|
3
|
-
static toRGBA(
|
|
3
|
+
static toRGBA(g6: string): string;
|
|
4
4
|
static cleanHTML(input: string): string;
|
|
5
5
|
static openWebLink(url?: string, component?: object): void;
|
|
6
6
|
}
|