@talex-touch/utils 1.0.14 → 1.0.15
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/base/index.ts +181 -181
- package/channel/index.ts +108 -99
- package/common/index.ts +2 -39
- package/common/storage/constants.ts +3 -0
- package/common/storage/entity/app-settings.ts +47 -0
- package/common/storage/entity/index.ts +1 -0
- package/common/storage/index.ts +3 -0
- package/common/utils.ts +160 -0
- package/core-box/README.md +218 -0
- package/core-box/index.ts +7 -0
- package/core-box/search.ts +536 -0
- package/core-box/types.ts +384 -0
- package/electron/download-manager.ts +118 -0
- package/{common → electron}/env-tool.ts +56 -56
- package/electron/touch-core.ts +167 -0
- package/electron/window.ts +71 -0
- package/eventbus/index.ts +86 -87
- package/index.ts +5 -0
- package/package.json +55 -30
- package/permission/index.ts +48 -48
- package/plugin/channel.ts +203 -193
- package/plugin/index.ts +216 -121
- package/plugin/log/logger-manager.ts +60 -0
- package/plugin/log/logger.ts +75 -0
- package/plugin/log/types.ts +27 -0
- package/plugin/preload.ts +39 -39
- package/plugin/sdk/common.ts +27 -27
- package/plugin/sdk/hooks/life-cycle.ts +95 -95
- package/plugin/sdk/index.ts +18 -13
- package/plugin/sdk/service/index.ts +29 -29
- package/plugin/sdk/types.ts +578 -0
- package/plugin/sdk/window/index.ts +40 -40
- package/renderer/index.ts +2 -0
- package/renderer/ref.ts +54 -54
- package/renderer/slots.ts +124 -0
- package/renderer/storage/app-settings.ts +34 -0
- package/renderer/storage/base-storage.ts +335 -0
- package/renderer/storage/index.ts +1 -0
- package/search/types.ts +726 -0
- package/service/index.ts +67 -67
- 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)
|
package/plugin/sdk/index.ts
CHANGED
|
@@ -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
|
}
|