@jolibox/implement 1.1.11-beta.4 → 1.1.11-beta.6

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.
@@ -5,7 +5,7 @@ import { hostEmitter, isBoolean } from '@jolibox/common';
5
5
  import { taskTracker, track } from '../report';
6
6
  import { initializeNativeEnv } from './init-env';
7
7
  import { adEventEmitter } from '@/common/ads';
8
- import { openRetentionSchema } from './retention';
8
+ import { openRetentionSchema } from '../ui/retention';
9
9
 
10
10
  let cleanStyles: () => void;
11
11
  RuntimeLoader.onReady(() => {
@@ -84,7 +84,7 @@ if (window.webkit) {
84
84
  };
85
85
  const doExit = async (uuid: string) => {
86
86
  const shouldInterrupt = await RuntimeLoader.exit();
87
- _joliboxJSCore.doExit.postMessage({ uuid, shouldInterrupt });
87
+ _joliboxJSCore.doExit.postMessage({ uuid, shouldInterrupt: shouldInterrupt });
88
88
  };
89
89
 
90
90
  joliboxJSCore = {
@@ -0,0 +1,130 @@
1
+ import { context } from '@/common/context';
2
+ import { invokeNative, subscribe } from '../bootstrap/bridge';
3
+ import { Deferred } from '@jolibox/common';
4
+ import { createRecommendModal, IGame, IRecommendationButton, RecommendModalOnCloseParams } from '@jolibox/ui';
5
+ import { innerFetch as fetch } from '../network';
6
+
7
+ let exitRecommendationsCache: {
8
+ code: string;
9
+ data: {
10
+ gameListInfo: {
11
+ games: IGame[];
12
+ };
13
+ title: string;
14
+ buttons: IRecommendationButton[];
15
+ };
16
+ } | null = null;
17
+
18
+ /**
19
+ * Fetches exit recommendations data from the API
20
+ */
21
+ async function fetchExitRecommendations() {
22
+ if (exitRecommendationsCache) {
23
+ return exitRecommendationsCache;
24
+ }
25
+ const host = context.testMode ? `https://stg-game.jolibox.com` : `https://game.jolibox.com`;
26
+ const url = `${host}/api/user-retention/exit-recommendations?objectId=${context.mpId}&from=GAME_DETAIL`;
27
+ const {
28
+ response: { data }
29
+ } = await fetch<{
30
+ code: string;
31
+ data: {
32
+ gameListInfo: {
33
+ games: IGame[];
34
+ };
35
+ title: string;
36
+ buttons: IRecommendationButton[];
37
+ };
38
+ }>(url);
39
+
40
+ exitRecommendationsCache = data;
41
+ return data;
42
+ }
43
+
44
+ //prefetch
45
+ fetchExitRecommendations();
46
+
47
+ const openGameSchema = (game: IGame) => {
48
+ const host = `https://${game.gameId}.content.jolibox.com`;
49
+ const schema = `${host}/?gameId=${context.mpId}&joliSource=${context.encodeJoliSourceQuery({
50
+ __mpType: 'game',
51
+ __orientation: game.orientation ?? 'VERTICAL'
52
+ })}`;
53
+ invokeNative('openSchemaSync', {
54
+ schema
55
+ });
56
+ };
57
+
58
+ export async function openRetentionSchema() {
59
+ // const { data } = invokeNative('envSync');
60
+ // const { orientation, webviewId } = data;
61
+ // let joliPayload: Record<string, unknown> = {
62
+ // __mpType: 'miniApp',
63
+ // __transparent: true,
64
+ // // set entryPath
65
+ // __orientation: orientation ?? 'VERTICAL', // 默认竖屏
66
+ // __showStatusBar: false,
67
+ // __shouldInterupt: false,
68
+ // __showCapsuleButton: false
69
+ // };
70
+ // if (webviewId) {
71
+ // joliPayload = {
72
+ // ...joliPayload,
73
+ // __from: webviewId
74
+ // };
75
+ // }
76
+
77
+ // const joliSource = context.encodeJoliSourceQuery(joliPayload);
78
+
79
+ // const host = context.testMode
80
+ // ? `https://G32115508989327465281365749294.app.jolibox.com`
81
+ // : `https://G32115508989327465281365749294.app.jolibox.com`;
82
+ // const retentionSchema = `${host}/recommended-guide/${context.mpId}?appId=${context.mpId}&joliSource=${joliSource}&navigationStyle=present`;
83
+
84
+ const quitResultDeffer = new Deferred<boolean>();
85
+
86
+ const data = await fetchExitRecommendations();
87
+
88
+ if (data.code !== 'SUCCESS') {
89
+ quitResultDeffer.resolve(false);
90
+ return quitResultDeffer.promise;
91
+ }
92
+
93
+ const { gameListInfo, title, buttons } = data.data;
94
+
95
+ const modal = createRecommendModal({
96
+ games: gameListInfo.games,
97
+ title,
98
+ buttons,
99
+ onClose: (params: RecommendModalOnCloseParams) => {
100
+ switch (params.type) {
101
+ case 'quit':
102
+ quitResultDeffer.resolve(false);
103
+ break;
104
+ case 'dismiss':
105
+ quitResultDeffer.resolve(true);
106
+ break;
107
+ case 'navigate':
108
+ // TODO: 跳转游戏
109
+ if (params.data?.game) {
110
+ openGameSchema(params.data.game);
111
+ } else {
112
+ quitResultDeffer.resolve(true);
113
+ }
114
+ modal.hide();
115
+ break;
116
+ default:
117
+ // 关闭弹框,留在当前游戏
118
+ quitResultDeffer.resolve(true);
119
+ break;
120
+ }
121
+ }
122
+ });
123
+ // // 异步
124
+ // setTimeout(() => {
125
+ // invokeNative('openSchemaSync', {
126
+ // schema: retentionSchema
127
+ // });
128
+ // }, 0);
129
+ return quitResultDeffer.promise;
130
+ }
@@ -1,44 +0,0 @@
1
- import { context } from '@/common/context';
2
- import { invokeNative, subscribe } from './bridge';
3
- import { Deferred } from '@jolibox/common';
4
- export async function openRetentionSchema() {
5
- const { data } = invokeNative('envSync');
6
- const { orientation, webviewId } = data;
7
- let joliPayload: Record<string, unknown> = {
8
- __mpType: 'miniApp',
9
- __transparent: true,
10
- // set entryPath
11
- __orientation: orientation ?? 'VERTICAL', // 默认竖屏
12
- __showStatusBar: false,
13
- __shouldInterupt: false,
14
- __showCapsuleButton: false
15
- };
16
- if (webviewId) {
17
- joliPayload = {
18
- ...joliPayload,
19
- __from: webviewId
20
- };
21
- }
22
-
23
- const joliSource = context.encodeJoliSourceQuery(joliPayload);
24
-
25
- const host = context.testMode
26
- ? `https://G32115508989327465281365749294.app.jolibox.com`
27
- : `https://G32115508989327465281365749294.app.jolibox.com`;
28
- const retentionSchema = `${host}/recommended-guide/${context.mpId}?appId=${context.mpId}&joliSource=${joliSource}&navigationStyle=present`;
29
-
30
- const quitResultDeffer = new Deferred<boolean>();
31
-
32
- subscribe('onRetentionResult', ({ shouldStay }) => {
33
- quitResultDeffer.resolve(shouldStay);
34
- });
35
- // 异步
36
- setTimeout(() => {
37
- invokeNative('openSchemaSync', {
38
- schema: retentionSchema
39
- });
40
- }, 0);
41
- return quitResultDeffer.promise;
42
- }
43
-
44
- // 添加锁变量,防止多次执行
File without changes