esoftplay 0.0.142 → 0.0.143

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.
Files changed (90) hide show
  1. package/bin/build.js +1 -0
  2. package/bin/cli.js +327 -6
  3. package/error.ts +17 -1
  4. package/esp.ts +1 -1
  5. package/global.ts +75 -60
  6. package/mmkv.ts +6 -0
  7. package/modules/lib/autoreload.ts +3 -0
  8. package/modules/lib/carrousel.tsx +1 -0
  9. package/modules/lib/carrousel_snap.tsx +1 -0
  10. package/modules/lib/collaps.tsx +1 -0
  11. package/modules/lib/component.tsx +1 -0
  12. package/modules/lib/compose.tsx +22 -15
  13. package/modules/lib/curl.ts +37 -9
  14. package/modules/lib/curl_view.tsx +69 -0
  15. package/modules/lib/custom.tsx +5 -4
  16. package/modules/lib/datepicker.tsx +3 -2
  17. package/modules/lib/dialog.tsx +13 -2
  18. package/modules/lib/direct_text.tsx +2 -1
  19. package/modules/lib/dropdown.tsx +1 -0
  20. package/modules/lib/editbox.tsx +4 -2
  21. package/modules/lib/effect.tsx +1 -0
  22. package/modules/lib/fadescroll.tsx +2 -0
  23. package/modules/lib/focus.tsx +1 -1
  24. package/modules/lib/font.ts +1 -0
  25. package/modules/lib/gallery.tsx +1 -0
  26. package/modules/lib/global.tsx +1 -0
  27. package/modules/lib/gradient.tsx +3 -2
  28. package/modules/lib/icon.tsx +14 -1
  29. package/modules/lib/image.tsx +9 -0
  30. package/modules/lib/image_crop.tsx +2 -0
  31. package/modules/lib/image_multi.tsx +1 -0
  32. package/modules/lib/image_shadow.tsx +4 -3
  33. package/modules/lib/infinite.tsx +1 -0
  34. package/modules/lib/input.tsx +15 -2
  35. package/modules/lib/keyboard_avoid.tsx +1 -1
  36. package/modules/lib/lazy.tsx +1 -0
  37. package/modules/lib/list.tsx +2 -2
  38. package/modules/lib/loading.tsx +1 -0
  39. package/modules/lib/locale.ts +6 -0
  40. package/modules/lib/navigation.ts +28 -0
  41. package/modules/lib/net_status.tsx +3 -0
  42. package/modules/lib/notification.ts +15 -2
  43. package/modules/lib/notify.ts +1 -0
  44. package/modules/lib/numbermeter.tsx +106 -0
  45. package/modules/lib/object.ts +25 -0
  46. package/modules/lib/picture.tsx +8 -2
  47. package/modules/lib/pin.tsx +1 -0
  48. package/modules/lib/pipe.ts +5 -1
  49. package/modules/lib/progress.tsx +6 -1
  50. package/modules/lib/scroll.tsx +1 -1
  51. package/modules/lib/scrollpicker.tsx +2 -1
  52. package/modules/lib/skeleton.tsx +6 -1
  53. package/modules/lib/slidingup.tsx +5 -0
  54. package/modules/lib/sociallogin.tsx +4 -1
  55. package/modules/lib/statusbar.tsx +1 -0
  56. package/modules/lib/style.ts +1 -0
  57. package/modules/lib/tabs.tsx +1 -1
  58. package/modules/lib/textstyle.tsx +1 -1
  59. package/modules/lib/theme.tsx +1 -1
  60. package/modules/lib/timepicker.tsx +2 -2
  61. package/modules/lib/toast.tsx +3 -1
  62. package/modules/lib/updater.tsx +5 -1
  63. package/modules/lib/utils.ts +41 -0
  64. package/modules/lib/version.tsx +7 -1
  65. package/modules/lib/version_view.tsx +1 -0
  66. package/modules/lib/video.tsx +1 -0
  67. package/modules/lib/webview.tsx +7 -3
  68. package/modules/lib/worker.tsx +5 -2
  69. package/modules/lib/workloop.tsx +1 -0
  70. package/modules/main/index.tsx +2 -2
  71. package/modules/use/condition.tsx +1 -0
  72. package/modules/use/curl.ts +1 -1
  73. package/modules/use/deeplink.ts +3 -2
  74. package/modules/use/form.ts +1 -0
  75. package/modules/use/map.tsx +1 -1
  76. package/modules/use/tasks.ts +2 -0
  77. package/modules/use/worker.tsx +1 -1
  78. package/modules/user/class.ts +7 -0
  79. package/modules/user/data.ts +37 -11
  80. package/modules/user/hook.tsx +1 -0
  81. package/modules/user/index.tsx +2 -0
  82. package/modules/user/loading.tsx +1 -0
  83. package/modules/user/notification.tsx +1 -0
  84. package/modules/user/notification_item.tsx +1 -0
  85. package/modules/user/routes.ts +4 -0
  86. package/moment.ts +2 -0
  87. package/package.json +1 -1
  88. package/render.tsx +11 -1
  89. package/subscribe.ts +1 -1
  90. package/timeout.ts +6 -0
package/bin/build.js CHANGED
@@ -267,6 +267,7 @@ npm-debug.*\n\
267
267
  package-lock.json\n\
268
268
  assets/esoftplaymodules/\n\
269
269
  bun.lockb\n\
270
+ bun.lock\n\
270
271
  yarn.lock\n\
271
272
  yarn-error.log\n\
272
273
  `
package/bin/cli.js CHANGED
@@ -1,8 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
  const fs = require('fs');
3
3
  const exec = require('child_process').execSync;
4
-
4
+ const fetch = require("node-fetch")
5
5
  const path = require('path');
6
+ const https = require('https');
6
7
  const os = require('os')
7
8
  const readline = require('readline');
8
9
  const DIR = "./"
@@ -23,10 +24,15 @@ const gplistdebug = DIR + "GoogleService-Info.debug.plist"
23
24
  var args = process.argv.slice(2);
24
25
 
25
26
  // console.log(modpath, "sdofsjdofjsd")
26
- function execution() {
27
- const cmd = `watchman watch-del ./ && watchman watch ./ && watchman -j <<< '["trigger","./",{"name":"esp","expression":["allof",["not",["dirname","node_modules"]],["not",["name","index.d.ts"]]],"command":["bun","./node_modules/esoftplay/bin/router.js"],"append_files":true}]' && bun ./node_modules/esoftplay/bin/run.js && bun ./node_modules/esoftplay/bin/gen.js && bun ./node_modules/esoftplay/bin/router.js`
28
- command(cmd)
29
-
27
+ async function execution() {
28
+ const preload = await preload_api()
29
+ console.log("PRELOAD", preload)
30
+ if (preload) {
31
+ const cmd = `watchman watch-del ./ && watchman watch ./ && watchman -j <<< '["trigger","./",{"name":"esp","expression":["allof",["not",["dirname","node_modules"]],["not",["name","index.d.ts"]]],"command":["bun","./node_modules/esoftplay/bin/router.js"],"append_files":true}]' && bun ./node_modules/esoftplay/bin/run.js && bun ./node_modules/esoftplay/bin/gen.js && bun ./node_modules/esoftplay/bin/router.js`
32
+ command(cmd)
33
+ } else {
34
+ console.log("SINI GAES")
35
+ }
30
36
  }
31
37
 
32
38
  if (args.length == 0) {
@@ -535,7 +541,149 @@ function isCustomUpdates() {
535
541
  return false
536
542
  }
537
543
 
538
- function publish(notes) {
544
+ async function preload_api() {
545
+ let out = true
546
+ let cjson = await readToJSON(confjson)
547
+ const { protocol, domain, uri, preload_api } = cjson.config
548
+ if (preload_api?.length > 0) {
549
+ fs.rmSync("./assets/preload_api", { recursive: true, force: true })
550
+ fs.rmSync("./assets/preload_assets", { recursive: true, force: true })
551
+ for (const apiUri of preload_api) {
552
+ let fullUrl = apiUri.includes("://") ? apiUri : `${(protocol || 'http')}://api.${domain}${(uri || "/")}${apiUri}`
553
+ const lastString = fullUrl.slice(fullUrl.lastIndexOf("/") + 1) // Fixed index adjustment
554
+ try {
555
+ const data = await fetch(fullUrl).then((res) => res.text())
556
+ if (data) {
557
+ try {
558
+ if (JSON.parse(data).ok === 0) {
559
+ consoleError(`-> preload_api: ${fullUrl}`)
560
+ fs.writeFileSync(`./assets/preload_api/${lastString}.json`, data)
561
+ out = false
562
+ return out
563
+ }
564
+ } catch (error) {
565
+ fs.writeFileSync(`./assets/preload_api/${lastString}.json`, data)
566
+ consoleError(`-> preload_api: ${fullUrl}`)
567
+ out = false
568
+ return out
569
+ }
570
+ /* sukses */
571
+ if (!fs.existsSync("./assets/preload_api")) {
572
+ fs.mkdirSync('./assets/preload_api', { recursive: true })
573
+ }
574
+ fs.writeFileSync(`./assets/preload_api/${lastString}.json`, data)
575
+ let objectData = JSON.parse(data)
576
+
577
+ async function readDeepObject(obj, path = []) {
578
+ if (Array.isArray(obj)) {
579
+ obj.forEach(async (item, index) => {
580
+ await readDeepObject(item, [...path, index]);
581
+ });
582
+ } else if (typeof obj === "object" && obj !== null) {
583
+ Object.keys(obj).forEach(async (key) => {
584
+ await readDeepObject(obj[key], [...path, key]);
585
+ });
586
+ } else if (obj != undefined) {
587
+ const value = obj
588
+ var cursor = path.join(".")
589
+ if (/\.(jpg|jpeg|png|gif|bmp|webp|svg|pdf|txt)$/i.test(value)) {
590
+ const localFilePath = await downloadFile(value, "./assets/preload_assets/" + lastString)
591
+ objectData = LibObject.set(objectData, String(localFilePath)?.replace('assets/', ''))(cursor)
592
+ const newData = JSON.stringify(objectData, undefined, 2)
593
+ fs.writeFileSync(`./assets/preload_api/${lastString}.json`, newData, { encoding: "utf8" })
594
+ }
595
+ }
596
+ }
597
+
598
+ async function downloadFile(url, downloadDir = "./assets/preload_assets", retries = 3) {
599
+ if (!fs.existsSync(downloadDir)) {
600
+ fs.mkdirSync(downloadDir, { recursive: true });
601
+ }
602
+ const fileName = path.basename(url);
603
+ const filePath = path.join(downloadDir, fileName);
604
+
605
+ for (let attempt = 1; attempt <= retries; attempt++) {
606
+ try {
607
+ return await new Promise((resolve, reject) => {
608
+ const fileStream = fs.createWriteStream(filePath);
609
+ const request = https.get(url, (response) => {
610
+ if (response.statusCode !== 200) {
611
+ reject(new Error(`Failed to fetch ${url}: ${response.statusCode}`));
612
+ return;
613
+ }
614
+
615
+ response.pipe(fileStream);
616
+
617
+ fileStream.on('finish', () => {
618
+ fileStream.close(() => {
619
+ // Validate that file is not empty
620
+ if (fs.statSync(filePath).size > 0) {
621
+ resolve(filePath);
622
+ } else {
623
+ reject(new Error(`Downloaded file is empty: ${filePath}`));
624
+ }
625
+ });
626
+ });
627
+
628
+ fileStream.on('error', (error) => {
629
+ fileStream.close(() => reject(error));
630
+ });
631
+ });
632
+
633
+ request.on('error', (error) => reject(error));
634
+ });
635
+ } catch (error) {
636
+ console.error(`Attempt ${attempt} failed:`, error);
637
+ if (attempt === retries) {
638
+ return null; // Return null after final attempt
639
+ }
640
+ }
641
+ }
642
+ }
643
+ // async function downloadFile(url, downloadDir = "./assets/preload_assets") {
644
+ // if (!fs.existsSync("./assets/preload_assets")) {
645
+ // fs.mkdirSync("./assets/preload_assets")
646
+ // }
647
+ // try {
648
+ // const https = require('https');
649
+ // const fileName = path.basename(url);
650
+ // const filePath = path.join(downloadDir, fileName);
651
+ // const fileStream = fs.createWriteStream(filePath);
652
+
653
+ // return new Promise((resolve, reject) => {
654
+ // https.get(url, (response) => {
655
+ // if (response.statusCode !== 200) {
656
+ // reject(new Error(`Failed to fetch ${url}: ${response.statusCode}`));
657
+ // return;
658
+ // }
659
+ // response.pipe(fileStream);
660
+ // fileStream.on('finish', () => resolve(filePath));
661
+ // fileStream.on('error', reject);
662
+ // }).on('error', reject);
663
+ // });
664
+ // } catch (error) {
665
+ // console.error(`Error downloading file ${url}:`, error);
666
+ // return null;
667
+ // }
668
+ // }
669
+
670
+ await readDeepObject(objectData)
671
+ consoleSucces("-> preload_api: " + fullUrl)
672
+ /* endSukses */
673
+ }
674
+ } catch (error) {
675
+ out = false
676
+ consoleError(`-> preload_api: ${fullUrl}`)
677
+ }
678
+ }
679
+ }
680
+ return out
681
+ }
682
+
683
+ async function publish(notes) {
684
+ if (!await preload_api()) {
685
+ return consoleError("Preload API ada yg error, tidak bisa publish")
686
+ }
539
687
  let status = "-"
540
688
  let isCustomServer = false
541
689
  let ajson = readToJSON(appjson)
@@ -1237,6 +1385,12 @@ function switchStatus(status) {
1237
1385
  const [usr, pwd] = cjson.config.build
1238
1386
  command(`eas logout && expect -c 'spawn eas login; expect "Email or username"; send "${usr}\r"; expect "Password"; send "${pwd}\r"; expect eof;'`)
1239
1387
  }
1388
+ if (cjson.config.hasOwnProperty('post_script')) {
1389
+ eval(cjson.config.post_script)
1390
+ }
1391
+ }
1392
+ if (valid) {
1393
+
1240
1394
  }
1241
1395
  }
1242
1396
  if (valid && fs.existsSync(gplist))
@@ -1255,6 +1409,173 @@ function tm(message) {
1255
1409
  command("curl -d \"text=" + message + "&disable_web_page_preview=true&chat_id=-1001227788828\" 'https://api.telegram.org/bot112133589:AAFFyztZh79OsHRCxJ9rGCGpnxkcjWBP8kU/sendMessage'")
1256
1410
  }
1257
1411
 
1412
+ class LibObject {
1413
+ #value = undefined;
1414
+
1415
+ constructor(array) {
1416
+ this.#value = array;
1417
+ this.value = this.value.bind(this);
1418
+ this.push = this.push.bind(this);
1419
+ this.unset = this.unset.bind(this);
1420
+ this.unshift = this.unshift.bind(this);
1421
+ this.set = this.set.bind(this);
1422
+ this.splice = this.splice.bind(this);
1423
+ this.update = this.update.bind(this);
1424
+ this.assign = this.assign.bind(this);
1425
+ this.cursorBuilder = this.cursorBuilder.bind(this);
1426
+ }
1427
+
1428
+ cursorBuilder(command, array, value, ...values) {
1429
+ return (cursor, ...cursors) => {
1430
+ let pathToUpdate = [cursor, ...cursors].filter(x => x != undefined).join('.');
1431
+ let allValues = [value, ...values].filter(x => x != undefined);
1432
+ let spec = {};
1433
+ if (pathToUpdate !== '') spec = { [pathToUpdate]: [command, ...allValues] };
1434
+ else spec = [command, ...allValues];
1435
+ this.#value = update(array, spec);
1436
+ return this;
1437
+ };
1438
+ }
1439
+
1440
+ push(value, ...values) {
1441
+ return this.cursorBuilder("push", this.#value, value, ...values);
1442
+ }
1443
+
1444
+ unshift(value, ...values) {
1445
+ return this.cursorBuilder("unshift", this.#value, value, ...values);
1446
+ }
1447
+
1448
+ splice(index, deleteCount, value, ...values) {
1449
+ return this.cursorBuilder("splice", this.#value, index, deleteCount, value, ...values);
1450
+ }
1451
+
1452
+ unset(index, ...indexs) {
1453
+ return this.cursorBuilder("unset", this.#value, index, ...indexs);
1454
+ }
1455
+
1456
+ set(value) {
1457
+ return this.cursorBuilder("set", this.#value, value);
1458
+ }
1459
+
1460
+ update(callback) {
1461
+ return this.cursorBuilder("batch", this.#value, callback);
1462
+ }
1463
+
1464
+ assign(obj1) {
1465
+ return this.cursorBuilder("assign", this.#value, deepCopy(obj1));
1466
+ }
1467
+
1468
+ removeKeys(deletedItemKeys) {
1469
+ return this.cursorBuilder("batch", this.#value, arr => _removeKeys(arr, deletedItemKeys));
1470
+ }
1471
+
1472
+ replaceItem(filter, newItem) {
1473
+ return this.cursorBuilder("batch", this.#value, arr => _replaceItem(arr, filter, newItem));
1474
+ }
1475
+
1476
+ value() {
1477
+ return this.#value;
1478
+ }
1479
+
1480
+ static push(array, value, ...values) {
1481
+ return cursorBuilder("push", array, value, ...values);
1482
+ }
1483
+
1484
+ static unshift(array, value, ...values) {
1485
+ return cursorBuilder("unshift", array, value, ...values);
1486
+ }
1487
+
1488
+ static removeKeys(arrayOrObj, deletedItemKeys) {
1489
+ return cursorBuilder("batch", arrayOrObj, arrOrObj => _removeKeys(arrOrObj, deletedItemKeys));
1490
+ }
1491
+
1492
+ static replaceItem(arrayOrObj, filter, newItem) {
1493
+ return cursorBuilder("batch", arrayOrObj, arrOrObj => _replaceItem(arrOrObj, filter, newItem));
1494
+ }
1495
+
1496
+ static splice(array, index, deleteCount, value, ...values) {
1497
+ return cursorBuilder("splice", array, index, deleteCount, value, ...values);
1498
+ }
1499
+
1500
+ static unset(obj, index, ...indexs) {
1501
+ return cursorBuilder("unset", obj, index, ...indexs);
1502
+ }
1503
+
1504
+ static set(obj, value) {
1505
+ return cursorBuilder("set", obj, value);
1506
+ }
1507
+
1508
+ static update(obj, callback) {
1509
+ return cursorBuilder("batch", obj, callback);
1510
+ }
1511
+
1512
+ static assign(obj, obj1) {
1513
+ return cursorBuilder("assign", obj, deepCopy(obj1));
1514
+ }
1515
+ }
1516
+
1517
+ function cursorBuilder(command, array, value, ...values) {
1518
+ const update = require('immhelper').default
1519
+ return function (cursor, ...cursors) {
1520
+ let pathToUpdate = [cursor, ...cursors].filter(x => x != undefined).join('.');
1521
+ let allValues = [value, ...values].filter(x => x != undefined);
1522
+ let spec = {};
1523
+ if (pathToUpdate !== '') spec = { [pathToUpdate]: [command, ...allValues] };
1524
+ else spec = [command, ...allValues];
1525
+ return update(array, spec);
1526
+ };
1527
+ }
1528
+
1529
+ function _removeKeys(objOrArr, keysToRemove) {
1530
+ if (Array.isArray(objOrArr)) {
1531
+ return objOrArr.map(obj => {
1532
+ let newObj = { ...obj };
1533
+ keysToRemove.forEach(key => {
1534
+ delete newObj[key];
1535
+ });
1536
+ return newObj;
1537
+ });
1538
+ } else {
1539
+ let newObj = { ...objOrArr };
1540
+ keysToRemove.forEach(key => {
1541
+ delete newObj[key];
1542
+ });
1543
+ return newObj;
1544
+ }
1545
+ }
1546
+
1547
+ function _replaceItem(data, predicate, newItem) {
1548
+ if (Array.isArray(data)) {
1549
+ return data.map((item, index) => (predicate(item, index) ? newItem : item));
1550
+ } else if (typeof data === 'object' && data !== null) {
1551
+ let newData = { ...data };
1552
+ Object.keys(newData).forEach((key, index) => {
1553
+ if (predicate(newData[key], index)) {
1554
+ newData[key] = newItem;
1555
+ }
1556
+ });
1557
+ return newData;
1558
+ } else return data;
1559
+ }
1560
+
1561
+ function deepCopy(o) {
1562
+ switch (typeof o) {
1563
+ case 'object':
1564
+ if (o === null) return null;
1565
+ if (Array.isArray(o)) return o.map(item => deepCopy(item));
1566
+ let newO = Object.create(Object.getPrototypeOf(o));
1567
+ for (let key in o) {
1568
+ if (Object.prototype.hasOwnProperty.call(o, key)) {
1569
+ newO[key] = deepCopy(o[key]);
1570
+ }
1571
+ }
1572
+ return newO;
1573
+ default:
1574
+ return o;
1575
+ }
1576
+ }
1577
+
1578
+
1258
1579
  function help() {
1259
1580
  console.log(
1260
1581
  "\n\n PERINTAH YANG BISA DIGUNAKAN",
package/error.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import Constants from 'expo-constants';
2
+ import * as FileSystem from 'expo-file-system';
2
3
  import { Platform } from 'react-native';
3
4
  import { LibCurl } from './cache/lib/curl/import';
4
5
  import { UserClass } from './cache/user/class/import';
@@ -22,6 +23,7 @@ const myErrorHandler = (e: any, isFatal: any) => {
22
23
  defaultErrorHandler?.(e, isFatal)
23
24
  }
24
25
 
26
+ /** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/error.md#setError) untuk melihat dokumentasi*/
25
27
  export function setError(error?: any) {
26
28
  const config = esp?.config?.();
27
29
  const routes = UserRoutes?.state()?.get?.();
@@ -36,12 +38,14 @@ export function setError(error?: any) {
36
38
  };
37
39
  try {
38
40
  FastStorage.setItem(`${config?.domain}error`, JSON.stringify(_e));
41
+ cleanCache()
39
42
  } catch (e) {
40
43
  console.error(e);
41
44
  }
42
45
  }
43
46
 
44
47
 
48
+ /** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/error.md#reportApiError) untuk melihat dokumentasi*/
45
49
  export function reportApiError(fetch: any, error: any) {
46
50
  let routes = UserRoutes?.state?.()?.get?.()
47
51
  let lastIndex = routes?.routes?.length - 1 ?? 0
@@ -79,6 +83,7 @@ export function reportApiError(fetch: any, error: any) {
79
83
  }
80
84
  }
81
85
 
86
+ /** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/error.md#sendTm) untuk melihat dokumentasi*/
82
87
  export function sendTm(message: string, chat_id?: string, bot?: string, res?: (result: any) => void): void {
83
88
  let _chatids: string[] = []
84
89
  if (chat_id) {
@@ -98,10 +103,12 @@ export function sendTm(message: string, chat_id?: string, bot?: string, res?: (r
98
103
  })
99
104
  }
100
105
 
106
+ /** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/error.md#getError) untuk melihat dokumentasi*/
101
107
  export function getError() {
102
108
  let config = esp?.config?.()
103
109
  FastStorage.getItem(config?.domain + 'error').then((e: any) => {
104
110
  if (e) {
111
+ cleanCache()
105
112
  let _e = JSON.parse(e)
106
113
  let msg = [
107
114
  'slug: ' + "#" + expoConfig?.slug,
@@ -141,9 +148,18 @@ export function getError() {
141
148
  new LibCurl()?.custom?.('https://api.telegram.org/bot923808407:AAEFBlllQNKCEn8E66fwEzCj5vs9qGwVGT4/sendMessage', post)
142
149
  });
143
150
  }
144
- // });
151
+
145
152
  FastStorage.removeItem(config.domain + 'error')
146
153
  }
147
154
  })
148
155
  }
156
+
157
+ function cleanCache() {
158
+ try {
159
+ // try remove cache after errors
160
+ if (FileSystem.cacheDirectory) {
161
+ FileSystem.deleteAsync(FileSystem.cacheDirectory, { idempotent: true });
162
+ }
163
+ } catch (error) { }
164
+ }
149
165
  ErrorUtils.setGlobalHandler(myErrorHandler)
package/esp.ts CHANGED
@@ -54,7 +54,7 @@ try {
54
54
  }
55
55
  if (conf?.config?.isDebug == 0)
56
56
  LogBox.ignoreAllLogs();
57
-
57
+ /** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/esp.md) untuk melihat dokumentasi*/
58
58
  const esp = {
59
59
  mergeDeep(target: any, ...sources: any[]) {
60
60
  target = Object(target);
package/global.ts CHANGED
@@ -1,7 +1,12 @@
1
+ import AsyncStorage from '@react-native-async-storage/async-storage';
1
2
  import esp from 'esoftplay/esp';
3
+ import MMKV from 'esoftplay/mmkv';
4
+ import Storage from 'esoftplay/storage';
2
5
  import * as R from 'react';
6
+ import isEqual from 'react-fast-compare';
3
7
  import { createDebounce } from './timeout';
4
8
 
9
+
5
10
  export interface useGlobalReturn<T> {
6
11
  useState: () => [T, (newState: T | ((newState: T) => T)) => void, () => T],
7
12
  get: (param?: string, ...params: string[]) => T,
@@ -38,22 +43,28 @@ export interface useGlobalConnect<T> {
38
43
  }
39
44
  export let userDataReset: Function[] = []
40
45
  let timeoutFinish: NodeJS.Timeout
46
+
47
+ /** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/global.md) untuk melihat dokumentasi*/
41
48
  export default function useGlobalState<T>(initValue: T, o?: useGlobalOption): useGlobalReturn<T> {
42
- let STORAGE: any = undefined
43
- const isEqual = require('react-fast-compare');
44
- const subsSetter = new Set<Function>()
49
+ const STORAGE = o?.inFastStorage ? MMKV : (o?.inFile ? Storage : AsyncStorage);
45
50
  let value: T = initValue;
46
- let listener = new Set<Function>()
47
- let loaded = -1
48
- let taskSync: any = undefined
49
-
50
- if (o?.persistKey) {
51
- STORAGE = o?.inFastStorage ? require('esoftplay/mmkv').default : (o?.inFile ? (require('esoftplay/storage').default) : (require('@react-native-async-storage/async-storage').default))
52
- loaded = 0
53
- if (o?.loadOnInit)
54
- loadFromDisk()
51
+ const subsSetter = new Set<(newValue: T) => void>(); // Typed Set
52
+ const listener = new Set<(value: T) => void>(); // Typed Set
53
+ let loaded = -1;
54
+ let taskSync: any = undefined;
55
+
56
+ // Optimization: Check persistKey only once
57
+ const hasPersistKey = !!o?.persistKey;
58
+ const persistKey = o?.persistKey; // Store it for easier access
59
+
60
+ if (hasPersistKey) {
61
+ loaded = 0;
62
+ if (o?.loadOnInit) {
63
+ loadFromDisk();
64
+ }
55
65
  }
56
66
 
67
+
57
68
  function _sync() {
58
69
  const debounce = createDebounce()
59
70
  if (o?.useAutoSync && taskSync && Array.isArray(value)) {
@@ -101,33 +112,38 @@ export default function useGlobalState<T>(initValue: T, o?: useGlobalOption): us
101
112
  })
102
113
  }
103
114
 
115
+
104
116
  function loadFromDisk() {
105
- if (loaded == 0) {
106
- loaded = 1
107
- let persistKey = o?.persistKey
108
- STORAGE.getItem(String(persistKey)).then((p: any) => {
109
- if (p) {
110
- if (persistKey != '__globalReady')
111
- if (p != undefined && typeof p == 'string' && (p.startsWith("{") || p.startsWith("[")))
112
- try { set(JSON.parse(p)) } catch (error) { }
113
- else {
114
- if (p == "true" || p == "false") {
115
- try { /* @ts-ignore */ set(eval(p)) } catch (error) { }
116
- } else if (isNaN(p)) {
117
- try { /* @ts-ignore */ set(p) } catch (error) { }
117
+ if (loaded === 0) {
118
+ loaded = 1;
119
+
120
+ if (hasPersistKey) { // Check hasPersistKey
121
+ STORAGE.getItem(String(persistKey)).then((p: any) => {
122
+ if (p) {
123
+ try {
124
+ if (persistKey !== '__globalReady' && typeof p == 'string' && ((String(p).startsWith('{') && String(p).endsWith('}')) || (String(p).startsWith('[') && String(p).endsWith(']')))) {
125
+ set(JSON.parse(p));
126
+ } else if (p === "true" || p === "false") {
127
+ set(JSON.parse(p)); // Directly parse boolean strings
128
+ } else if (!isNaN(p as any)) {
129
+ set(Number(p)); // Directly convert to number
118
130
  } else {
119
- try { /* @ts-ignore */ set(eval(p)) } catch (error) { }
131
+ set(p); // No need for eval if not an object or boolean or number
120
132
  }
133
+ } catch (error) {
134
+ console.error("Error loading from disk:", persistKey, error, JSON.stringify(p)); // More informative error message
121
135
  }
122
- }
123
- if (o?.onFinish) {
124
- clearTimeout(timeoutFinish)
125
- timeoutFinish = setTimeout(() => {
126
- o.onFinish?.()
127
- clearTimeout(timeoutFinish)
128
- }, 50);
129
- }
130
- })
136
+ }
137
+
138
+ if (o?.onFinish) {
139
+ clearTimeout(timeoutFinish);
140
+ timeoutFinish = setTimeout(() => {
141
+ o.onFinish?.();
142
+ clearTimeout(timeoutFinish);
143
+ }, 50);
144
+ }
145
+ });
146
+ }
131
147
  }
132
148
  }
133
149
 
@@ -148,37 +164,36 @@ export default function useGlobalState<T>(initValue: T, o?: useGlobalOption): us
148
164
  }
149
165
 
150
166
  function set(ns: T | ((old: T) => T)) {
151
- let newValue: any
167
+ let newValue: T; // Type newValue correctly
152
168
  if (ns instanceof Function) {
153
- newValue = ns(value)
169
+ newValue = ns(value);
154
170
  } else {
155
- newValue = ns
171
+ newValue = ns;
156
172
  }
157
- const isChange = !isEqual(value, newValue)
158
- if (isChange) {
159
- value = newValue
160
- subsSetter.forEach((c) => c?.(newValue))
161
- if (o?.persistKey && newValue != undefined) {
162
- let data: any
163
- switch (typeof newValue) {
164
- case 'object':
165
- if (newValue != null || newValue != undefined)
166
- data = o.jsonBeautify ? JSON.stringify(newValue, undefined, 2) : JSON.stringify(newValue)
167
- break;
168
- default:
169
- data = String(newValue)
170
- }
171
- STORAGE.setItem(o.persistKey, data)
173
+
174
+ if (!isEqual(value, newValue)) { // Use direct import of isEqual
175
+ value = newValue;
176
+ subsSetter.forEach((c) => c(newValue)); // Directly call the callback
177
+
178
+ if (hasPersistKey && newValue !== undefined) { // Check hasPersistKey
179
+ const data = typeof newValue === 'object' && newValue !== null
180
+ ? (o.jsonBeautify ? JSON.stringify(newValue, null, 2) : JSON.stringify(newValue))
181
+ : String(newValue); // Simplified data assignment
182
+
183
+ STORAGE.setItem(persistKey, data); // Use the stored persistKey
172
184
  }
173
- if (o?.listener)
174
- o.listener(newValue)
175
- if (o?.useAutoSync && taskSync)
176
- taskSync?.[0]?.(newValue.filter((item: any) => item.synced != 1))
177
- if (listener.size > 0) {
178
- listener.forEach((fun) => fun?.(newValue))
185
+
186
+ if (o?.listener) {
187
+ o.listener(newValue);
179
188
  }
189
+
190
+ if (o?.useAutoSync && taskSync && Array.isArray(newValue)) {
191
+ taskSync[0](newValue.filter((item: any) => item.synced != 1));
192
+ }
193
+
194
+ listener.forEach((fun) => fun(newValue)); // Directly call the listener functions
180
195
  }
181
- };
196
+ }
182
197
 
183
198
  function del() {
184
199
  if (o?.persistKey) {
package/mmkv.ts CHANGED
@@ -2,19 +2,25 @@ import { MMKV } from 'react-native-mmkv';
2
2
 
3
3
  const storage = new MMKV()
4
4
 
5
+ /** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/mmkv.md) untuk melihat dokumentasi*/
5
6
  const FastStorage = {
7
+ /** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/mmkv.md#getItemSync) untuk melihat dokumentasi*/
6
8
  getItemSync(key: string): string {
7
9
  return storage.getString(key)
8
10
  },
11
+ /** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/mmkv.md#getItem) untuk melihat dokumentasi*/
9
12
  getItem(key: string): Promise<string | undefined | null> {
10
13
  return new Promise((r) => r(storage.getString(key)))
11
14
  },
15
+ /** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/mmkv.md#setItem) untuk melihat dokumentasi*/
12
16
  setItem(key: string, value: string) {
13
17
  storage.set(key, value)
14
18
  },
19
+ /** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/mmkv.md#removeItem) untuk melihat dokumentasi*/
15
20
  removeItem(key: string) {
16
21
  storage.delete(key)
17
22
  },
23
+ /** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/mmkv.md#clear) untuk melihat dokumentasi*/
18
24
  clear(): void {
19
25
  storage.clearAll()
20
26
  },
@@ -3,7 +3,9 @@
3
3
  import { InteractionManager } from 'react-native'
4
4
 
5
5
  let updater: any
6
+ /** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/modules/lib/autoreload.md) untuk melihat dokumentasi*/
6
7
  export default {
8
+ /** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/modules/lib/autoreload.md#setcallback---void-duration-number-void) untuk melihat dokumentasi*/
7
9
  set(callback: () => void, duration?: number): void {
8
10
  if (updater != undefined) {
9
11
  clearInterval(updater)
@@ -15,6 +17,7 @@ export default {
15
17
  });
16
18
  }, duration || 6000)
17
19
  },
20
+ /** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/modules/lib/autoreload.md#clear-void) untuk melihat dokumentasi*/
18
21
  clear(): void {
19
22
  if (updater != undefined) {
20
23
  clearInterval(updater)