@talex-touch/utils 1.0.13 → 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.
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
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
  }