@lark-apaas/client-toolkit 1.1.31 → 1.1.32-alpha.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/lib/hooks/useAppInfo.d.ts +1 -0
- package/lib/hooks/useAppInfo.js +22 -5
- package/lib/integrations/getAppInfo.d.ts +1 -1
- package/lib/integrations/getAppInfo.js +3 -3
- package/lib/types/common.d.ts +1 -0
- package/lib/utils/getInitialInfo.d.ts +1 -1
- package/lib/utils/getInitialInfo.js +2 -2
- package/package.json +1 -1
package/lib/hooks/useAppInfo.js
CHANGED
|
@@ -3,9 +3,12 @@ import { getAppInfo } from "../integrations/getAppInfo.js";
|
|
|
3
3
|
const useAppInfo = ()=>{
|
|
4
4
|
const [appInfo, setAppInfo] = useState({});
|
|
5
5
|
useEffect(()=>{
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
const updateDomInfo = (info)=>{
|
|
7
|
+
if (info.name) {
|
|
8
|
+
document.title = info.name;
|
|
9
|
+
const meta = document.querySelector("meta[property='og:title']");
|
|
10
|
+
if (meta) meta.content = info.name;
|
|
11
|
+
}
|
|
9
12
|
if (info.avatar) {
|
|
10
13
|
let link = document.querySelector("link[rel~='icon']");
|
|
11
14
|
if (!link) {
|
|
@@ -14,13 +17,27 @@ const useAppInfo = ()=>{
|
|
|
14
17
|
document.head.appendChild(link);
|
|
15
18
|
}
|
|
16
19
|
link.href = info.avatar;
|
|
20
|
+
const meta = document.querySelector("meta[property='og:image']");
|
|
21
|
+
if (meta) meta.content = info.avatar;
|
|
22
|
+
}
|
|
23
|
+
if (info.description) {
|
|
24
|
+
const meta = document.querySelector("meta[property='og:description']");
|
|
25
|
+
if (meta) meta.content = info.description;
|
|
17
26
|
}
|
|
27
|
+
};
|
|
28
|
+
const handleMetaInfoChanged = async (info)=>{
|
|
29
|
+
if (!info) info = await getAppInfo(true);
|
|
30
|
+
updateDomInfo(info);
|
|
18
31
|
setAppInfo(info);
|
|
19
32
|
};
|
|
20
33
|
handleMetaInfoChanged();
|
|
21
|
-
|
|
34
|
+
const onMessage = (e)=>{
|
|
35
|
+
const data = e.data;
|
|
36
|
+
if (data?.type === 'MiaoDaMetaInfoChanged') return void handleMetaInfoChanged(data.data);
|
|
37
|
+
};
|
|
38
|
+
window.addEventListener('message', onMessage);
|
|
22
39
|
return ()=>{
|
|
23
|
-
window.removeEventListener('
|
|
40
|
+
window.removeEventListener('message', onMessage);
|
|
24
41
|
};
|
|
25
42
|
}, []);
|
|
26
43
|
return {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { AppInfoPayload } from '../types/common';
|
|
2
|
-
export declare function getAppInfo(): Promise<AppInfoPayload>;
|
|
2
|
+
export declare function getAppInfo(refresh?: boolean): Promise<AppInfoPayload>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { getInitialInfo } from "../utils/getInitialInfo.js";
|
|
2
2
|
import { isSparkRuntime } from "../utils/utils.js";
|
|
3
|
-
async function getAppInfo() {
|
|
3
|
+
async function getAppInfo(refresh = false) {
|
|
4
4
|
let appInfo = 'undefined' != typeof window ? window._appInfo : void 0;
|
|
5
|
-
if (!appInfo && isSparkRuntime()) {
|
|
6
|
-
const info = (await getInitialInfo())?.app_info;
|
|
5
|
+
if ((!appInfo || refresh) && isSparkRuntime()) {
|
|
6
|
+
const info = (await getInitialInfo(refresh))?.app_info;
|
|
7
7
|
appInfo = {
|
|
8
8
|
name: info?.app_name || '',
|
|
9
9
|
avatar: info?.app_avatar || ''
|
package/lib/types/common.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ interface BucketConfig {
|
|
|
13
13
|
default_bucket_id?: string;
|
|
14
14
|
}
|
|
15
15
|
/** 获取应用初始化信息(仅全栈沙箱模式下使用) */
|
|
16
|
-
export declare function getInitialInfo(): Promise<{
|
|
16
|
+
export declare function getInitialInfo(refresh?: boolean): Promise<{
|
|
17
17
|
app_info?: AppRuntimePublished;
|
|
18
18
|
app_runtime_extra?: AppRuntimeExtra;
|
|
19
19
|
}>;
|
|
@@ -23,8 +23,8 @@ async function getAppPublished() {
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
let initialInfo;
|
|
26
|
-
async function getInitialInfo() {
|
|
27
|
-
if (initialInfo) return initialInfo;
|
|
26
|
+
async function getInitialInfo(refresh = false) {
|
|
27
|
+
if (initialInfo && !refresh) return initialInfo;
|
|
28
28
|
initialInfo = await getAppPublished();
|
|
29
29
|
if (initialInfo) window._bucket_id = initialInfo.app_runtime_extra?.bucket?.default_bucket_id;
|
|
30
30
|
return initialInfo;
|