@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
|
@@ -0,0 +1,578 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Plugin SDK utilities and interfaces for Talex Touch plugin development
|
|
3
|
+
* @author Talex Touch Team
|
|
4
|
+
* @version 1.0.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Plugin utilities interface providing core functionality for plugin development
|
|
9
|
+
*
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
export interface IPluginUtils {
|
|
13
|
+
/**
|
|
14
|
+
* HTTP client for network requests (axios instance)
|
|
15
|
+
* @remarks Provides direct access to axios for making HTTP requests
|
|
16
|
+
*/
|
|
17
|
+
http: any;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Data storage manager for persistent data operations
|
|
21
|
+
* @see {@link IStorageManager}
|
|
22
|
+
*/
|
|
23
|
+
storage: IStorageManager;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Clipboard manager for system clipboard operations
|
|
27
|
+
* @see {@link IClipboardManager}
|
|
28
|
+
*/
|
|
29
|
+
clipboard: IClipboardManager;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Search result manager for handling search operations
|
|
33
|
+
* @see {@link ISearchManager}
|
|
34
|
+
*/
|
|
35
|
+
search: ISearchManager;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Dialog manager for system dialog operations
|
|
39
|
+
* @see {@link IDialogManager}
|
|
40
|
+
*/
|
|
41
|
+
dialog: IDialogManager;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Logger for plugin logging operations
|
|
45
|
+
* @see {@link ILogger}
|
|
46
|
+
*/
|
|
47
|
+
logger: ILogger;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Event manager for plugin event handling
|
|
51
|
+
* @see {@link IEventManager}
|
|
52
|
+
*/
|
|
53
|
+
$event: IEventManager;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Opens a URL in the default browser
|
|
57
|
+
* @param url - The URL to open
|
|
58
|
+
*/
|
|
59
|
+
openUrl: (url: string) => void;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Pushes search result items to the search interface
|
|
63
|
+
* @param items - Array of search result items to add
|
|
64
|
+
*/
|
|
65
|
+
pushItems: (items: any[]) => void;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Clears all current search results
|
|
69
|
+
*/
|
|
70
|
+
clearItems: () => void;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Gets all current search result items
|
|
74
|
+
* @returns Array of current search result items
|
|
75
|
+
*/
|
|
76
|
+
getItems: () => any[];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Storage manager interface for persistent data operations
|
|
81
|
+
*
|
|
82
|
+
* @public
|
|
83
|
+
* @remarks Provides key-value storage functionality with JSON serialization
|
|
84
|
+
*/
|
|
85
|
+
export interface IStorageManager {
|
|
86
|
+
/**
|
|
87
|
+
* Sets a value for the given key
|
|
88
|
+
* @param key - The storage key
|
|
89
|
+
* @param value - The value to store (will be JSON serialized)
|
|
90
|
+
* @returns Promise that resolves when the value is stored
|
|
91
|
+
*/
|
|
92
|
+
set(key: string, value: any): Promise<void>;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Gets a value for the given key
|
|
96
|
+
* @param key - The storage key
|
|
97
|
+
* @param defaultValue - Default value to return if key doesn't exist
|
|
98
|
+
* @returns Promise that resolves to the stored value or default value
|
|
99
|
+
*/
|
|
100
|
+
get(key: string, defaultValue?: any): Promise<any>;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Checks if a key exists in storage
|
|
104
|
+
* @param key - The storage key to check
|
|
105
|
+
* @returns Promise that resolves to true if key exists, false otherwise
|
|
106
|
+
*/
|
|
107
|
+
has(key: string): Promise<boolean>;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Removes a key from storage
|
|
111
|
+
* @param key - The storage key to remove
|
|
112
|
+
* @returns Promise that resolves when the key is removed
|
|
113
|
+
*/
|
|
114
|
+
remove(key: string): Promise<void>;
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Clears all stored data
|
|
118
|
+
* @returns Promise that resolves when all data is cleared
|
|
119
|
+
*/
|
|
120
|
+
clear(): Promise<void>;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Gets all storage keys
|
|
124
|
+
* @returns Promise that resolves to an array of all storage keys
|
|
125
|
+
*/
|
|
126
|
+
keys(): Promise<string[]>;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Clipboard manager interface for system clipboard operations
|
|
131
|
+
*
|
|
132
|
+
* @public
|
|
133
|
+
* @remarks Provides access to system clipboard for text and image operations
|
|
134
|
+
*/
|
|
135
|
+
export interface IClipboardManager {
|
|
136
|
+
/**
|
|
137
|
+
* Reads text from the clipboard
|
|
138
|
+
* @returns The text content from clipboard
|
|
139
|
+
*/
|
|
140
|
+
readText(): string;
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Writes text to the clipboard
|
|
144
|
+
* @param text - The text to write to clipboard
|
|
145
|
+
*/
|
|
146
|
+
writeText(text: string): void;
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Reads image from the clipboard
|
|
150
|
+
* @returns The image data from clipboard, or null if no image
|
|
151
|
+
*/
|
|
152
|
+
readImage(): any | null;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Writes image to the clipboard
|
|
156
|
+
* @param image - The image data to write to clipboard
|
|
157
|
+
*/
|
|
158
|
+
writeImage(image: any): void;
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Clears the clipboard content
|
|
162
|
+
*/
|
|
163
|
+
clear(): void;
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Checks if clipboard contains text
|
|
167
|
+
* @returns True if clipboard has text content, false otherwise
|
|
168
|
+
*/
|
|
169
|
+
hasText(): boolean;
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Checks if clipboard contains image
|
|
173
|
+
* @returns True if clipboard has image content, false otherwise
|
|
174
|
+
*/
|
|
175
|
+
hasImage(): boolean;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Search manager interface for handling search operations
|
|
180
|
+
*
|
|
181
|
+
* @public
|
|
182
|
+
* @remarks Manages search query state and timing information
|
|
183
|
+
*/
|
|
184
|
+
export interface ISearchManager {
|
|
185
|
+
/**
|
|
186
|
+
* Updates the current search query
|
|
187
|
+
* @param query - The new search query string
|
|
188
|
+
*/
|
|
189
|
+
updateQuery(query: string): void;
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Gets the current search query
|
|
193
|
+
* @returns The current search query string
|
|
194
|
+
*/
|
|
195
|
+
getQuery(): string;
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Gets the timestamp of the last query update
|
|
199
|
+
* @returns Timestamp in milliseconds since epoch
|
|
200
|
+
*/
|
|
201
|
+
getTimestamp(): number;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Dialog manager interface for system dialog operations
|
|
206
|
+
*
|
|
207
|
+
* @public
|
|
208
|
+
* @remarks Provides access to native system dialogs
|
|
209
|
+
*/
|
|
210
|
+
export interface IDialogManager {
|
|
211
|
+
/**
|
|
212
|
+
* Shows a message box dialog
|
|
213
|
+
* @param options - Message box configuration options
|
|
214
|
+
* @param options.type - Dialog type (info, warning, error, question)
|
|
215
|
+
* @param options.title - Dialog title
|
|
216
|
+
* @param options.message - Main message text
|
|
217
|
+
* @param options.detail - Additional detail text
|
|
218
|
+
* @param options.buttons - Array of button labels
|
|
219
|
+
* @returns Promise that resolves to the dialog result
|
|
220
|
+
*/
|
|
221
|
+
showMessageBox(options: {
|
|
222
|
+
type?: 'info' | 'warning' | 'error' | 'question';
|
|
223
|
+
title?: string;
|
|
224
|
+
message: string;
|
|
225
|
+
detail?: string;
|
|
226
|
+
buttons?: string[];
|
|
227
|
+
}): Promise<any>;
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Shows an open file/folder dialog
|
|
231
|
+
* @param options - Open dialog configuration options
|
|
232
|
+
* @param options.title - Dialog title
|
|
233
|
+
* @param options.defaultPath - Default path to open
|
|
234
|
+
* @param options.filters - File type filters
|
|
235
|
+
* @param options.properties - Dialog properties (openFile, openDirectory, etc.)
|
|
236
|
+
* @returns Promise that resolves to the selected file/folder paths
|
|
237
|
+
*/
|
|
238
|
+
showOpenDialog(options: {
|
|
239
|
+
title?: string;
|
|
240
|
+
defaultPath?: string;
|
|
241
|
+
filters?: Array<{ name: string; extensions: string[] }>;
|
|
242
|
+
properties?: string[];
|
|
243
|
+
}): Promise<any>;
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Shows a save file dialog
|
|
247
|
+
* @param options - Save dialog configuration options
|
|
248
|
+
* @param options.title - Dialog title
|
|
249
|
+
* @param options.defaultPath - Default file path
|
|
250
|
+
* @param options.filters - File type filters
|
|
251
|
+
* @returns Promise that resolves to the selected save path
|
|
252
|
+
*/
|
|
253
|
+
showSaveDialog(options: {
|
|
254
|
+
title?: string;
|
|
255
|
+
defaultPath?: string;
|
|
256
|
+
filters?: Array<{ name: string; extensions: string[] }>;
|
|
257
|
+
}): Promise<any>;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Logger interface for plugin logging operations
|
|
262
|
+
*
|
|
263
|
+
* @public
|
|
264
|
+
* @remarks Provides structured logging with different severity levels
|
|
265
|
+
*/
|
|
266
|
+
export interface ILogger {
|
|
267
|
+
/**
|
|
268
|
+
* Logs an informational message
|
|
269
|
+
* @param message - The log message
|
|
270
|
+
* @param args - Additional arguments to log
|
|
271
|
+
*/
|
|
272
|
+
info(message: string, ...args: any[]): void;
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Logs a warning message
|
|
276
|
+
* @param message - The warning message
|
|
277
|
+
* @param args - Additional arguments to log
|
|
278
|
+
*/
|
|
279
|
+
warn(message: string, ...args: any[]): void;
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Logs an error message
|
|
283
|
+
* @param message - The error message
|
|
284
|
+
* @param args - Additional arguments to log
|
|
285
|
+
*/
|
|
286
|
+
error(message: string, ...args: any[]): void;
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Logs a debug message
|
|
290
|
+
* @param message - The debug message
|
|
291
|
+
* @param args - Additional arguments to log
|
|
292
|
+
*/
|
|
293
|
+
debug(message: string, ...args: any[]): void;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Event manager interface for plugin event handling
|
|
298
|
+
*
|
|
299
|
+
* @public
|
|
300
|
+
* @remarks Provides event-driven communication within plugins
|
|
301
|
+
*/
|
|
302
|
+
export interface IEventManager {
|
|
303
|
+
/**
|
|
304
|
+
* Registers an event listener
|
|
305
|
+
* @param event - The event name to listen for
|
|
306
|
+
* @param callback - The callback function to execute when event is emitted
|
|
307
|
+
*/
|
|
308
|
+
on(event: string, callback: Function): void;
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Removes an event listener
|
|
312
|
+
* @param event - The event name to stop listening for
|
|
313
|
+
* @param callback - The callback function to remove
|
|
314
|
+
*/
|
|
315
|
+
off(event: string, callback: Function): void;
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Emits an event with optional arguments
|
|
319
|
+
* @param event - The event name to emit
|
|
320
|
+
* @param args - Arguments to pass to event listeners
|
|
321
|
+
*/
|
|
322
|
+
emit(event: string, ...args: any[]): void;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Plugin configuration interface
|
|
327
|
+
*
|
|
328
|
+
* @public
|
|
329
|
+
* @remarks Flexible configuration object for plugin settings
|
|
330
|
+
*/
|
|
331
|
+
export interface IPluginConfig {
|
|
332
|
+
/** Dynamic configuration properties */
|
|
333
|
+
[key: string]: any;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Plugin context interface providing runtime information and utilities
|
|
338
|
+
*
|
|
339
|
+
* @public
|
|
340
|
+
* @remarks Contains all necessary context information for plugin execution
|
|
341
|
+
*/
|
|
342
|
+
export interface IPluginContext {
|
|
343
|
+
/**
|
|
344
|
+
* The name of the plugin
|
|
345
|
+
*/
|
|
346
|
+
pluginName: string;
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* The file system path to the plugin directory
|
|
350
|
+
*/
|
|
351
|
+
pluginPath: string;
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Plugin configuration object
|
|
355
|
+
* @see {@link IPluginConfig}
|
|
356
|
+
*/
|
|
357
|
+
config: IPluginConfig;
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Plugin utilities and tools
|
|
361
|
+
* @see {@link IPluginUtils}
|
|
362
|
+
*/
|
|
363
|
+
utils: IPluginUtils;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Plugin lifecycle interface defining plugin event handlers
|
|
368
|
+
*
|
|
369
|
+
* @public
|
|
370
|
+
* @remarks Defines the lifecycle methods that plugins can implement
|
|
371
|
+
*/
|
|
372
|
+
export interface IPluginLifecycle {
|
|
373
|
+
/**
|
|
374
|
+
* Called when the plugin is initialized
|
|
375
|
+
* @param context - The plugin context containing utilities and configuration
|
|
376
|
+
* @returns Promise or void
|
|
377
|
+
* @optional
|
|
378
|
+
*/
|
|
379
|
+
onInit?(context: IPluginContext): Promise<void> | void;
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Called when a plugin feature is triggered
|
|
383
|
+
* @param featureId - The ID of the triggered feature
|
|
384
|
+
* @param query - The search query or input data
|
|
385
|
+
* @param feature - The feature configuration object
|
|
386
|
+
* @returns Promise or void
|
|
387
|
+
*/
|
|
388
|
+
onFeatureTriggered(featureId: string, query: any, feature: any): Promise<void> | void;
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Called when user input changes (for real-time features)
|
|
392
|
+
* @param input - The current input string
|
|
393
|
+
* @returns Promise or void
|
|
394
|
+
* @optional
|
|
395
|
+
*/
|
|
396
|
+
onInputChanged?(input: string): Promise<void> | void;
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Called when an action button is clicked
|
|
400
|
+
* @param actionId - The ID of the clicked action
|
|
401
|
+
* @param data - Optional data associated with the action
|
|
402
|
+
* @returns Promise or void
|
|
403
|
+
* @optional
|
|
404
|
+
*/
|
|
405
|
+
onActionClick?(actionId: string, data?: any): Promise<void> | void;
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* Called when the plugin is being destroyed/unloaded
|
|
409
|
+
* @returns Promise or void
|
|
410
|
+
* @optional
|
|
411
|
+
*/
|
|
412
|
+
onDestroy?(): Promise<void> | void;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* Creates a storage manager instance for plugin data persistence
|
|
417
|
+
*
|
|
418
|
+
* @param pluginPath - The file system path to the plugin directory
|
|
419
|
+
* @param fse - File system extra module (fs-extra)
|
|
420
|
+
* @returns A configured storage manager instance
|
|
421
|
+
*
|
|
422
|
+
* @public
|
|
423
|
+
* @remarks Creates a JSON-based storage system in the plugin's data directory
|
|
424
|
+
*
|
|
425
|
+
* @example
|
|
426
|
+
* ```typescript
|
|
427
|
+
* const storage = createStorageManager('/path/to/plugin', fse);
|
|
428
|
+
* await storage.set('config', { theme: 'dark' });
|
|
429
|
+
* const config = await storage.get('config', {});
|
|
430
|
+
* ```
|
|
431
|
+
*/
|
|
432
|
+
export function createStorageManager(
|
|
433
|
+
pluginPath: string,
|
|
434
|
+
fse: any
|
|
435
|
+
): IStorageManager {
|
|
436
|
+
const path = require('path');
|
|
437
|
+
const dataPath = path.join(pluginPath, 'data');
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* Ensures the data directory exists
|
|
441
|
+
* @internal
|
|
442
|
+
*/
|
|
443
|
+
const ensureDataDir = async (): Promise<void> => {
|
|
444
|
+
if (!await fse.pathExists(dataPath)) {
|
|
445
|
+
await fse.ensureDir(dataPath);
|
|
446
|
+
}
|
|
447
|
+
};
|
|
448
|
+
|
|
449
|
+
return {
|
|
450
|
+
async set(key: string, value: any): Promise<void> {
|
|
451
|
+
await ensureDataDir();
|
|
452
|
+
const filePath = path.join(dataPath, `${key}.json`);
|
|
453
|
+
await fse.writeJSON(filePath, value, { spaces: 2 });
|
|
454
|
+
},
|
|
455
|
+
|
|
456
|
+
async get(key: string, defaultValue?: any): Promise<any> {
|
|
457
|
+
await ensureDataDir();
|
|
458
|
+
const filePath = path.join(dataPath, `${key}.json`);
|
|
459
|
+
if (await fse.pathExists(filePath)) {
|
|
460
|
+
return await fse.readJSON(filePath);
|
|
461
|
+
}
|
|
462
|
+
return defaultValue;
|
|
463
|
+
},
|
|
464
|
+
|
|
465
|
+
async has(key: string): Promise<boolean> {
|
|
466
|
+
await ensureDataDir();
|
|
467
|
+
const filePath = path.join(dataPath, `${key}.json`);
|
|
468
|
+
return await fse.pathExists(filePath);
|
|
469
|
+
},
|
|
470
|
+
|
|
471
|
+
async remove(key: string): Promise<void> {
|
|
472
|
+
await ensureDataDir();
|
|
473
|
+
const filePath = path.join(dataPath, `${key}.json`);
|
|
474
|
+
if (await fse.pathExists(filePath)) {
|
|
475
|
+
await fse.remove(filePath);
|
|
476
|
+
}
|
|
477
|
+
},
|
|
478
|
+
|
|
479
|
+
async clear(): Promise<void> {
|
|
480
|
+
if (await fse.pathExists(dataPath)) {
|
|
481
|
+
await fse.emptyDir(dataPath);
|
|
482
|
+
}
|
|
483
|
+
},
|
|
484
|
+
|
|
485
|
+
async keys(): Promise<string[]> {
|
|
486
|
+
await ensureDataDir();
|
|
487
|
+
const files = await fse.readdir(dataPath);
|
|
488
|
+
return files
|
|
489
|
+
.filter((file: string) => file.endsWith('.json'))
|
|
490
|
+
.map((file: string) => path.basename(file, '.json'));
|
|
491
|
+
}
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* Creates a clipboard manager instance for system clipboard operations
|
|
497
|
+
*
|
|
498
|
+
* @param clipboard - The Electron clipboard module
|
|
499
|
+
* @returns A configured clipboard manager instance
|
|
500
|
+
*
|
|
501
|
+
* @public
|
|
502
|
+
* @remarks Provides a wrapper around Electron's clipboard API
|
|
503
|
+
*
|
|
504
|
+
* @example
|
|
505
|
+
* ```typescript
|
|
506
|
+
* const clipboardManager = createClipboardManager(clipboard);
|
|
507
|
+
* clipboardManager.writeText('Hello World');
|
|
508
|
+
* const text = clipboardManager.readText();
|
|
509
|
+
* ```
|
|
510
|
+
*/
|
|
511
|
+
export function createClipboardManager(clipboard: any): IClipboardManager {
|
|
512
|
+
return {
|
|
513
|
+
readText(): string {
|
|
514
|
+
return clipboard.readText();
|
|
515
|
+
},
|
|
516
|
+
|
|
517
|
+
writeText(text: string): void {
|
|
518
|
+
clipboard.writeText(text);
|
|
519
|
+
},
|
|
520
|
+
|
|
521
|
+
readImage(): any | null {
|
|
522
|
+
const image = clipboard.readImage();
|
|
523
|
+
return image.isEmpty() ? null : image;
|
|
524
|
+
},
|
|
525
|
+
|
|
526
|
+
writeImage(image: any): void {
|
|
527
|
+
clipboard.writeImage(image);
|
|
528
|
+
},
|
|
529
|
+
|
|
530
|
+
clear(): void {
|
|
531
|
+
clipboard.clear();
|
|
532
|
+
},
|
|
533
|
+
|
|
534
|
+
hasText(): boolean {
|
|
535
|
+
return clipboard.has('text/plain');
|
|
536
|
+
},
|
|
537
|
+
|
|
538
|
+
hasImage(): boolean {
|
|
539
|
+
return clipboard.has('image/png') || clipboard.has('image/jpeg');
|
|
540
|
+
}
|
|
541
|
+
};
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* Creates a search manager instance for handling search state
|
|
546
|
+
*
|
|
547
|
+
* @returns A configured search manager instance
|
|
548
|
+
*
|
|
549
|
+
* @public
|
|
550
|
+
* @remarks Manages search query state and timing information
|
|
551
|
+
*
|
|
552
|
+
* @example
|
|
553
|
+
* ```typescript
|
|
554
|
+
* const searchManager = createSearchManager();
|
|
555
|
+
* searchManager.updateQuery('hello world');
|
|
556
|
+
* const query = searchManager.getQuery();
|
|
557
|
+
* const timestamp = searchManager.getTimestamp();
|
|
558
|
+
* ```
|
|
559
|
+
*/
|
|
560
|
+
export function createSearchManager(): ISearchManager {
|
|
561
|
+
let currentQuery = '';
|
|
562
|
+
let timestamp = Date.now();
|
|
563
|
+
|
|
564
|
+
return {
|
|
565
|
+
updateQuery(query: string): void {
|
|
566
|
+
currentQuery = query;
|
|
567
|
+
timestamp = Date.now();
|
|
568
|
+
},
|
|
569
|
+
|
|
570
|
+
getQuery(): string {
|
|
571
|
+
return currentQuery;
|
|
572
|
+
},
|
|
573
|
+
|
|
574
|
+
getTimestamp(): number {
|
|
575
|
+
return timestamp;
|
|
576
|
+
}
|
|
577
|
+
};
|
|
578
|
+
}
|
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import { genChannel } from '../../channel';
|
|
2
|
-
import {
|
|
3
|
-
BrowserWindowConstructorOptions, BrowserWindow, WebContents
|
|
4
|
-
} from "electron";
|
|
5
|
-
|
|
6
|
-
export function createWindow(options: BrowserWindowConstructorOptions & { file?: string } & { url?: string }): number {
|
|
7
|
-
const res = genChannel().sendSync('window:new', options)
|
|
8
|
-
if (res.error) throw new Error(res.error)
|
|
9
|
-
|
|
10
|
-
return res.id
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function toggleWinVisible(id: number, visible?: boolean): boolean {
|
|
14
|
-
const res = genChannel().sendSync('window:visible', visible !== undefined ? { id, visible } : { id })
|
|
15
|
-
if (res.error) throw new Error(res.error)
|
|
16
|
-
|
|
17
|
-
return res.visible
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function setWindowProperty(id: number, property: {
|
|
21
|
-
|
|
22
|
-
}): boolean {
|
|
23
|
-
const res = genChannel().sendSync('window:property', { id, property })
|
|
24
|
-
if (res.error) throw new Error(res.error)
|
|
25
|
-
|
|
26
|
-
return res.success
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export type WindowProperty = {
|
|
30
|
-
[P in keyof BrowserWindow]?: BrowserWindow[P]
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export type WebContentsProperty = {
|
|
34
|
-
[P in keyof WebContents]?: WebContents[P]
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export interface WindowProperties {
|
|
38
|
-
window?: WindowProperty
|
|
39
|
-
webContents?: WebContentsProperty
|
|
40
|
-
}
|
|
1
|
+
import { genChannel } from '../../channel';
|
|
2
|
+
import {
|
|
3
|
+
BrowserWindowConstructorOptions, BrowserWindow, WebContents
|
|
4
|
+
} from "electron";
|
|
5
|
+
|
|
6
|
+
export function createWindow(options: BrowserWindowConstructorOptions & { file?: string } & { url?: string }): number {
|
|
7
|
+
const res = genChannel().sendSync('window:new', options)
|
|
8
|
+
if (res.error) throw new Error(res.error)
|
|
9
|
+
|
|
10
|
+
return res.id
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function toggleWinVisible(id: number, visible?: boolean): boolean {
|
|
14
|
+
const res = genChannel().sendSync('window:visible', visible !== undefined ? { id, visible } : { id })
|
|
15
|
+
if (res.error) throw new Error(res.error)
|
|
16
|
+
|
|
17
|
+
return res.visible
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function setWindowProperty(id: number, property: {
|
|
21
|
+
|
|
22
|
+
}): boolean {
|
|
23
|
+
const res = genChannel().sendSync('window:property', { id, property })
|
|
24
|
+
if (res.error) throw new Error(res.error)
|
|
25
|
+
|
|
26
|
+
return res.success
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type WindowProperty = {
|
|
30
|
+
[P in keyof BrowserWindow]?: BrowserWindow[P]
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type WebContentsProperty = {
|
|
34
|
+
[P in keyof WebContents]?: WebContents[P]
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface WindowProperties {
|
|
38
|
+
window?: WindowProperty
|
|
39
|
+
webContents?: WebContentsProperty
|
|
40
|
+
}
|