@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.
- 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
package/service/index.ts
CHANGED
|
@@ -1,68 +1,68 @@
|
|
|
1
|
-
export interface IService {
|
|
2
|
-
/**
|
|
3
|
-
* service id
|
|
4
|
-
*/
|
|
5
|
-
id: Symbol;
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* service name
|
|
9
|
-
*/
|
|
10
|
-
name: string;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* service description
|
|
14
|
-
*/
|
|
15
|
-
description: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface IServiceEvent {
|
|
19
|
-
|
|
20
|
-
service: IService;
|
|
21
|
-
|
|
22
|
-
setCancelled(cancelled: boolean): void;
|
|
23
|
-
|
|
24
|
-
isCancelled(): boolean;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface IServiceHandler {
|
|
28
|
-
/**
|
|
29
|
-
* The plugin scope of the service handler
|
|
30
|
-
* @description
|
|
31
|
-
* When service registered, the service center will use the plugin scope to find the service handler.
|
|
32
|
-
* If plugin is disabled, the app will automatically enable plugin and hand on the service to the plugin.
|
|
33
|
-
* When plugin enabled, you must immediately register service handler to the service center, app will waiting for the service handler, until the service handler handled.
|
|
34
|
-
*/
|
|
35
|
-
pluginScope: string
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Handle the service data
|
|
39
|
-
* @param data service data
|
|
40
|
-
*/
|
|
41
|
-
handle(event: IServiceEvent, data: object): any;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export interface IServiceCenter {
|
|
45
|
-
/**
|
|
46
|
-
* The service center will register the service
|
|
47
|
-
* @param service will be registered service
|
|
48
|
-
* @param handler service handler
|
|
49
|
-
* @returns register result (true: success, false: fail)
|
|
50
|
-
*/
|
|
51
|
-
regService(service: IService, handler: IServiceHandler): boolean;
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* The service center will unregister the service
|
|
55
|
-
* @param service will be unregistered service
|
|
56
|
-
* @returns unregister result (true: success, false: fail)
|
|
57
|
-
*/
|
|
58
|
-
unRegService(service: IService): boolean;
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Get the service by service id
|
|
62
|
-
* @param id service id
|
|
63
|
-
* @returns service
|
|
64
|
-
*/
|
|
65
|
-
// getService(id: symbol): IService;
|
|
66
|
-
|
|
67
|
-
useService(service: IService, data: object): Promise<boolean> | boolean;
|
|
1
|
+
export interface IService {
|
|
2
|
+
/**
|
|
3
|
+
* service id
|
|
4
|
+
*/
|
|
5
|
+
id: Symbol;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* service name
|
|
9
|
+
*/
|
|
10
|
+
name: string;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* service description
|
|
14
|
+
*/
|
|
15
|
+
description: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface IServiceEvent {
|
|
19
|
+
|
|
20
|
+
service: IService;
|
|
21
|
+
|
|
22
|
+
setCancelled(cancelled: boolean): void;
|
|
23
|
+
|
|
24
|
+
isCancelled(): boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface IServiceHandler {
|
|
28
|
+
/**
|
|
29
|
+
* The plugin scope of the service handler
|
|
30
|
+
* @description
|
|
31
|
+
* When service registered, the service center will use the plugin scope to find the service handler.
|
|
32
|
+
* If plugin is disabled, the app will automatically enable plugin and hand on the service to the plugin.
|
|
33
|
+
* When plugin enabled, you must immediately register service handler to the service center, app will waiting for the service handler, until the service handler handled.
|
|
34
|
+
*/
|
|
35
|
+
pluginScope: string
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Handle the service data
|
|
39
|
+
* @param data service data
|
|
40
|
+
*/
|
|
41
|
+
handle(event: IServiceEvent, data: object): any;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface IServiceCenter {
|
|
45
|
+
/**
|
|
46
|
+
* The service center will register the service
|
|
47
|
+
* @param service will be registered service
|
|
48
|
+
* @param handler service handler
|
|
49
|
+
* @returns register result (true: success, false: fail)
|
|
50
|
+
*/
|
|
51
|
+
regService(service: IService, handler: IServiceHandler): boolean;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The service center will unregister the service
|
|
55
|
+
* @param service will be unregistered service
|
|
56
|
+
* @returns unregister result (true: success, false: fail)
|
|
57
|
+
*/
|
|
58
|
+
unRegService(service: IService): boolean;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Get the service by service id
|
|
62
|
+
* @param id service id
|
|
63
|
+
* @returns service
|
|
64
|
+
*/
|
|
65
|
+
// getService(id: symbol): IService;
|
|
66
|
+
|
|
67
|
+
useService(service: IService, data: object): Promise<boolean> | boolean;
|
|
68
68
|
}
|
|
@@ -1,78 +1,78 @@
|
|
|
1
|
-
import { IService } from './../index';
|
|
2
|
-
|
|
3
|
-
export abstract class ProtocolService<T extends string> implements IService {
|
|
4
|
-
id: symbol;
|
|
5
|
-
name: string;
|
|
6
|
-
description: string;
|
|
7
|
-
|
|
8
|
-
protocol: string[]
|
|
9
|
-
|
|
10
|
-
type: T
|
|
11
|
-
|
|
12
|
-
constructor(id: symbol, protocol: string[]) {
|
|
13
|
-
this.id = id;
|
|
14
|
-
this.name = id.description!;
|
|
15
|
-
this.description = `${this.name} Protocol Service`;
|
|
16
|
-
this.protocol = protocol
|
|
17
|
-
|
|
18
|
-
this.type = id.description as T
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export const IMAGE_SUFFIX = [
|
|
23
|
-
'jpg', 'png', 'gif', 'bmp', 'webp', 'svg', 'ico', 'tiff', 'tif', 'jpeg', 'avif'
|
|
24
|
-
]
|
|
25
|
-
|
|
26
|
-
export class ImageProtocolService extends ProtocolService<'image'> {
|
|
27
|
-
constructor() {
|
|
28
|
-
super(Symbol('Image'), IMAGE_SUFFIX)
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export const AUDIO_SUFFIX = [
|
|
33
|
-
'mp3', 'wav', 'ogg', 'aac', 'flac', 'wma', 'ape', 'm4a', 'm4r', 'm4b', 'm4p', 'm4v', 'mp4', '3gp', 'avi', 'mov', 'wmv', 'flv', 'mkv', 'rmvb', 'rm', 'asf', 'dat', 'mpg', 'mpeg', 'vob', 'f4v', 'm3u8', 'webm', 'ts', 'mts', 'm2ts', 'mts', 'dv', 'divx', 'xvid', 'mpe', 'mod', 'sdp', 'm2v', 'm2p', 'm2t', 'm2ts', 'm2v', 'm2p', 'm2t', 'm2ts', 'm2v', 'm2p', 'm2t', 'm2ts', 'm2v', 'm2p', 'm2t', 'm2ts', 'm2v', 'm2p', 'm2t', 'm2ts', 'm2v', 'm2p', 'm2t', 'm2ts'
|
|
34
|
-
]
|
|
35
|
-
|
|
36
|
-
export class AudioProtocolService extends ProtocolService<'audio'> {
|
|
37
|
-
constructor() {
|
|
38
|
-
super(Symbol('Audio'), AUDIO_SUFFIX)
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export const VIDEO_SUFFIX = [
|
|
43
|
-
'mp4', '3gp', 'avi', 'mov', 'wmv', 'flv', 'mkv', 'rmvb', 'rm', 'asf', 'dat', 'mpg', 'mpeg', 'vob', 'f4v', 'm3u8', 'webm', 'ts', 'mts', 'm2ts', 'mts', 'dv', 'divx', 'xvid', 'mpe', 'mod', 'sdp', 'm2v', 'm2p', 'm2t', 'm2ts', 'm2v', 'm2p', 'm2t', 'm2ts', 'm2v', 'm2p', 'm2t', 'm2ts', 'm2v', 'm2p', 'm2t', 'm2ts', 'm2v', 'm2p', 'm2t', 'm2ts'
|
|
44
|
-
]
|
|
45
|
-
|
|
46
|
-
export class VideoProtocolService extends ProtocolService<'video'> {
|
|
47
|
-
constructor() {
|
|
48
|
-
super(Symbol('Video'), VIDEO_SUFFIX)
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export const TEXT_SUFFIX = [
|
|
53
|
-
'txt', 'md', 'markdown', 'json', 'js', 'ts', 'html', 'css', 'scss', 'sass', 'less', 'xml', 'yaml', 'yml', 'ini', 'log', 'bat', 'sh', 'cmd', 'c', 'cpp', 'h', 'hpp', 'java', 'py', 'go', 'php', 'sql', 'swift', 'vb', 'vbs', 'lua', 'rb', 'r', 'cs', 'm', 'mm', 'pl', 'perl', 'asm', 'asmx', 'inc', 'coffee', 'ts', 'tsx', 'jsx', 'vue', 'php', 'php3', 'php4', 'php5', 'php7', 'phps', 'phtml', 'pht', 'phar', 'phpt', 'php-cgi', 'php-cs-fixer', 'phpunit', 'phpunit.xml', 'phpunit.xml.dist', 'phpunit.phar', 'phpunit.phar.dist', 'phpunit-4.8.36.phar', 'phpunit-4.8.36.phar.dist', 'phpunit-5.7.27.phar', 'phpunit-5.7.27.phar.dist', 'phpunit-6.5.14.phar', 'phpunit-6.5.14.phar.dist', 'phpunit-7.5.20.phar', 'phpunit-7.5.20.phar.dist', 'phpunit-8.5.8.phar', 'phpunit-8.5.8.phar.dist', 'phpunit-9.3.10.phar', 'phpunit-9.3.10.phar.dist', 'phpunit-9.4.3.phar', 'phpunit-9.4.3.phar.dist', 'phpunit-9.5.0.phar', 'phpunit-9.5.0.phar.dist', 'phpunit-9.5.1.phar', 'phpunit-9.5.1.phar.dist', 'phpunit-9.5.2.phar', 'phpunit-9.5.2.phar.dist', 'phpunit-9.5.4.phar', 'phpunit-9.5.4.phar.dist', 'php'
|
|
54
|
-
]
|
|
55
|
-
|
|
56
|
-
export class TextProtocolService extends ProtocolService<'text'> {
|
|
57
|
-
constructor() {
|
|
58
|
-
super(Symbol('Text'), TEXT_SUFFIX)
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export const serviceSuffixMap = new Map<ProtocolService<string>, string[]>
|
|
63
|
-
|
|
64
|
-
serviceSuffixMap.set(new ImageProtocolService(), IMAGE_SUFFIX)
|
|
65
|
-
serviceSuffixMap.set(new AudioProtocolService(), AUDIO_SUFFIX)
|
|
66
|
-
serviceSuffixMap.set(new VideoProtocolService(), VIDEO_SUFFIX)
|
|
67
|
-
serviceSuffixMap.set(new TextProtocolService(), TEXT_SUFFIX)
|
|
68
|
-
|
|
69
|
-
export function suffix2Service(suffix: string): ProtocolService<string> | null {
|
|
70
|
-
|
|
71
|
-
for (const [type, suffixes] of serviceSuffixMap.entries()) {
|
|
72
|
-
if (suffixes.includes(suffix)) {
|
|
73
|
-
return type
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return null
|
|
1
|
+
import { IService } from './../index';
|
|
2
|
+
|
|
3
|
+
export abstract class ProtocolService<T extends string> implements IService {
|
|
4
|
+
id: symbol;
|
|
5
|
+
name: string;
|
|
6
|
+
description: string;
|
|
7
|
+
|
|
8
|
+
protocol: string[]
|
|
9
|
+
|
|
10
|
+
type: T
|
|
11
|
+
|
|
12
|
+
constructor(id: symbol, protocol: string[]) {
|
|
13
|
+
this.id = id;
|
|
14
|
+
this.name = id.description!;
|
|
15
|
+
this.description = `${this.name} Protocol Service`;
|
|
16
|
+
this.protocol = protocol
|
|
17
|
+
|
|
18
|
+
this.type = id.description as T
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const IMAGE_SUFFIX = [
|
|
23
|
+
'jpg', 'png', 'gif', 'bmp', 'webp', 'svg', 'ico', 'tiff', 'tif', 'jpeg', 'avif'
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
export class ImageProtocolService extends ProtocolService<'image'> {
|
|
27
|
+
constructor() {
|
|
28
|
+
super(Symbol('Image'), IMAGE_SUFFIX)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const AUDIO_SUFFIX = [
|
|
33
|
+
'mp3', 'wav', 'ogg', 'aac', 'flac', 'wma', 'ape', 'm4a', 'm4r', 'm4b', 'm4p', 'm4v', 'mp4', '3gp', 'avi', 'mov', 'wmv', 'flv', 'mkv', 'rmvb', 'rm', 'asf', 'dat', 'mpg', 'mpeg', 'vob', 'f4v', 'm3u8', 'webm', 'ts', 'mts', 'm2ts', 'mts', 'dv', 'divx', 'xvid', 'mpe', 'mod', 'sdp', 'm2v', 'm2p', 'm2t', 'm2ts', 'm2v', 'm2p', 'm2t', 'm2ts', 'm2v', 'm2p', 'm2t', 'm2ts', 'm2v', 'm2p', 'm2t', 'm2ts', 'm2v', 'm2p', 'm2t', 'm2ts', 'm2v', 'm2p', 'm2t', 'm2ts'
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
export class AudioProtocolService extends ProtocolService<'audio'> {
|
|
37
|
+
constructor() {
|
|
38
|
+
super(Symbol('Audio'), AUDIO_SUFFIX)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const VIDEO_SUFFIX = [
|
|
43
|
+
'mp4', '3gp', 'avi', 'mov', 'wmv', 'flv', 'mkv', 'rmvb', 'rm', 'asf', 'dat', 'mpg', 'mpeg', 'vob', 'f4v', 'm3u8', 'webm', 'ts', 'mts', 'm2ts', 'mts', 'dv', 'divx', 'xvid', 'mpe', 'mod', 'sdp', 'm2v', 'm2p', 'm2t', 'm2ts', 'm2v', 'm2p', 'm2t', 'm2ts', 'm2v', 'm2p', 'm2t', 'm2ts', 'm2v', 'm2p', 'm2t', 'm2ts', 'm2v', 'm2p', 'm2t', 'm2ts'
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
export class VideoProtocolService extends ProtocolService<'video'> {
|
|
47
|
+
constructor() {
|
|
48
|
+
super(Symbol('Video'), VIDEO_SUFFIX)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export const TEXT_SUFFIX = [
|
|
53
|
+
'txt', 'md', 'markdown', 'json', 'js', 'ts', 'html', 'css', 'scss', 'sass', 'less', 'xml', 'yaml', 'yml', 'ini', 'log', 'bat', 'sh', 'cmd', 'c', 'cpp', 'h', 'hpp', 'java', 'py', 'go', 'php', 'sql', 'swift', 'vb', 'vbs', 'lua', 'rb', 'r', 'cs', 'm', 'mm', 'pl', 'perl', 'asm', 'asmx', 'inc', 'coffee', 'ts', 'tsx', 'jsx', 'vue', 'php', 'php3', 'php4', 'php5', 'php7', 'phps', 'phtml', 'pht', 'phar', 'phpt', 'php-cgi', 'php-cs-fixer', 'phpunit', 'phpunit.xml', 'phpunit.xml.dist', 'phpunit.phar', 'phpunit.phar.dist', 'phpunit-4.8.36.phar', 'phpunit-4.8.36.phar.dist', 'phpunit-5.7.27.phar', 'phpunit-5.7.27.phar.dist', 'phpunit-6.5.14.phar', 'phpunit-6.5.14.phar.dist', 'phpunit-7.5.20.phar', 'phpunit-7.5.20.phar.dist', 'phpunit-8.5.8.phar', 'phpunit-8.5.8.phar.dist', 'phpunit-9.3.10.phar', 'phpunit-9.3.10.phar.dist', 'phpunit-9.4.3.phar', 'phpunit-9.4.3.phar.dist', 'phpunit-9.5.0.phar', 'phpunit-9.5.0.phar.dist', 'phpunit-9.5.1.phar', 'phpunit-9.5.1.phar.dist', 'phpunit-9.5.2.phar', 'phpunit-9.5.2.phar.dist', 'phpunit-9.5.4.phar', 'phpunit-9.5.4.phar.dist', 'php'
|
|
54
|
+
]
|
|
55
|
+
|
|
56
|
+
export class TextProtocolService extends ProtocolService<'text'> {
|
|
57
|
+
constructor() {
|
|
58
|
+
super(Symbol('Text'), TEXT_SUFFIX)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export const serviceSuffixMap = new Map<ProtocolService<string>, string[]>
|
|
63
|
+
|
|
64
|
+
serviceSuffixMap.set(new ImageProtocolService(), IMAGE_SUFFIX)
|
|
65
|
+
serviceSuffixMap.set(new AudioProtocolService(), AUDIO_SUFFIX)
|
|
66
|
+
serviceSuffixMap.set(new VideoProtocolService(), VIDEO_SUFFIX)
|
|
67
|
+
serviceSuffixMap.set(new TextProtocolService(), TEXT_SUFFIX)
|
|
68
|
+
|
|
69
|
+
export function suffix2Service(suffix: string): ProtocolService<string> | null {
|
|
70
|
+
|
|
71
|
+
for (const [type, suffixes] of serviceSuffixMap.entries()) {
|
|
72
|
+
if (suffixes.includes(suffix)) {
|
|
73
|
+
return type
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return null
|
|
78
78
|
}
|