esoftplay 0.0.118 → 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/_cache.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import AsyncStorage from '@react-native-async-storage/async-storage';
2
+ import Storage from 'esoftplay/storage';
2
3
  import * as R from 'react';
3
4
  import { fastFilter, fastLoop } from './fast';
4
5
  const isEqual = require('react-fast-compare');
@@ -11,21 +12,22 @@ export interface UseCache_return<T> {
11
12
 
12
13
  export interface UseCache_options {
13
14
  persistKey?: string,
15
+ inFile?: boolean,
14
16
  listener?: (data: any) => void
15
17
  }
16
18
  export default (() => {
17
19
  let useCacheIdx = 0
18
- let useCacheSubscriber = []
19
- let value = []
20
+ let useCacheSubscriber: any[] = []
20
21
  return <T>(initValue: T, o?: UseCache_options): UseCache_return<T> => {
22
+ const STORAGE = o?.inFile ? new Storage() : AsyncStorage
21
23
  const _idx = useCacheIdx
22
24
  if (!useCacheSubscriber[_idx]) {
23
25
  useCacheSubscriber[_idx] = [];
24
26
  }
25
- value[_idx] = initValue
27
+ let value = initValue
26
28
  // rehidryte instant
27
29
  if (o?.persistKey) {
28
- AsyncStorage.getItem(o.persistKey).then((p) => {
30
+ STORAGE.getItem(o.persistKey).then((p) => {
29
31
  if (p)
30
32
  set(JSON.parse(p))
31
33
  })
@@ -33,24 +35,24 @@ export default (() => {
33
35
 
34
36
  function set(ns: T | ((x: T) => T)) {
35
37
  let isChange = false
36
- if (!isEqual(value[_idx], ns)) {
38
+ if (!isEqual(value, ns)) {
37
39
  isChange = true
38
40
  }
39
41
  if (isChange) {
40
- value[_idx] = ns instanceof Function ? ns(value[_idx]) : ns
41
- fastLoop(useCacheSubscriber[_idx], (c: any) => c?.(value[_idx]))
42
+ value = ns instanceof Function ? ns(value) : ns
43
+ fastLoop(useCacheSubscriber[_idx], (c: any) => c?.(value))
42
44
  if (o?.persistKey) {
43
- AsyncStorage.setItem(o.persistKey, JSON.stringify(value[_idx]))
45
+ STORAGE.setItem(o.persistKey, JSON.stringify(value))
44
46
  }
45
47
  if (o?.listener) {
46
- o?.listener?.(ns instanceof Function ? ns(value[_idx]) : ns)
48
+ o?.listener?.(ns instanceof Function ? ns(value) : ns)
47
49
  }
48
50
  }
49
51
  };
50
52
 
51
53
  function del() {
52
54
  if (o?.persistKey) {
53
- AsyncStorage.removeItem(o.persistKey)
55
+ STORAGE.removeItem(o.persistKey)
54
56
  }
55
57
  set(initValue)
56
58
  }
@@ -67,7 +69,7 @@ export default (() => {
67
69
 
68
70
 
69
71
  function useCache(): [T, (newCache: T | ((oldCache: T) => T)) => void, () => void] {
70
- let l = R.useRef<T>(value[_idx]).current;
72
+ let l = R.useRef<T>(value).current;
71
73
 
72
74
  const sl = (ns: T | ((oldCache: T) => T)) => {
73
75
  l = ns instanceof Function ? ns(l) : ns
@@ -78,6 +80,6 @@ export default (() => {
78
80
  return [l, set, del];
79
81
  };
80
82
  useCacheIdx++
81
- return { useCache, get: () => value[_idx], set: set };
83
+ return { useCache, get: () => value, set: set };
82
84
  }
83
85
  })()
package/bin/build.js CHANGED
@@ -24,7 +24,10 @@ const pathLowercasePrompt = DIR + 'node_modules/@react-navigation/core/src/useNa
24
24
 
25
25
  if (fs.existsSync(packjson)) {
26
26
  let txt = fs.readFileSync(packjson, 'utf8');
27
- let $package = JSON.parse(txt);
27
+ let $package
28
+ try {
29
+ $package = JSON.parse(txt)
30
+ } catch (error) { }
28
31
  let args = process.argv.slice(2);
29
32
 
30
33
  /* ADD SCRIPTS.PRESTART AND SCRIPTS.POSTSTOP */
@@ -41,7 +44,9 @@ if (fs.existsSync(packjson)) {
41
44
  if (args[0] == "install") {
42
45
  let $config = {}
43
46
  if (fs.existsSync(confjson))
44
- $config = JSON.parse(fs.readFileSync(confjson, 'utf8')) || {};
47
+ try {
48
+ $config = JSON.parse(fs.readFileSync(confjson, 'utf8')) || {};
49
+ } catch (error) { }
45
50
  if (!$config.hasOwnProperty('config')) {
46
51
  $config.config = {
47
52
  "domain": "domain.com",
@@ -63,14 +68,18 @@ if (fs.existsSync(packjson)) {
63
68
  if (err) throw err;
64
69
  console.log('config.json has been created');
65
70
  });
66
- fs.writeFile(conflivejson, JSON.stringify($config, null, 2), (err) => {
67
- if (err) throw err;
68
- console.log('config.live.json has been created');
69
- });
71
+ if (!fs.existsSync(conflivejson)) {
72
+ fs.writeFile(conflivejson, JSON.stringify($config, null, 2), (err) => {
73
+ if (err) throw err;
74
+ console.log('config.live.json has been created');
75
+ });
76
+ }
70
77
 
71
78
  let $appjson = {}
72
79
  if (fs.existsSync(appjson))
73
- $appjson = JSON.parse(fs.readFileSync(appjson, 'utf8')) || {};
80
+ try {
81
+ $appjson = JSON.parse(fs.readFileSync(appjson, 'utf8')) || {};
82
+ } catch (error) { }
74
83
  if (!$appjson.expo.hasOwnProperty('android')) {
75
84
  $appjson.expo.android = {
76
85
  "useNextNotificationsApi": true,
@@ -200,7 +209,7 @@ if (fs.existsSync(packjson)) {
200
209
  "lib": [\n\
201
210
  "es2017"\n\
202
211
  ],\n\
203
- "module": "es2022",\n\
212
+ "module": "es2015",\n\
204
213
  "moduleResolution": "node", \n\
205
214
  "noEmitHelpers": true,\n\
206
215
  "noImplicitReturns": true,\n\
package/bin/cli.js CHANGED
@@ -223,10 +223,20 @@ function createMaster(module_name) {
223
223
  throw "Mohon install esoftplay package terlebih dahulu"
224
224
  }
225
225
 
226
+ function readAsJson(path) {
227
+ let out = ""
228
+ try {
229
+ out = JSON.parse(fs.readFileSync(path, { encoding: 'utf8' }))
230
+ } catch(e) {
231
+
232
+ }
233
+ return out;
234
+ }
235
+
226
236
  function injectConfig(configPath) {
227
237
  if (fs.existsSync(configPath)) {
228
- const exsConf = require(configPath)
229
- const conf = require("./config.json")
238
+ const exsConf = readAsJson(configPath)
239
+ const conf = readAsJson("./config.json")
230
240
  let _cf = merge({ config: conf }, exsConf)
231
241
  fs.writeFileSync(configPath, JSON.stringify({..._cf}, undefined, 2))
232
242
  }
@@ -256,9 +266,9 @@ function createMaster(module_name) {
256
266
 
257
267
  /* inject lang */
258
268
  if (fs.existsSync("./id.json")) {
259
- let moduleLang = require("./id.json")
269
+ let moduleLang = readAsJson("./id.json")
260
270
  if (fs.existsSync("../../assets/locale/id.json")) {
261
- let projectLang = require("../../assets/locale/id.json")
271
+ let projectLang = readAsJson("../../assets/locale/id.json")
262
272
  let _lg = merge(moduleLang, projectLang)
263
273
  moduleLang = {..._lg}
264
274
  }
@@ -267,7 +277,7 @@ function createMaster(module_name) {
267
277
 
268
278
  /* inject libs */
269
279
  if (fs.existsSync("./libs.json")) {
270
- let libs = require("./libs.json")
280
+ let libs = readAsJson("./libs.json")
271
281
  let libsToSkip = []
272
282
  libs.forEach((element, index) => {
273
283
  console.log(element.split("@")[0])
@@ -636,8 +646,22 @@ function devClientPos(file) {
636
646
  function configAvailable(enabled) {
637
647
  if (fs.existsSync(gitignore)) {
638
648
  let _git = fs.readFileSync(gitignore, 'utf8')
639
- const ignore = "config.json"
640
- const notignore = "#config.json"
649
+ var ignore = "config.json"
650
+ var notignore = "#config.json"
651
+ if (enabled) {
652
+ _git = _git.replace(ignore, notignore)
653
+ } else {
654
+ _git = _git.replace(notignore, ignore)
655
+ }
656
+ var ignore = "config.live.json"
657
+ var notignore = "#config.live.json"
658
+ if (enabled) {
659
+ _git = _git.replace(ignore, notignore)
660
+ } else {
661
+ _git = _git.replace(notignore, ignore)
662
+ }
663
+ var ignore = "config.debug.json"
664
+ var notignore = "#config.debug.json"
641
665
  if (enabled) {
642
666
  _git = _git.replace(ignore, notignore)
643
667
  } else {
package/bin/router.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- // @ts-check
2
+ // @ts-nocheck
3
3
  /* EXECUTED ON `ESP START` TO BUILD FILE CACHES */
4
4
  const fs = require('fs');
5
5
  var checks = ['./node_modules/esoftplay/modules/', './modules/', './templates/'];
@@ -396,7 +396,8 @@ declare module "esoftplay" {
396
396
  function dispatch(action: any): any;
397
397
  function config(param?: string, ...params: string[]): any;
398
398
  function _config(): string | number | boolean;
399
- function mod(path: string): any;
399
+ function mod<T extends AllRoutes>(module: T): ModType<T>;
400
+ function modProp<T extends AllRoutes>(module: T): ModPropType<T>;
400
401
  function reducer(): any;
401
402
  function versionName(): string;
402
403
  function navigations(): any;
@@ -445,6 +446,7 @@ declare module "esoftplay" {
445
446
  }
446
447
  interface createCacheOption {
447
448
  persistKey?: string,
449
+ inFile?: boolean,
448
450
  listener?: (s:any)=> void
449
451
  }
450
452
  interface createCacheReturn<T> {
@@ -524,7 +526,16 @@ declare module "esoftplay" {
524
526
  Text += "}";
525
527
  }
526
528
  }
527
- Text += "\n\ttype LibNavigationRoutes = \"" + Navigations.join("\" | \"") + "\"\n"
529
+ Text += "\n\ttype LibNavigationRoutes = \"" + Navigations.join("\" |\n\t\t\t \"") + "\"\n"
530
+ Text += "\n\ttype AllRoutes = \"" + AllRoutes.join("\" |\n\t\t\t \"") + "\"\n"
531
+ Text += "\n\ttype ModType<T> =" + AllRoutes.map(v => {
532
+ const Words = v.split("/")
533
+ return `\t\tT extends "${v}" ? typeof ${ucword(Words[0]) + ucword(Words[1])} :`
534
+ }).join("\n") + "\nnever;\n"
535
+ Text += "\n\ttype ModPropType<T> =" + AllRoutes.map(v => {
536
+ const Words = v.split("/")
537
+ return `\t\tT extends "${v}" ? typeof ${ucword(Words[0]) + ucword(Words[1]) + "Property"} :`
538
+ }).join("\n") + "\nnever;\n"
528
539
  Text += "}"
529
540
 
530
541
  if (isChange(typesDir + "index.d.ts", Text)) {
@@ -565,6 +576,7 @@ function ucword(string) {
565
576
  }
566
577
  /* CREATE ROUTER LIST */
567
578
  var Navigations = [];
579
+ var AllRoutes = []
568
580
 
569
581
  function createRouter() {
570
582
  var Task = "";
@@ -584,7 +596,8 @@ function createRouter() {
584
596
  if (NavsExclude[nav] == false) {
585
597
  Navigations.push(nav);
586
598
  }
587
- Task += "\t\t" + 'case "' + nav + '":' + "\n\t\t\t" + 'Out = require("../../.' + Modules[module][task] + '").default' + "\n\t\t\t" + 'break;' + "\n";
599
+ AllRoutes.push(nav)
600
+ Task += "\t\t" + 'case "' + nav + '":' + "\n\t\t\t" + 'Out = require("../../.' + Modules[module][task] + '")?.default' + "\n\t\t\t" + 'break;' + "\n";
588
601
  TaskProperty += "\t\t" + 'case "' + nav + '":' + "\n\t\t\t" + 'Out = require("../../.' + Modules[module][task] + '")' + "\n\t\t\t" + 'break;' + "\n";
589
602
  /* ADD ROUTER EACH FILE FOR STATIC IMPORT */
590
603
  var item = "import { default as _" + ucword(module) + ucword(task) + " } from '../../." + Modules[module][task] + "';\n"
@@ -630,11 +643,11 @@ function createRouter() {
630
643
  });
631
644
 
632
645
  let Props = 'function properties(modtask) {' + "\n\t" +
633
- 'var let = {}' + "\n\t" +
646
+ 'var Out = {}' + "\n\t" +
634
647
  'switch (modtask) {' + "\n" +
635
648
  TaskProperty + "\t" +
636
649
  '}' + "\n\t" +
637
- 'return let;' + "\n" +
650
+ 'return Out;' + "\n" +
638
651
  '}' + "\n" +
639
652
  'module.exports = properties;';
640
653
  if (isChange(tmpDir + "properties.js", Props)) {
package/error.ts CHANGED
@@ -18,10 +18,10 @@ const myErrorHandler = (e: any, isFatal: any) => {
18
18
  }
19
19
 
20
20
  export function setError(error?: any) {
21
- let config = esp.config()
22
- let routes = UserRoutes.state().get()
23
- const user = UserClass.state().get()
24
- let lastIndex = routes?.routes?.length - 1 ?? 0
21
+ let config = esp?.config?.()
22
+ let routes = UserRoutes?.state()?.get?.()
23
+ const user = UserClass?.state()?.get?.()
24
+ let lastIndex = (routes?.routes?.length - 1) ?? 0
25
25
  let _e: any = {}
26
26
  _e['user'] = user
27
27
  _e['error'] = String(error)
@@ -30,10 +30,10 @@ export function setError(error?: any) {
30
30
  }
31
31
 
32
32
  export function reportApiError(fetch: any, error: any) {
33
- let routes = UserRoutes.state().get()
33
+ let routes = UserRoutes?.state?.()?.get?.()
34
34
  let lastIndex = routes?.routes?.length - 1 ?? 0
35
- const user = UserClass.state().get()
36
- let config = esp.config()
35
+ const user = UserClass?.state?.()?.get?.()
36
+ let config = esp?.config?.()
37
37
  let msg = [
38
38
  'slug: ' + "#" + manifest?.slug,
39
39
  'error: ' + error,
@@ -51,19 +51,19 @@ export function reportApiError(fetch: any, error: any) {
51
51
  chat_id: '-626800023',
52
52
  disable_web_page_preview: true
53
53
  }
54
- new LibCurl().custom('https://api.telegram.org/bot923808407:AAEFBlllQNKCEn8E66fwEzCj5vs9qGwVGT4/sendMessage', post)
54
+ new LibCurl()?.custom?.('https://api.telegram.org/bot923808407:AAEFBlllQNKCEn8E66fwEzCj5vs9qGwVGT4/sendMessage', post)
55
55
  } else {
56
56
  let post = {
57
57
  text: msg,
58
58
  chat_id: "-1001212227631",
59
59
  disable_web_page_preview: true
60
60
  }
61
- new LibCurl().custom('https://api.telegram.org/bot923808407:AAEFBlllQNKCEn8E66fwEzCj5vs9qGwVGT4/sendMessage', post)
61
+ new LibCurl()?.custom?.('https://api.telegram.org/bot923808407:AAEFBlllQNKCEn8E66fwEzCj5vs9qGwVGT4/sendMessage', post)
62
62
  }
63
63
  }
64
64
 
65
65
  export function getError() {
66
- let config = esp.config()
66
+ let config = esp?.config?.()
67
67
  AsyncStorage.getItem(config?.domain + 'error').then((e: any) => {
68
68
  if (e) {
69
69
  let _e = JSON.parse(e)
package/global.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import AsyncStorage from '@react-native-async-storage/async-storage';
2
- import Storage from 'esoftplay/storage';
3
2
  import * as R from 'react';
4
3
  import { fastFilter, fastLoop } from './fast';
5
4
  const _global = require('./_global')
@@ -38,6 +37,7 @@ class Context {
38
37
 
39
38
  export const globalIdx = new Context()
40
39
  export default function useGlobalState<T>(initValue: T, o?: useGlobalOption): useGlobalReturn<T> {
40
+ const Storage = require('./storage').default;
41
41
  const STORAGE = o?.inFile ? new Storage() : AsyncStorage
42
42
  const _idx = globalIdx.idx
43
43
  if (!useGlobalSubscriber[_idx])
@@ -48,30 +48,15 @@ export default function useGlobalState<T>(initValue: T, o?: useGlobalOption): us
48
48
  let persistKey = o?.persistKey
49
49
  STORAGE.getItem(persistKey).then((p) => {
50
50
  if (p) {
51
- // console.log(persistKey + " = " + p?.length)
52
- // if (persistKey == 'lib_apitest_debug') {
53
- // console.log(p)
54
- // }
55
- // const byteSize = str => new Blob([str]).size;
56
- // function bytesToSize(bytes) {
57
- // var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
58
- // if (bytes == 0) return '0 Byte';
59
- // var i = parseInt(String(Math.floor(Math.log(bytes) / Math.log(1024))));
60
- // return Math.round(bytes / Math.pow(1024, i)) + ' ' + sizes[i];
61
- // }
62
- // console.log(persistKey + ' => ' + bytesToSize(byteSize(p)))
63
51
  if (p.includes("\\\\\\\\")) {
64
52
  if (persistKey)
65
53
  STORAGE.clear()
66
54
  return
67
55
  }
68
- if (p.startsWith("{") || p.startsWith("["))
56
+ if (p != undefined && typeof p == 'string' && (p.startsWith("{") || p.startsWith("[")))
69
57
  try { set(JSON.parse(p)) } catch (error) { }
70
58
  else
71
- try {
72
- // @ts-ignore
73
- set(p)
74
- } catch (error) { }
59
+ try { /* @ts-ignore */ set(eval(p)) } catch (error) { }
75
60
  }
76
61
  })
77
62
  }
@@ -82,8 +67,10 @@ export default function useGlobalState<T>(initValue: T, o?: useGlobalOption): us
82
67
  set(initValue)
83
68
  }
84
69
  if (o?.persistKey) {
85
- const UserData = require('./modules/user/data').default
86
- UserData.register(o?.persistKey)
70
+ const esp = require('./esp').default;
71
+ const UserData = esp.mod('user/data')
72
+ if (UserData)
73
+ UserData?.register?.(o?.persistKey)
87
74
  }
88
75
  _global.useGlobalUserDelete[_idx] = resetFunction
89
76
  }
@@ -96,17 +83,12 @@ export default function useGlobalState<T>(initValue: T, o?: useGlobalOption): us
96
83
  if (o?.persistKey && ns != undefined) {
97
84
  let data: any
98
85
  switch (typeof ns) {
99
- case 'string':
100
- case 'boolean':
101
- case 'number':
102
- case 'bigint':
103
- case 'undefined':
104
- data = String(ns)
105
- break
106
86
  case 'object':
107
87
  if (ns != null || ns != undefined)
108
88
  data = JSON.stringify(ns)
109
89
  break;
90
+ default:
91
+ data = String(ns)
110
92
  }
111
93
  STORAGE.setItem(o.persistKey, data)
112
94
  }
@@ -1,47 +1,30 @@
1
- // noPage
2
-
3
- import { _global } from 'esoftplay';
4
- import React, { Component } from "react";
5
- import { Platform } from 'react-native';
6
-
7
-
8
- export interface LibWorkerInit {
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.LibWorkerReady = 0
24
- _global.LibWorkerCount = 0
25
-
26
- export default class m extends Component<LibWorkerProps, LibWorkerState> {
27
- constructor(props: LibWorkerProps) {
28
- super(props)
29
- }
30
- static delete(taskId: string): void {
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
- m.dispatch(() => x, '', () => { })
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
- m.dispatch(
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
- m.dispatch(() => x, '', () => { })
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
- m.dispatch(
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
- m.dispatch(
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
- m.dispatch(
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
- // static image(url: string, toSize: number, result: (r: string) => void): void {
132
- // m.dispatch((id) => `imageCompress("` + id + `", "` + url + `", ` + PixelRatio.getPixelSizeForLayoutSize(toSize) + `)`, url, result)
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.LibWorkerBase?.current?.injectJavaScript?.(_task)
117
+ _global.WorkerBase?.current?.injectJavaScript?.(_task)
144
118
  } else {
145
119
  setTimeout(() => {
146
- m.dispatch(task, url, result)
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.LibWorkerReady += 1
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.LibWorkerTasks.get(String(x.id))
132
+ const itemTask = _global.WorkerTasks.get(String(x.id))
160
133
  if (itemTask) {
161
134
  itemTask.result(x.data)
162
- m.delete(x.id)
135
+ Worker.delete(x.id)
163
136
  }
164
137
  }
165
- }
166
-
167
- render(): any {
168
- return null
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
@@ -3,7 +3,7 @@
3
3
  import { Component } from "react";
4
4
  const isEqual = require("react-fast-compare");
5
5
 
6
- export default class SaveComponent <K, S, U = any> extends Component<K, S, U>{
6
+ export default class m <K, S, U = any> extends Component<K, S, U>{
7
7
  _isMounted: boolean = false
8
8
  state: any
9
9
  props: any
@@ -7,7 +7,7 @@ import Constants from 'expo-constants';
7
7
 
8
8
  const { manifest } = Constants;
9
9
 
10
- export default class ecurl {
10
+ export default class m {
11
11
  controller = new AbortController()
12
12
  signal = this.controller.signal
13
13
  timeout = 30000;
@@ -1,28 +1,28 @@
1
1
  // noPage
2
2
 
3
3
  import {
4
- AntDesign, Entypo,
5
- EvilIcons,
6
- Feather,
7
- FontAwesome,
8
- Fontisto,
9
- Foundation, Ionicons, MaterialCommunityIcons, MaterialIcons,
10
- Octicons, SimpleLineIcons, Zocial
4
+ AntDesign, Entypo,
5
+ EvilIcons,
6
+ Feather,
7
+ FontAwesome,
8
+ Fontisto,
9
+ Foundation, Ionicons, MaterialCommunityIcons, MaterialIcons,
10
+ Octicons, SimpleLineIcons, Zocial
11
11
  } from '@expo/vector-icons';
12
12
  import {
13
- AntDesignTypes,
14
- EntypoTypes,
15
- EvilIconsTypes,
16
- FeatherTypes,
17
- FontAwesomeTypes,
18
- FontistoTypes,
19
- FoundationTypes,
20
- IoniconsTypes,
21
- MaterialCommunityIconsTypes,
22
- MaterialIconsTypes,
23
- OcticonsTypes,
24
- SimpleLineIconsTypes,
25
- ZocialTypes
13
+ AntDesignTypes,
14
+ EntypoTypes,
15
+ EvilIconsTypes,
16
+ FeatherTypes,
17
+ FontAwesomeTypes,
18
+ FontistoTypes,
19
+ FoundationTypes,
20
+ IoniconsTypes,
21
+ MaterialCommunityIconsTypes,
22
+ MaterialIconsTypes,
23
+ OcticonsTypes,
24
+ SimpleLineIconsTypes,
25
+ ZocialTypes
26
26
  } from '@expo/vector-icons/build/esoftplay_icons';
27
27
  import { LibComponent } from 'esoftplay';
28
28
  import React from 'react';
@@ -113,7 +113,7 @@ export interface LibIconState {
113
113
 
114
114
  }
115
115
 
116
- export default class icon extends LibComponent<LibIconProps, LibIconState>{
116
+ export default class m extends LibComponent<LibIconProps, LibIconState>{
117
117
 
118
118
  constructor(props: LibIconProps) {
119
119
  super(props);
@@ -47,7 +47,7 @@ export interface LibListProps {
47
47
  export interface LibListState {
48
48
  }
49
49
 
50
- export default class EList extends LibComponent<LibListProps, LibListState> {
50
+ export default class m extends LibComponent<LibListProps, LibListState> {
51
51
 
52
52
  view: any = React.createRef()
53
53
  flatlist = React.createRef<FlatList<View>>()
@@ -0,0 +1,46 @@
1
+ // useLibs
2
+
3
+ import { LibCrypt, LibObject, useGlobalState } from 'esoftplay';
4
+
5
+ export interface LibNotifyItem {
6
+ to: string,
7
+ sound: string,
8
+ title: string,
9
+ body: string,
10
+ data: any,
11
+ }
12
+ export interface LibNotifyProps {
13
+ notifications: LibNotifyItem[]
14
+ }
15
+
16
+ const state = useGlobalState([], { persistKey: 'lib_notify', inFile: true })
17
+
18
+ export default function libnotify(res: LibNotifyProps): any {
19
+ if (res.notifications && Array.isArray(res.notifications)) {
20
+ res.notifications.forEach(curl)
21
+ }
22
+ }
23
+
24
+ const curl = (data: LibNotifyItem) => {
25
+ let dData: any = data
26
+ if (!dData.to.includes("ExponentPushToken")) {
27
+ dData['to'] = new LibCrypt().decode(dData.to)
28
+ }
29
+ fetch('https://exp.host/--/api/v2/push/send', {
30
+ method: 'POST',
31
+ headers: {
32
+ Accept: 'application/json',
33
+ 'Accept-encoding': 'gzip, deflate',
34
+ 'Content-Type': 'application/json',
35
+ },
36
+ body: JSON.stringify(dData),
37
+ }).then((response) => response.json())
38
+ .then((data) => {
39
+ console.log('Success:', data);
40
+ })
41
+ .catch((error) => {
42
+ console.error('Error:', error);
43
+ const x = LibObject.push(state.get(), dData)()
44
+ state.set(x)
45
+ });
46
+ }
@@ -1,11 +1,12 @@
1
1
  // withHooks
2
2
  // noPage
3
3
 
4
- import { esp, LibStyle, LibWorker, LibWorkloop, useSafeState } from 'esoftplay';
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 = LibWorker?.registerJobAsync?.('lib_picture_fetch', (url: string, toSize: number) => {
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' })
@@ -52,7 +52,7 @@ export interface LibScrollState {
52
52
  data: any
53
53
  }
54
54
 
55
- export default class escroll extends LibComponent<LibScrollProps, LibScrollState> {
55
+ export default class m extends LibComponent<LibScrollProps, LibScrollState> {
56
56
 
57
57
  flatscroll = React.createRef<ScrollView>();
58
58
  idxNumber = []
@@ -3,10 +3,10 @@
3
3
  import { LibComponent } from 'esoftplay';
4
4
  import React from 'react';
5
5
  import {
6
- Dimensions,
7
- Platform, ScrollView, StyleSheet,
8
- Text,
9
- View
6
+ Dimensions,
7
+ Platform, ScrollView, StyleSheet,
8
+ Text,
9
+ View
10
10
  } from 'react-native';
11
11
 
12
12
  export interface LibScrollpickerProps {
@@ -72,7 +72,7 @@ function Skeleton(props: LibSkeletonProps): any {
72
72
  }
73
73
  })
74
74
 
75
- useEffect(() => {
75
+ /* sd */useEffect(() => {
76
76
  offset.value = -LibStyle.width * 0.75
77
77
  offset.value = withRepeat(withTiming(LibStyle.width * 0.5, { duration: props.duration || 1000 }), -1, props.reverse ?? false)
78
78
  }, [])
@@ -16,7 +16,7 @@ export interface LibSocialloginState {
16
16
 
17
17
  }
18
18
 
19
- export default class esocialLogin extends LibComponent<LibSocialloginProps, LibSocialloginState> {
19
+ export default class m extends LibComponent<LibSocialloginProps, LibSocialloginState> {
20
20
  props: LibSocialloginProps
21
21
 
22
22
  constructor(props: LibSocialloginProps) {
@@ -83,7 +83,7 @@ const defaultStyle = {
83
83
  },
84
84
  }
85
85
 
86
- export default class Style {
86
+ export default class m {
87
87
  static isIphoneX: boolean = isIphoneX();
88
88
  static STATUSBAR_HEIGHT: number = STATUSBAR_HEIGHT;
89
89
  static STATUSBAR_HEIGHT_MASTER: number = STATUSBAR_HEIGHT_MASTER;
@@ -17,7 +17,7 @@ export interface LibTextstyleState {
17
17
 
18
18
  }
19
19
 
20
- export default class etextstyle extends LibComponent<LibTextstyleProps, LibTextstyleState>{
20
+ export default class m extends LibComponent<LibTextstyleProps, LibTextstyleState>{
21
21
  props: any
22
22
 
23
23
  constructor(props: LibTextstyleProps) {
@@ -28,18 +28,18 @@ export function checkAlertInstall(): void {
28
28
  check((isNew) => { if (isNew) alertInstall() })
29
29
  }
30
30
 
31
- export function check(callback: (isNew: boolean) => void): void {
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
  })
@@ -19,7 +19,7 @@ export type LibUtilsTravelMode = 'driving' | 'walking'
19
19
  let installationIdDefault
20
20
  const installationId = createCache(installationIdDefault, { persistKey: 'installationId' })
21
21
  const cache = createCache<any>({ inDebounce: undefined })
22
- export default class eutils {
22
+ export default class m {
23
23
 
24
24
  static checkUndefined(obj: any, cursorsAsString: string): boolean {
25
25
  var args = cursorsAsString.split('.')
@@ -10,7 +10,7 @@ import moment from "../../moment";
10
10
 
11
11
  const state = useGlobalState?.(null, { persistKey: "user" })
12
12
 
13
- export default class eclass {
13
+ export default class m {
14
14
  static state(): useGlobalReturn<any> {
15
15
  return state
16
16
  }
@@ -33,7 +33,7 @@ export default class eclass {
33
33
 
34
34
  static isLogin(callback: (user?: any | null) => void): Promise<any> {
35
35
  return new Promise((r, j) => {
36
- eclass.load().then((user) => {
36
+ m.load().then((user) => {
37
37
  r(user);
38
38
  if (callback) callback(user);
39
39
  }).catch((nouser) => {
@@ -1,7 +1,8 @@
1
1
  // withHooks
2
2
  // noPage
3
3
 
4
- import { esp, LibDialog, LibImage, LibNet_status, LibProgress, LibStyle, LibToast, LibUpdaterProperty, LibVersion, LibWorker, LibWorkloop, LibWorkview, UseDeeplink, UserClass, UserHook, UserLoading, UserRoutes, useSafeState, _global } from 'esoftplay';
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.LibWorkerReady < 1) {
35
+ if (_global.WorkerReady < 1) {
35
36
  setTimeout(() => isWorkerReady(onReady), 10)
36
37
  } else {
37
38
  onReady()
@@ -39,7 +40,8 @@ function isWorkerReady(onReady: () => void): void {
39
40
  }
40
41
 
41
42
 
42
- export default function UserIndex(props: UserIndexProps): any {
43
+
44
+ export default function m(props: UserIndexProps): any {
43
45
  const [loading, setLoading] = useSafeState(true)
44
46
  const user = UserClass.state().useSelector(s => s)
45
47
  const ready = React.useRef(0)
@@ -57,6 +59,11 @@ export default function UserIndex(props: UserIndexProps): any {
57
59
 
58
60
  useLayoutEffect(() => {
59
61
  let limitReady = 3
62
+
63
+ if (esp.config("asyncWorker") == true) {
64
+ limitReady = 2
65
+ }
66
+
60
67
  if (Platform.OS == 'android') {
61
68
  if (Platform.Version <= 22) {
62
69
  limitReady = 2
@@ -71,7 +78,7 @@ export default function UserIndex(props: UserIndexProps): any {
71
78
  }
72
79
  })
73
80
  }
74
-
81
+
75
82
  (async () => {
76
83
  await setFonts()
77
84
  ready.current += 1
@@ -79,7 +86,7 @@ export default function UserIndex(props: UserIndexProps): any {
79
86
  setLoading(false)
80
87
  }
81
88
  })()
82
-
89
+
83
90
  UserClass.isLogin(async () => {
84
91
  ready.current += 1
85
92
  if (ready.current >= limitReady) {
@@ -87,8 +94,16 @@ export default function UserIndex(props: UserIndexProps): any {
87
94
  }
88
95
  })
89
96
 
90
- //esoftplay-chatting
91
-
97
+
98
+ if (esp.config('firebase').hasOwnProperty('apiKey')) {
99
+ try {
100
+ const ChattingFirebase = esp.mod('chatting/firebase')
101
+ if (ChattingFirebase)
102
+ ChattingFirebase?.signInAnonymously?.();
103
+ } catch (error) {
104
+
105
+ }
106
+ }
92
107
  LibUpdaterProperty.check((isNew) => { })
93
108
  }, [])
94
109
 
@@ -103,21 +118,22 @@ export default function UserIndex(props: UserIndexProps): any {
103
118
  return (
104
119
  <GestureHandlerRootView style={{ flex: 1 }}>
105
120
  <View style={{ flex: 1 }}>
106
- <LibWorker />
107
- <LibWorkview />
108
- <LibWorkloop />
121
+ <Worker.View />
109
122
  {
110
123
  loading ?
111
124
  <UserLoading />
112
125
  :
113
- <Navs user={user} initialState={initialState} handler={handler} />
126
+ <>
127
+ <LibWorkloop />
128
+ <Navs user={user} initialState={initialState} handler={handler} />
129
+ <LibNet_status />
130
+ <LibDialog style={'default'} />
131
+ <LibImage />
132
+ <LibProgress />
133
+ <LibToast />
134
+ <UserHook />
135
+ </>
114
136
  }
115
- <LibNet_status />
116
- <LibDialog style={'default'} />
117
- <LibImage />
118
- <LibProgress />
119
- <UserHook />
120
- <LibToast />
121
137
  </View>
122
138
  <View style={{ backgroundColor: LibStyle.colorNavigationBar || 'white', height: LibStyle.isIphoneX ? 35 : 0 }} />
123
139
  </GestureHandlerRootView>
@@ -1,7 +1,7 @@
1
1
  import { Ionicons } from "@expo/vector-icons";
2
2
  import {
3
- esp, LibComponent, LibCrypt,
4
- LibCurl, LibStyle, UserClass
3
+ esp, LibComponent, LibCrypt,
4
+ LibCurl, LibStyle, UserClass
5
5
  } from "esoftplay";
6
6
  import { StatusBar } from 'expo-status-bar';
7
7
  import React from "react";
@@ -30,7 +30,7 @@ export interface UserLoginState {
30
30
  isLoading: boolean
31
31
  }
32
32
 
33
- export default class euserLogin extends LibComponent<UserLoginProps, UserLoginState> {
33
+ export default class m extends LibComponent<UserLoginProps, UserLoginState> {
34
34
 
35
35
  inputUsername: any;
36
36
  inputPassword: any;
@@ -14,7 +14,7 @@ export interface UserNotifbadgeState {
14
14
  }
15
15
 
16
16
 
17
- export default class Enotifbadge extends LibComponent<UserNotifbadgeProps, UserNotifbadgeState> {
17
+ export default class m extends LibComponent<UserNotifbadgeProps, UserNotifbadgeState> {
18
18
 
19
19
  props: UserNotifbadgeProps
20
20
  constructor(props: UserNotifbadgeProps) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "esoftplay",
3
- "version": "0.0.118",
3
+ "version": "0.0.119-c",
4
4
  "description": "embedding data from esoftplay framework (web based) into mobile app",
5
5
  "main": "cache/index.js",
6
6
  "types": "../../index.d.ts",
package/storage.ts CHANGED
@@ -27,7 +27,7 @@ export default class Storage {
27
27
  }
28
28
 
29
29
  private getDBPath(key: string): string {
30
- const path = `${CACHE_DIR}${key}.txt`;
30
+ const path = `${CACHE_DIR}${key.replace(/\\/g, "_")}.txt`;
31
31
  return path
32
32
  }
33
33
 
@@ -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
- }