@talex-touch/utils 1.0.14 → 1.0.16

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 (41) hide show
  1. package/base/index.ts +181 -181
  2. package/channel/index.ts +108 -99
  3. package/common/index.ts +2 -39
  4. package/common/storage/constants.ts +3 -0
  5. package/common/storage/entity/app-settings.ts +47 -0
  6. package/common/storage/entity/index.ts +1 -0
  7. package/common/storage/index.ts +3 -0
  8. package/common/utils.ts +160 -0
  9. package/core-box/README.md +218 -0
  10. package/core-box/index.ts +7 -0
  11. package/core-box/search.ts +536 -0
  12. package/core-box/types.ts +384 -0
  13. package/electron/download-manager.ts +118 -0
  14. package/{common → electron}/env-tool.ts +56 -56
  15. package/electron/touch-core.ts +167 -0
  16. package/electron/window.ts +71 -0
  17. package/eventbus/index.ts +86 -87
  18. package/index.ts +5 -0
  19. package/package.json +55 -30
  20. package/permission/index.ts +48 -48
  21. package/plugin/channel.ts +203 -193
  22. package/plugin/index.ts +216 -121
  23. package/plugin/log/logger-manager.ts +60 -0
  24. package/plugin/log/logger.ts +75 -0
  25. package/plugin/log/types.ts +27 -0
  26. package/plugin/preload.ts +39 -39
  27. package/plugin/sdk/common.ts +27 -27
  28. package/plugin/sdk/hooks/life-cycle.ts +95 -95
  29. package/plugin/sdk/index.ts +18 -13
  30. package/plugin/sdk/service/index.ts +29 -29
  31. package/plugin/sdk/types.ts +578 -0
  32. package/plugin/sdk/window/index.ts +40 -40
  33. package/renderer/index.ts +2 -0
  34. package/renderer/ref.ts +54 -54
  35. package/renderer/slots.ts +124 -0
  36. package/renderer/storage/app-settings.ts +34 -0
  37. package/renderer/storage/base-storage.ts +335 -0
  38. package/renderer/storage/index.ts +1 -0
  39. package/search/types.ts +726 -0
  40. package/service/index.ts +67 -67
  41. package/service/protocol/index.ts +77 -77
@@ -1,96 +1,96 @@
1
- import { genChannel } from './../../channel';
2
-
3
- export enum LifecycleHooks {
4
- ENABLE = 'en',
5
- DISABLE = 'di',
6
- ACTIVE = 'ac',
7
- INACTIVE = 'in',
8
- // FORE_PAUSED = 'fp',
9
- CRASH = 'cr'
10
- }
11
-
12
- // @ts-ignore
13
- export function injectHook(type: LifecycleHooks, hook: Function, processFunc = ({ data, reply }) => {
14
- // @ts-ignore
15
- const hooks: Array<Function> = window.$touchSDK.__hooks[type]
16
- if (hooks) {
17
- hooks.forEach(hook => hook(data))
18
- }
19
- reply(true)
20
- }) {
21
- // @ts-ignore
22
- const __hooks = window.$touchSDK.__hooks
23
- // @ts-ignore
24
- const hooks: Array<Function> = __hooks[type] || (__hooks[type] = [])
25
-
26
- if (hooks.length === 0) {
27
-
28
- genChannel().regChannel("@lifecycle:" + type, (obj: any) => {
29
-
30
- processFunc(obj)
31
-
32
- // @ts-ignore
33
- delete window.$touchSDK.__hooks[type]
34
- })
35
-
36
- }
37
-
38
- const wrappedHook = (data: any) => {
39
-
40
- try {
41
-
42
- hook(data)
43
-
44
- } catch (e) {
45
- console.error(`[TouchSDK] ${type} hook error: `, e)
46
- }
47
-
48
- }
49
-
50
- hooks.push(wrappedHook)
51
-
52
- return wrappedHook
53
- }
54
-
55
- export const createHook = <T extends Function = (data: any) => any>(type: LifecycleHooks) => (hook: T) => injectHook(type, hook)
56
-
57
- /**
58
- * The plugin is enabled
59
- * When the plugin is enabled, the plugin can be used
60
- * @returns void
61
- */
62
- export const onPluginEnable = createHook(LifecycleHooks.ENABLE)
63
-
64
- /**
65
- * The plugin is disabled
66
- * When the plugin is disabled, the plugin can not be used
67
- * @returns void
68
- */
69
- export const onPluginDisable = createHook(LifecycleHooks.DISABLE)
70
-
71
- /**
72
- * The plugin is activated
73
- * @returns boolean If return false, the plugin will not be activated (User can force to activate the plugin)
74
- */
75
- export const onPluginActive = createHook(LifecycleHooks.ACTIVE)
76
-
77
- /**
78
- * The plugin is inactivated
79
- * @returns boolean If return false, the plugin will not be inactivated (User can force to inactivate the plugin)
80
- */
81
- export const onPluginInactive = createHook(LifecycleHooks.INACTIVE)
82
-
83
- /**
84
- * When plugin is in foreground (e.g. plugin is using media, camera, microphone, etc.) But paused by user
85
- * For a detail example: User force to stop music playing
86
- * @returns void
87
- */
88
- // export const onForePaused = createHook(LifecycleHooks.FORE_PAUSED)
89
-
90
- /**
91
- * When plugin is crashed
92
- * data.message Crash message
93
- * data.extraData Crash data
94
- * @returns void
95
- */
1
+ import { genChannel } from './../../channel';
2
+
3
+ export enum LifecycleHooks {
4
+ ENABLE = 'en',
5
+ DISABLE = 'di',
6
+ ACTIVE = 'ac',
7
+ INACTIVE = 'in',
8
+ // FORE_PAUSED = 'fp',
9
+ CRASH = 'cr'
10
+ }
11
+
12
+ // @ts-ignore
13
+ export function injectHook(type: LifecycleHooks, hook: Function, processFunc = ({ data, reply }) => {
14
+ // @ts-ignore
15
+ const hooks: Array<Function> = window.$touchSDK.__hooks[type]
16
+ if (hooks) {
17
+ hooks.forEach(hook => hook(data))
18
+ }
19
+ reply(true)
20
+ }) {
21
+ // @ts-ignore
22
+ const __hooks = window.$touchSDK.__hooks
23
+ // @ts-ignore
24
+ const hooks: Array<Function> = __hooks[type] || (__hooks[type] = [])
25
+
26
+ if (hooks.length === 0) {
27
+
28
+ genChannel().regChannel("@lifecycle:" + type, (obj: any) => {
29
+
30
+ processFunc(obj)
31
+
32
+ // @ts-ignore
33
+ delete window.$touchSDK.__hooks[type]
34
+ })
35
+
36
+ }
37
+
38
+ const wrappedHook = (data: any) => {
39
+
40
+ try {
41
+
42
+ hook(data)
43
+
44
+ } catch (e) {
45
+ console.error(`[TouchSDK] ${type} hook error: `, e)
46
+ }
47
+
48
+ }
49
+
50
+ hooks.push(wrappedHook)
51
+
52
+ return wrappedHook
53
+ }
54
+
55
+ export const createHook = <T extends Function = (data: any) => any>(type: LifecycleHooks) => (hook: T) => injectHook(type, hook)
56
+
57
+ /**
58
+ * The plugin is enabled
59
+ * When the plugin is enabled, the plugin can be used
60
+ * @returns void
61
+ */
62
+ export const onPluginEnable = createHook(LifecycleHooks.ENABLE)
63
+
64
+ /**
65
+ * The plugin is disabled
66
+ * When the plugin is disabled, the plugin can not be used
67
+ * @returns void
68
+ */
69
+ export const onPluginDisable = createHook(LifecycleHooks.DISABLE)
70
+
71
+ /**
72
+ * The plugin is activated
73
+ * @returns boolean If return false, the plugin will not be activated (User can force to activate the plugin)
74
+ */
75
+ export const onPluginActive = createHook(LifecycleHooks.ACTIVE)
76
+
77
+ /**
78
+ * The plugin is inactivated
79
+ * @returns boolean If return false, the plugin will not be inactivated (User can force to inactivate the plugin)
80
+ */
81
+ export const onPluginInactive = createHook(LifecycleHooks.INACTIVE)
82
+
83
+ /**
84
+ * When plugin is in foreground (e.g. plugin is using media, camera, microphone, etc.) But paused by user
85
+ * For a detail example: User force to stop music playing
86
+ * @returns void
87
+ */
88
+ // export const onForePaused = createHook(LifecycleHooks.FORE_PAUSED)
89
+
90
+ /**
91
+ * When plugin is crashed
92
+ * data.message Crash message
93
+ * data.extraData Crash data
94
+ * @returns void
95
+ */
96
96
  export const onCrash = createHook(LifecycleHooks.CRASH)
@@ -1,13 +1,18 @@
1
- import * as HOOKS from './hooks/index'
2
-
3
- export interface ITouchSDK {
4
- hooks: typeof HOOKS
5
- __hooks: {}
6
- }
7
-
8
- // window type
9
- declare global {
10
- export interface Window {
11
- $touchSDK: ITouchSDK
12
- }
13
- }
1
+ import * as HOOKS from './hooks/index'
2
+
3
+ export interface ITouchSDK {
4
+ hooks: typeof HOOKS
5
+ __hooks: {}
6
+ }
7
+
8
+ // window type
9
+ declare global {
10
+ export interface Window {
11
+ $touchSDK: ITouchSDK
12
+ }
13
+ }
14
+
15
+ export * from './types'
16
+ export * from './window/index'
17
+ export * from './hooks/index'
18
+ export * from './service/index'
@@ -1,30 +1,30 @@
1
- import { genChannel } from '../../channel';
2
- import { IService } from "../../../service";
3
-
4
- export function regService(service: IService, handler: Function): boolean {
5
- const res = !!genChannel().sendSync('service:reg', { service: service.name })
6
-
7
- if (res)
8
- onHandleService(service, handler)
9
-
10
- return res
11
- }
12
-
13
- export function unRegService(service: IService): boolean {
14
- return !!genChannel().sendSync('service:unreg', { service: service.name })
15
- }
16
-
17
- export function onHandleService(service: IService, handler: Function) {
18
- // @ts-ignore
19
- genChannel().regChannel('service:handle', ({ data: _data }) => {
20
- const { data } = _data
21
-
22
- // console.log('service:handle', data, service)
23
-
24
- if (data.service === service.name) {
25
- return handler(data)
26
- }
27
-
28
- return false
29
- })
1
+ import { genChannel } from '../../channel';
2
+ import { IService } from "../../../service";
3
+
4
+ export function regService(service: IService, handler: Function): boolean {
5
+ const res = !!genChannel().sendSync('service:reg', { service: service.name })
6
+
7
+ if (res)
8
+ onHandleService(service, handler)
9
+
10
+ return res
11
+ }
12
+
13
+ export function unRegService(service: IService): boolean {
14
+ return !!genChannel().sendSync('service:unreg', { service: service.name })
15
+ }
16
+
17
+ export function onHandleService(service: IService, handler: Function) {
18
+ // @ts-ignore
19
+ genChannel().regChannel('service:handle', ({ data: _data }) => {
20
+ const { data } = _data
21
+
22
+ // console.log('service:handle', data, service)
23
+
24
+ if (data.service === service.name) {
25
+ return handler(data)
26
+ }
27
+
28
+ return false
29
+ })
30
30
  }