esoftplay 0.0.119-b → 0.0.119-c
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/global.ts +0 -2
- package/{modules/lib → libs}/worker.tsx +63 -75
- package/modules/lib/picture.tsx +3 -2
- package/modules/lib/updater.tsx +4 -4
- package/modules/user/index.tsx +4 -6
- package/package.json +1 -1
- package/modules/lib/workview.tsx +0 -33
package/global.ts
CHANGED
|
@@ -1,47 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
task: string,
|
|
10
|
-
taskId: string,
|
|
11
|
-
result: (res: string) => void
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface LibWorkerProps {
|
|
15
|
-
tasks?: LibWorkerInit[],
|
|
16
|
-
}
|
|
17
|
-
export interface LibWorkerState {
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
_global.LibWorkerBase = React.createRef()
|
|
21
|
-
_global.LibWorkerTasks = new Map()
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Platform, View } from 'react-native';
|
|
3
|
+
import WebView from "react-native-webview";
|
|
4
|
+
const _global = require('../_global').default
|
|
5
|
+
const esp = require('../esp').default
|
|
6
|
+
|
|
7
|
+
_global.WorkerBase = React.createRef()
|
|
8
|
+
_global.WorkerTasks = new Map()
|
|
22
9
|
_global.injectedJavaScripts = []
|
|
23
|
-
_global.
|
|
24
|
-
_global.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
_global.LibWorkerTasks.delete(taskId)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
static registerJob(name: string, func: Function): (params: any[], res: (data: any) => void) => void {
|
|
10
|
+
_global.WorkerReady = 0
|
|
11
|
+
_global.WorkerCount = 0
|
|
12
|
+
|
|
13
|
+
const Worker = {
|
|
14
|
+
delete(taskId: string) {
|
|
15
|
+
_global.WorkerTasks.delete(taskId)
|
|
16
|
+
},
|
|
17
|
+
registerJob(name: string, func: Function): (params: any[], res: (data: any) => void) => void {
|
|
35
18
|
'show source';
|
|
36
19
|
const x = func.toString().replace('function', 'function ' + name)
|
|
37
20
|
_global.injectedJavaScripts.push(x)
|
|
38
|
-
|
|
21
|
+
Worker.dispatch(() => x, '', () => { })
|
|
39
22
|
return (params: (string | number | boolean)[], res: (data: string) => void) => {
|
|
40
23
|
if (Platform.OS == 'android')
|
|
41
24
|
if (Platform.Version <= 22) {
|
|
42
25
|
return res(func(...params))
|
|
43
26
|
}
|
|
44
|
-
|
|
27
|
+
Worker.dispatch(
|
|
45
28
|
(id: number) => {
|
|
46
29
|
let _params = params.map((param) => {
|
|
47
30
|
if (typeof param == 'string')
|
|
@@ -52,13 +35,12 @@ export default class m extends Component<LibWorkerProps, LibWorkerState> {
|
|
|
52
35
|
}
|
|
53
36
|
, '', res)
|
|
54
37
|
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
static registerJobAsync(name: string, func: (...fparams: any[]) => Promise<any>): (params: any[], res: (data: any) => void) => void {
|
|
38
|
+
},
|
|
39
|
+
registerJobAsync(name: string, func: (...fparams: any[]) => Promise<any>): (params: any[], res: (data: any) => void) => void {
|
|
58
40
|
'show source';
|
|
59
41
|
const x = func.toString().replace('function', 'function ' + name)
|
|
60
42
|
_global.injectedJavaScripts.push(x)
|
|
61
|
-
|
|
43
|
+
Worker.dispatch(() => x, '', () => { })
|
|
62
44
|
return (params: (string | number | boolean)[], res: (data: string) => void) => {
|
|
63
45
|
if (Platform.OS == 'android')
|
|
64
46
|
if (Platform.Version <= 22) {
|
|
@@ -66,7 +48,7 @@ export default class m extends Component<LibWorkerProps, LibWorkerState> {
|
|
|
66
48
|
return
|
|
67
49
|
}
|
|
68
50
|
|
|
69
|
-
|
|
51
|
+
Worker.dispatch(
|
|
70
52
|
(id: number) => {
|
|
71
53
|
let _params = params.map((param) => {
|
|
72
54
|
if (typeof param == 'string')
|
|
@@ -77,24 +59,22 @@ export default class m extends Component<LibWorkerProps, LibWorkerState> {
|
|
|
77
59
|
}
|
|
78
60
|
, '', res)
|
|
79
61
|
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
static objToString(data: any): string {
|
|
62
|
+
},
|
|
63
|
+
objToString(data: any): string {
|
|
83
64
|
if (Platform.OS == 'android')
|
|
84
65
|
if (Platform.Version <= 22) {
|
|
85
66
|
return JSON.stringify(data)
|
|
86
67
|
}
|
|
87
68
|
return JSON.stringify(JSON.stringify(data)).slice(1, -1);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
static jobAsync(func: (...fparams: any[]) => Promise<any>, params: (string | number | boolean)[], res: (data: any) => void): void {
|
|
69
|
+
},
|
|
70
|
+
jobAsync(func: (...fparams: any[]) => Promise<any>, params: (string | number | boolean)[], res: (data: any) => void): void {
|
|
91
71
|
'show source';
|
|
92
72
|
if (Platform.OS == 'android')
|
|
93
73
|
if (Platform.Version <= 22) {
|
|
94
74
|
(async () => res(await func(...params)))()
|
|
95
75
|
return
|
|
96
76
|
}
|
|
97
|
-
|
|
77
|
+
Worker.dispatch(
|
|
98
78
|
(id: number) => {
|
|
99
79
|
const nameFunction = func.toString().replace('function', 'function tempFunction')
|
|
100
80
|
let _params = params.map((param) => {
|
|
@@ -105,15 +85,14 @@ export default class m extends Component<LibWorkerProps, LibWorkerState> {
|
|
|
105
85
|
return (`(async () => window.ReactNativeWebView.postMessage(JSON.stringify({ data: await ` + nameFunction + `(` + _params.join(", ") + `), id: ` + id + ` })))();true;`)
|
|
106
86
|
}
|
|
107
87
|
, '', res)
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
static job(func: Function, params: (string | number | boolean)[], res: (data: any) => void): void {
|
|
88
|
+
},
|
|
89
|
+
job(func: Function, params: (string | number | boolean)[], res: (data: any) => void): void {
|
|
111
90
|
'show source';
|
|
112
91
|
if (Platform.OS == 'android')
|
|
113
92
|
if (Platform.Version <= 22) {
|
|
114
93
|
return res(func(...params))
|
|
115
94
|
}
|
|
116
|
-
|
|
95
|
+
Worker.dispatch(
|
|
117
96
|
(id: number) => {
|
|
118
97
|
const nameFunction = func.toString().replace('function', 'function tempFunction')
|
|
119
98
|
let _params = params.map((param) => {
|
|
@@ -126,46 +105,55 @@ export default class m extends Component<LibWorkerProps, LibWorkerState> {
|
|
|
126
105
|
return out
|
|
127
106
|
}
|
|
128
107
|
, '', res)
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
static dispatch(task: (id: number) => string, url: string, result: (r: string) => void): void {
|
|
136
|
-
if (_global.LibWorkerReady > 0 && typeof _global.LibWorkerBase?.current?.injectJavaScript == 'function') {
|
|
137
|
-
_global.LibWorkerCount++
|
|
138
|
-
var _task = task(_global.LibWorkerCount)
|
|
139
|
-
_global.LibWorkerTasks.set(String(_global.LibWorkerCount), {
|
|
108
|
+
},
|
|
109
|
+
dispatch(task: (id: number) => string, url: string, result: (r: string) => void): void {
|
|
110
|
+
if (_global.WorkerReady > 0 && typeof _global.WorkerBase?.current?.injectJavaScript == 'function') {
|
|
111
|
+
_global.WorkerCount++
|
|
112
|
+
var _task = task(_global.WorkerCount)
|
|
113
|
+
_global.WorkerTasks.set(String(_global.WorkerCount), {
|
|
140
114
|
task: _task,
|
|
141
115
|
result: result
|
|
142
116
|
})
|
|
143
|
-
_global.
|
|
117
|
+
_global.WorkerBase?.current?.injectJavaScript?.(_task)
|
|
144
118
|
} else {
|
|
145
119
|
setTimeout(() => {
|
|
146
|
-
|
|
120
|
+
Worker.dispatch(task, url, result)
|
|
147
121
|
}, 1000);
|
|
148
122
|
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
static onMessage(withRefName: string): any {
|
|
123
|
+
},
|
|
124
|
+
onMessage(withRefName: string): any {
|
|
152
125
|
return (e: any) => {
|
|
153
126
|
if (e.nativeEvent.data == withRefName) {
|
|
154
|
-
_global.
|
|
127
|
+
_global.WorkerReady += 1
|
|
155
128
|
return
|
|
156
129
|
}
|
|
157
130
|
const dt = e.nativeEvent.data
|
|
158
131
|
const x = JSON.parse(dt)
|
|
159
|
-
const itemTask = _global.
|
|
132
|
+
const itemTask = _global.WorkerTasks.get(String(x.id))
|
|
160
133
|
if (itemTask) {
|
|
161
134
|
itemTask.result(x.data)
|
|
162
|
-
|
|
135
|
+
Worker.delete(x.id)
|
|
163
136
|
}
|
|
164
137
|
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
138
|
+
},
|
|
139
|
+
View(): any {
|
|
140
|
+
if (Platform.OS == 'android')
|
|
141
|
+
if (Platform.Version <= 22) {
|
|
142
|
+
return null
|
|
143
|
+
}
|
|
144
|
+
return (
|
|
145
|
+
<View style={{ height: 0, width: 0 }} >
|
|
146
|
+
<WebView
|
|
147
|
+
ref={_global.WorkerBase}
|
|
148
|
+
style={{ width: 0, height: 0 }}
|
|
149
|
+
javaScriptEnabled={true}
|
|
150
|
+
injectedJavaScript={`\nwindow.ReactNativeWebView.postMessage("BaseWorkerIsReady")\n` + _global.injectedJavaScripts.join('\n') + '\ntrue;'}
|
|
151
|
+
originWhitelist={["*"]}
|
|
152
|
+
source={{ uri: esp.config("protocol") + "://" + esp.config("domain") + esp.config("uri") + "dummyPageToBypassCORS" }}
|
|
153
|
+
onMessage={Worker.onMessage('BaseWorkerIsReady')}
|
|
154
|
+
/>
|
|
155
|
+
</View>
|
|
156
|
+
)
|
|
169
157
|
}
|
|
170
158
|
}
|
|
171
|
-
|
|
159
|
+
export default Worker
|
package/modules/lib/picture.tsx
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
// withHooks
|
|
2
2
|
// noPage
|
|
3
3
|
|
|
4
|
-
import { esp, LibStyle,
|
|
4
|
+
import { esp, LibStyle, LibWorkloop, useSafeState } from 'esoftplay';
|
|
5
5
|
import * as FileSystem from 'expo-file-system';
|
|
6
6
|
import { useLayoutEffect } from 'react';
|
|
7
7
|
import { PixelRatio, Platform, View } from 'react-native';
|
|
8
8
|
import FastImage from 'react-native-fast-image';
|
|
9
|
+
import Worker from '../../libs/worker';
|
|
9
10
|
const sh = require("shorthash")
|
|
10
11
|
|
|
11
12
|
export interface LibPictureSource {
|
|
@@ -36,7 +37,7 @@ const getCacheEntry = async (uri: string, toSize: number): Promise<{ exists: boo
|
|
|
36
37
|
return { exists, path };
|
|
37
38
|
};
|
|
38
39
|
|
|
39
|
-
const fetchPicture =
|
|
40
|
+
const fetchPicture = Worker.registerJobAsync?.('lib_picture_fetch', (url: string, toSize: number) => {
|
|
40
41
|
'show source';
|
|
41
42
|
return new Promise((resolve, reject) => {
|
|
42
43
|
fetch(url, { mode: 'cors' })
|
package/modules/lib/updater.tsx
CHANGED
|
@@ -28,18 +28,18 @@ export function checkAlertInstall(): void {
|
|
|
28
28
|
check((isNew) => { if (isNew) alertInstall() })
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
export function check(callback
|
|
31
|
+
export function check(callback?: (isNew: boolean) => void): void {
|
|
32
32
|
if (__DEV__) {
|
|
33
|
-
callback(false)
|
|
33
|
+
callback?.(false)
|
|
34
34
|
return
|
|
35
35
|
}
|
|
36
36
|
Updates.checkForUpdateAsync().then(({ isAvailable }) => {
|
|
37
37
|
if (!isAvailable) {
|
|
38
|
-
callback(false)
|
|
38
|
+
callback?.(false)
|
|
39
39
|
LibProgress.hide()
|
|
40
40
|
} else {
|
|
41
41
|
Updates.fetchUpdateAsync().then(({ isNew }) => {
|
|
42
|
-
callback(isNew)
|
|
42
|
+
callback?.(isNew)
|
|
43
43
|
}).catch((e) => {
|
|
44
44
|
LibProgress.hide()
|
|
45
45
|
})
|
package/modules/user/index.tsx
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// withHooks
|
|
2
2
|
// noPage
|
|
3
3
|
|
|
4
|
-
import { esp, LibDialog, LibImage, LibNet_status, LibProgress, LibStyle, LibToast, LibUpdaterProperty, LibVersion,
|
|
4
|
+
import { esp, LibDialog, LibImage, LibNet_status, LibProgress, LibStyle, LibToast, LibUpdaterProperty, LibVersion, LibWorkloop, UseDeeplink, UserClass, UserHook, UserLoading, UserRoutes, useSafeState, _global } from 'esoftplay';
|
|
5
|
+
import Worker from 'esoftplay/libs/worker';
|
|
5
6
|
import * as Font from "expo-font";
|
|
6
7
|
import React, { useEffect, useLayoutEffect } from "react";
|
|
7
8
|
import { Platform, View } from "react-native";
|
|
@@ -31,7 +32,7 @@ function setFonts(): Promise<void> {
|
|
|
31
32
|
|
|
32
33
|
|
|
33
34
|
function isWorkerReady(onReady: () => void): void {
|
|
34
|
-
if (_global.
|
|
35
|
+
if (_global.WorkerReady < 1) {
|
|
35
36
|
setTimeout(() => isWorkerReady(onReady), 10)
|
|
36
37
|
} else {
|
|
37
38
|
onReady()
|
|
@@ -103,8 +104,6 @@ export default function m(props: UserIndexProps): any {
|
|
|
103
104
|
|
|
104
105
|
}
|
|
105
106
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
107
|
LibUpdaterProperty.check((isNew) => { })
|
|
109
108
|
}, [])
|
|
110
109
|
|
|
@@ -119,8 +118,7 @@ export default function m(props: UserIndexProps): any {
|
|
|
119
118
|
return (
|
|
120
119
|
<GestureHandlerRootView style={{ flex: 1 }}>
|
|
121
120
|
<View style={{ flex: 1 }}>
|
|
122
|
-
<
|
|
123
|
-
<LibWorkview />
|
|
121
|
+
<Worker.View />
|
|
124
122
|
{
|
|
125
123
|
loading ?
|
|
126
124
|
<UserLoading />
|
package/package.json
CHANGED
package/modules/lib/workview.tsx
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
// withHooks
|
|
2
|
-
// noPage
|
|
3
|
-
|
|
4
|
-
import { esp, LibWorker, _global } from 'esoftplay';
|
|
5
|
-
import React from 'react';
|
|
6
|
-
import { Platform, View } from 'react-native';
|
|
7
|
-
import WebView from 'react-native-webview';
|
|
8
|
-
|
|
9
|
-
export interface LibWorkviewArgs {
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
export interface LibWorkviewProps {
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
export default function m(props: LibWorkviewProps): any {
|
|
16
|
-
if (Platform.OS == 'android')
|
|
17
|
-
if (Platform.Version <= 22) {
|
|
18
|
-
return null
|
|
19
|
-
}
|
|
20
|
-
return (
|
|
21
|
-
<View style={{ height: 0, width: 0 }} >
|
|
22
|
-
<WebView
|
|
23
|
-
ref={_global.LibWorkerBase}
|
|
24
|
-
style={{ width: 0, height: 0 }}
|
|
25
|
-
javaScriptEnabled={true}
|
|
26
|
-
injectedJavaScript={`\nwindow.ReactNativeWebView.postMessage("BaseWorkerIsReady")\n` + _global.injectedJavaScripts.join('\n') + '\ntrue;'}
|
|
27
|
-
originWhitelist={["*"]}
|
|
28
|
-
source={{ uri: esp.config("protocol") + "://" + esp.config("domain") + esp.config("uri") + "dummyPageToBypassCORS" }}
|
|
29
|
-
onMessage={LibWorker.onMessage('BaseWorkerIsReady')}
|
|
30
|
-
/>
|
|
31
|
-
</View>
|
|
32
|
-
)
|
|
33
|
-
}
|