@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
@@ -0,0 +1,167 @@
1
+ import { OpenDevToolsOptions } from "electron";
2
+
3
+ export namespace TalexTouch {
4
+ export interface TouchApp {
5
+ app: Electron.App;
6
+ window: ITouchWindow;
7
+ version: AppVersion;
8
+ moduleManager: IModuleManager;
9
+ config: IConfiguration;
10
+ rootPath: string;
11
+ }
12
+
13
+ export enum AppVersion {
14
+ // ALPHA = "alpha",
15
+ // BETA = "beta",
16
+ DEV = "dev",
17
+ RELEASE = "release",
18
+ }
19
+
20
+ export interface ITouchWindow {
21
+ window: Electron.BrowserWindow;
22
+
23
+ /**
24
+ * Try to close the window. This has the same effect as a user manually clicking
25
+ * the close button of the window. The web page may cancel the close though. See
26
+ * the close event.
27
+ */
28
+ close(): void;
29
+
30
+ /**
31
+ * Minimizes the window. On some platforms the minimized window will be shown in
32
+ * the Dock.
33
+ */
34
+ minimize(): void;
35
+
36
+ /**
37
+ * Opens the devtools.
38
+ *
39
+ * When `contents` is a `<webview>` tag, the `mode` would be `detach` by default,
40
+ * explicitly passing an empty `mode` can force using last used dock state.
41
+ *
42
+ * On Windows, if Windows Control Overlay is enabled, Devtools will be opened with
43
+ * `mode: 'detach'`.
44
+ */
45
+ openDevTools(options?: OpenDevToolsOptions): void;
46
+
47
+ loadURL(
48
+ url: string,
49
+ options?: LoadURLOptions | undefined
50
+ ): Promise<Electron.WebContents>;
51
+ loadFile(
52
+ filePath: string,
53
+ options?: LoadFileOptions | undefined
54
+ ): Promise<Electron.WebContents>;
55
+ }
56
+
57
+ export type LoadFileOptions = Electron.LoadFileOptions & {
58
+ devtools?: boolean | "detach" | "left" | "right" | "bottom" | "undocked";
59
+ };
60
+ export type LoadURLOptions = Electron.LoadURLOptions & {
61
+ devtools?: boolean | "detach" | "left" | "right" | "bottom" | "undocked";
62
+ };
63
+
64
+ export interface IModuleManager {
65
+ /**
66
+ * Module Loader
67
+ * @param {TalexTouch.IModule} module
68
+ * @description This function will load the module with the given name.
69
+ * @returns {boolean} Returns true if the module is loaded successfully, otherwise returns false.
70
+ */
71
+ loadModule(module: IModule): boolean | Promise<boolean>;
72
+
73
+ /**
74
+ * Module Unloader
75
+ * @param {string}
76
+ * @description This function will unload the module with the given name.
77
+ * @description This function will also call the module's destroy function.
78
+ * @returns {boolean} Returns true if the module is unloaded successfully, otherwise returns false.
79
+ */
80
+ unloadModule(moduleName: Symbol): boolean | Promise<boolean>;
81
+
82
+ /**
83
+ * Module Getter
84
+ * @param {string}
85
+ * @description This function will return the module with the given name.
86
+ * @description If the module is not loaded, this function will return undefined.
87
+ */
88
+ getModule(moduleName: Symbol): IModule | undefined;
89
+
90
+ // TODO Next version preview
91
+ // /**
92
+ // * Module register event listener
93
+ // */
94
+ // registerEvent(moduleName: Symbol, eventName: string, callback: Function): void
95
+
96
+ // /**
97
+ // * Module unregister event listener
98
+ // */
99
+ // unregisterEvent(moduleName: Symbol, eventName: string, callback: Function): void
100
+
101
+ // /**
102
+ // * Module emit event
103
+ // */
104
+ // emitEvent(eventName: string, ...args: any[]): void
105
+ }
106
+
107
+ export interface IModule {
108
+ /**
109
+ * Module name
110
+ * @type {string}
111
+ * @description It's a unique name for each module, and it will be used to identify the module.
112
+ * @description It's also the name of the module's folder, which will be automatically created by the manager.
113
+ * @example "example-module"
114
+ */
115
+ name: Symbol;
116
+
117
+ /**
118
+ * Custom module file-path
119
+ * @type {string}
120
+ * @description If you want to load the module from a custom file-path, you can set this property.
121
+ * @description If this property is not set, the manager will load the module from the default file-path. (.../modules/{module-name})
122
+ */
123
+ filePath?: string | boolean;
124
+
125
+ /**
126
+ * Module Initialization
127
+ * @param {TalexTouch.TouchApp} app
128
+ * @param {TalexTouch.IModuleManager} manager
129
+ * @description This function will be called when the module is loaded.
130
+ * @description You can use this function to initialize your module.
131
+ * @description You can also use this function to register your module's event listeners.
132
+ */
133
+ init(
134
+ app: TalexTouch.TouchApp,
135
+ manager: TalexTouch.IModuleManager
136
+ ): void;
137
+
138
+ /**
139
+ * Module Destruction
140
+ * @param {TalexTouch.TouchApp} app
141
+ * @param {TalexTouch.IModuleManager} manager
142
+ * @description This function will be called when the module is unloaded.
143
+ * @description You can use this function to destroy your module.
144
+ * @description You can also use this function to unregister your module's event listeners.
145
+ * @description This function will be called when the app is closed.
146
+ */
147
+ destroy(
148
+ app: TalexTouch.TouchApp,
149
+ manager: TalexTouch.IModuleManager
150
+ ): void;
151
+ }
152
+
153
+ export interface IConfiguration {
154
+ configPath: string;
155
+ data: TouchAppConfig
156
+ triggerSave: Function
157
+ }
158
+
159
+ export interface TouchAppConfig {
160
+ frame: {
161
+ width: number;
162
+ height: number;
163
+ left?: number;
164
+ top?: number;
165
+ }
166
+ }
167
+ }
@@ -0,0 +1,71 @@
1
+ import gsap from 'gsap'
2
+ TalexTouch.
3
+ // 使用类型注释避免直接引用Electron命名空间
4
+ interface ITouchWindow {
5
+ window: {
6
+ getSize(): [number, number];
7
+ getPosition(): [number, number];
8
+ setSize(width: number, height: number): void;
9
+ setPosition(x: number, y: number): void;
10
+ };
11
+ }
12
+
13
+ // 保存当前动画实例的引用,用于取消上次动画
14
+ let currentTween: gsap.core.Tween | null = null
15
+
16
+ /**
17
+ * 使用GSAP动画设置窗口高度的函数
18
+ * @param window TouchWindow对象
19
+ * @returns 返回一个可以更新窗口高度的方法
20
+ */
21
+ export function useWindowHeight(window: ITouchWindow): {
22
+ updateHeight: (newHeight: number, duration?: number) => void
23
+ } {
24
+ /**
25
+ * 更新窗口高度的方法
26
+ * @param newHeight 新的高度值
27
+ * @param duration 动画持续时间,默认为0.5秒
28
+ */
29
+ const updateHeight = (newHeight: number, duration: number = 0.5): void => {
30
+ // 如果存在上次的动画,先取消它
31
+ if (currentTween) {
32
+ currentTween.kill()
33
+ }
34
+
35
+ // 获取当前窗口的BrowserWindow实例
36
+ const browserWindow = window.window
37
+
38
+ // 获取当前窗口的位置和宽度
39
+ const [currentWidth, currentHeight] = browserWindow.getSize()
40
+ const [x, y] = browserWindow.getPosition()
41
+
42
+ // 使用GSAP创建动画
43
+ currentTween = gsap.to(
44
+ {
45
+ height: currentHeight
46
+ },
47
+ {
48
+ height: newHeight,
49
+ duration,
50
+ ease: 'cubic-bezier(0.785, 0.135, 0.15, 0.86)', // 使用指定的贝塞尔曲线
51
+ onUpdate: function () {
52
+ // 在动画更新时调整窗口大小
53
+ const animatedHeight = Math.round(this.targets()[0].height)
54
+ browserWindow.setSize(currentWidth, animatedHeight)
55
+
56
+ // 保持窗口的顶部位置不变,只改变高度
57
+ browserWindow.setPosition(x, y)
58
+ },
59
+ onComplete: () => {
60
+ // 动画完成时,清除引用
61
+ currentTween = null
62
+ }
63
+ }
64
+ )
65
+ }
66
+
67
+ // 返回更新高度的方法
68
+ return {
69
+ updateHeight
70
+ }
71
+ }
package/eventbus/index.ts CHANGED
@@ -1,87 +1,86 @@
1
- export type EventHandler = (event: ITouchEvent) => void;
2
-
3
- export interface EventHandlerWrapper {
4
- /**
5
- * Event handler
6
- */
7
- handler: EventHandler;
8
-
9
- /**
10
- * Event type
11
- * @see EventType
12
- * @default EventType.PERSIST (must be, if implements)
13
- */
14
- type?: EventType;
15
- }
16
-
17
- export enum EventType {
18
- PERSIST,
19
- CONSUME,
20
- }
21
-
22
- export interface ITouchEvent<E = any> {
23
- /**
24
- * Event name
25
- */
26
- name: E;
27
-
28
- /**
29
- * Event data
30
- */
31
- data?: any;
32
- }
33
-
34
- export interface ITouchEventBus<E> {
35
- map: Map<E, Set<EventHandlerWrapper>>;
36
-
37
- /**
38
- * Subscribe touch-app events (any kind of events extends from TouchEvent)
39
- * @param event EventName (extends from TouchEvent)
40
- * @param handler Event handler (extends from EventHandler)
41
- * @returns true if the event was added, otherwise false
42
- */
43
- on(event: E, handler: EventHandler): boolean | void;
44
-
45
- /**
46
- * Subscribe touch-app events (any kind of events extends from TouchEvent)
47
- * @param event EventName (extends from TouchEvent)
48
- * @param handler Event handler (extends from EventHandler)
49
- * @returns true if the event was added, otherwise false
50
- */
51
- once(event: E, handler: EventHandler): boolean | void;
52
-
53
- /**
54
- * UnSubscribe touch-app events (any kind of events extends from TouchEvent)
55
- * @param event EventName (extends from TouchEvent)
56
- * @param handler Event handler (extends from EventHandler)
57
- * @returns true if the event was removed, otherwise false
58
- * @example
59
- * ```ts
60
- * const handler = (event: TouchEvent) => {
61
- * console.log(event)
62
- * }
63
- */
64
- off<T extends ITouchEvent>(event: E, handler: EventHandler): boolean;
65
-
66
- /**
67
- * UnSubscribe touch-app events all matched (any kind of events extends from TouchEvent)
68
- * @param event EventName (extends from TouchEvent)
69
- * @returns true if the event was added, otherwise false
70
- */
71
- offAll(event: E): boolean;
72
-
73
- /**
74
- * UnSubscribe touch-app events all matched (any kind of events extends from TouchEvent)
75
- * @param event EventName (extends from TouchEvent)
76
- * @param handler Event handler (extends from EventHandler)
77
- * @returns true if the event was added, otherwise false
78
- */
79
- off<T extends ITouchEvent>(event: E, handler: EventHandler): boolean;
80
-
81
- /**
82
- * Emit touch-app events (any kind of events extends from TouchEvent)
83
- * @param event EventName (extends from TouchEvent)
84
- * @param data Event data (extends from TouchEvent)
85
- */
86
- emit<T extends ITouchEvent<E>>(event: E, data: T): void;
87
- }
1
+ export type EventHandler = (event: ITouchEvent) => void;
2
+
3
+ export interface EventHandlerWrapper {
4
+ /**
5
+ * Event handler
6
+ */
7
+ handler: EventHandler;
8
+
9
+ /**
10
+ * Event type
11
+ * @see EventType
12
+ * @default EventType.PERSIST (must be, if implements)
13
+ */
14
+ type?: EventType;
15
+ }
16
+
17
+ export enum EventType {
18
+ PERSIST,
19
+ CONSUME,
20
+ }
21
+
22
+ export interface ITouchEvent<E = any> {
23
+ /**
24
+ * Event name
25
+ */
26
+ name: E;
27
+
28
+ /**
29
+ * Event data
30
+ */
31
+ data?: any;
32
+ }
33
+
34
+ export interface ITouchEventBus<E> {
35
+ map: Map<E, Set<EventHandlerWrapper>>;
36
+
37
+ /**
38
+ * Subscribe touch-app events (any kind of events extends from TouchEvent)
39
+ * @param event EventName (extends from TouchEvent)
40
+ * @param handler Event handler (extends from EventHandler)
41
+ * @returns true if the event was added, otherwise false
42
+ */
43
+ on(event: E, handler: EventHandler): boolean | void;
44
+
45
+ /**
46
+ * Subscribe touch-app events (any kind of events extends from TouchEvent)
47
+ * @param event EventName (extends from TouchEvent)
48
+ * @param handler Event handler (extends from EventHandler)
49
+ * @returns true if the event was added, otherwise false
50
+ */
51
+ once(event: E, handler: EventHandler): boolean | void;
52
+
53
+ /**
54
+ * UnSubscribe touch-app events (any kind of events extends from TouchEvent)
55
+ * @param event EventName (extends from TouchEvent)
56
+ * @param handler Event handler (extends from EventHandler)
57
+ * @returns true if the event was removed, otherwise false
58
+ * @example
59
+ * ```ts
60
+ * const handler = (event: TouchEvent) => {
61
+ * console.log(event)
62
+ * }
63
+ */
64
+ off(event: E, handler: EventHandler): boolean;
65
+
66
+ /**
67
+ * UnSubscribe touch-app events all matched (any kind of events extends from TouchEvent)
68
+ * @param event EventName (extends from TouchEvent)
69
+ * @returns true if the event was added, otherwise false
70
+ */
71
+ offAll(event: E): boolean;
72
+
73
+ /**
74
+ * UnSubscribe touch-app events all matched (any kind of events extends from TouchEvent)
75
+ * @param event EventName (extends from TouchEvent)
76
+ * @returns true if the event was added, otherwise false
77
+ */
78
+ offAll(event: E): boolean;
79
+
80
+ /**
81
+ * Emit touch-app events (any kind of events extends from TouchEvent)
82
+ * @param event EventName (extends from TouchEvent)
83
+ * @param data Event data (extends from TouchEvent)
84
+ */
85
+ emit<T extends ITouchEvent<E>>(event: E, data: T): void;
86
+ }
package/index.ts CHANGED
@@ -0,0 +1,5 @@
1
+ export * from './base'
2
+ export * from './common'
3
+ export * from './plugin'
4
+ export * from './core-box'
5
+ export * from './channel'
package/package.json CHANGED
@@ -1,30 +1,55 @@
1
- {
2
- "main": "./index.ts",
3
- "name": "@talex-touch/utils",
4
- "author": "TalexDreamSoul",
5
- "module": "./index.ts",
6
- "license": "MPL-2.0",
7
- "private": false,
8
- "version": "1.0.13",
9
- "scripts": {
10
- "publish": "npm publish --access public"
11
- },
12
- "keywords": [
13
- "vue",
14
- "electron",
15
- "talex-touch"
16
- ],
17
- "repository": {
18
- "url": "https://github.com/talex-touch/talex-touch.git",
19
- "type": "git"
20
- },
21
- "description": "TalexTouch series utils",
22
- "dependencies": {
23
- "path-browserify": "^1.0.1",
24
- "vue": "^3.4.19"
25
- },
26
- "peerDependencies": {
27
- "electron": "^24.4.0",
28
- "vue": "^3.2.47"
29
- }
30
- }
1
+ {
2
+ "main": "index.ts",
3
+ "name": "@talex-touch/utils",
4
+ "author": "TalexDreamSoul",
5
+ "module": "./index.ts",
6
+ "license": "MPL-2.0",
7
+ "private": false,
8
+ "version": "1.0.15",
9
+ "exports": {
10
+ ".": "./index.ts",
11
+ "./channel": "./channel/index.ts",
12
+ "./base": "./base/index.ts",
13
+ "./common": "./common/index.ts",
14
+ "./common/utils": "./common/utils.ts",
15
+ "./plugin": "./plugin/index.ts",
16
+ "./plugin/log/logger-manager": "./plugin/log/logger-manager.ts",
17
+ "./plugin/log/logger": "./plugin/log/logger.ts",
18
+ "./plugin/sdk": "./plugin/sdk.ts",
19
+ "./plugin/sdk/window": "./plugin/sdk/window.ts",
20
+ "./core-box": "./core-box/index.ts",
21
+ "./search/types": "./search/types.ts",
22
+ "./eventbus": "./eventbus/index.ts",
23
+ "./permission": "./permission/index.ts",
24
+ "./renderer": "./renderer/index.ts",
25
+ "./renderer/ref": "./renderer/ref.ts",
26
+ "./renderer/slots": "./renderer/slots.ts",
27
+ "./renderer/storage/app-settings": "./renderer/storage/app-settings.ts",
28
+ "./service": "./service/index.ts",
29
+ "./service/protocol": "./service/protocol/index.ts",
30
+ "./electron/env-tool": "./electron/env-tool.ts",
31
+ "./electron/download-manager": "./electron/download-manager.ts"
32
+ },
33
+ "scripts": {
34
+ "publish": "npm publish --access public"
35
+ },
36
+ "keywords": [
37
+ "vue",
38
+ "electron",
39
+ "talex-touch"
40
+ ],
41
+ "repository": {
42
+ "url": "https://github.com/talex-touch/talex-touch.git",
43
+ "type": "git"
44
+ },
45
+ "description": "TalexTouch series utils",
46
+ "dependencies": {
47
+ "@vueuse/core": "^13.5.0",
48
+ "path-browserify": "^1.0.1",
49
+ "vue": "^3.5.18"
50
+ },
51
+ "peerDependencies": {
52
+ "electron": "^29.4.6",
53
+ "vue": "^3.5.15"
54
+ }
55
+ }
@@ -1,49 +1,49 @@
1
- export interface Permission {
2
- /**
3
- * permission id
4
- */
5
- id: symbol;
6
-
7
- /**
8
- * permission name
9
- */
10
- name: string;
11
-
12
- /**
13
- * permission description
14
- */
15
- description: string;
16
- }
17
-
18
- export interface IPermissionCenter {
19
- /**
20
- * add a permission
21
- * @param pluginScope plugin name
22
- * @param permission permission
23
- * @throws if permission already exists
24
- */
25
- addPermission(pluginScope: string, permission: Permission): void;
26
-
27
- /**
28
- * remove a permission
29
- * @param pluginScope plugin name
30
- * @param permission permission
31
- * @throws if permission not exists
32
- */
33
- delPermission(pluginScope: string, permission: Permission): void;
34
-
35
- /**
36
- * if pluginScope has permission
37
- * @param pluginScope plugin name
38
- * @param permission permission
39
- */
40
- hasPermission(pluginScope: string, permission: Permission): boolean;
41
-
42
- /**
43
- * get permission
44
- * @param pluginScope plugin name
45
- * @param permission permission id
46
- * @returns permission
47
- */
48
- getPermission(pluginScope: string, permission: symbol): Permission;
1
+ export interface Permission {
2
+ /**
3
+ * permission id
4
+ */
5
+ id: symbol;
6
+
7
+ /**
8
+ * permission name
9
+ */
10
+ name: string;
11
+
12
+ /**
13
+ * permission description
14
+ */
15
+ description: string;
16
+ }
17
+
18
+ export interface IPermissionCenter {
19
+ /**
20
+ * add a permission
21
+ * @param pluginScope plugin name
22
+ * @param permission permission
23
+ * @throws if permission already exists
24
+ */
25
+ addPermission(pluginScope: string, permission: Permission): void;
26
+
27
+ /**
28
+ * remove a permission
29
+ * @param pluginScope plugin name
30
+ * @param permission permission
31
+ * @throws if permission not exists
32
+ */
33
+ delPermission(pluginScope: string, permission: Permission): void;
34
+
35
+ /**
36
+ * if pluginScope has permission
37
+ * @param pluginScope plugin name
38
+ * @param permission permission
39
+ */
40
+ hasPermission(pluginScope: string, permission: Permission): boolean;
41
+
42
+ /**
43
+ * get permission
44
+ * @param pluginScope plugin name
45
+ * @param permission permission id
46
+ * @returns permission
47
+ */
48
+ getPermission(pluginScope: string, permission: symbol): Permission;
49
49
  }