@talex-touch/utils 1.0.28 → 1.0.29
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/package.json +1 -1
- package/plugin/sdk/storage.ts +10 -32
package/package.json
CHANGED
package/plugin/sdk/storage.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Get the storage for the current plugin.
|
|
3
|
-
* It provides file-based storage that is persisted across application launches.
|
|
3
|
+
* It provides simple file-based storage that is persisted across application launches.
|
|
4
4
|
* Each plugin can have multiple storage files in its own directory.
|
|
5
5
|
*
|
|
6
6
|
* @returns An object with methods to interact with the storage.
|
|
@@ -21,7 +21,7 @@ export function usePluginStorage() {
|
|
|
21
21
|
* @param fileName The name of the file to retrieve.
|
|
22
22
|
* @returns A promise that resolves with the file content, or null if the file does not exist.
|
|
23
23
|
*/
|
|
24
|
-
|
|
24
|
+
getFile: async (fileName: string): Promise<any> => {
|
|
25
25
|
return channel.send('plugin:storage:get-file', { pluginName, fileName })
|
|
26
26
|
},
|
|
27
27
|
|
|
@@ -31,47 +31,25 @@ export function usePluginStorage() {
|
|
|
31
31
|
* @param content The content to store in the file.
|
|
32
32
|
* @returns A promise that resolves when the file has been stored.
|
|
33
33
|
*/
|
|
34
|
-
|
|
35
|
-
return channel.send('plugin:storage:
|
|
34
|
+
setFile: async (fileName: string, content: any): Promise<{ success: boolean, error?: string }> => {
|
|
35
|
+
return channel.send('plugin:storage:set-file', { pluginName, fileName, content: JSON.parse(JSON.stringify(content)) })
|
|
36
36
|
},
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
|
-
*
|
|
40
|
-
* @param fileName The name of the file to
|
|
41
|
-
* @returns A promise that resolves when the file has been
|
|
39
|
+
* Deletes a storage file.
|
|
40
|
+
* @param fileName The name of the file to delete.
|
|
41
|
+
* @returns A promise that resolves when the file has been deleted.
|
|
42
42
|
*/
|
|
43
|
-
|
|
44
|
-
return channel.send('plugin:storage:
|
|
43
|
+
deleteFile: async (fileName: string): Promise<{ success: boolean, error?: string }> => {
|
|
44
|
+
return channel.send('plugin:storage:delete-file', { pluginName, fileName })
|
|
45
45
|
},
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
48
|
* Lists all storage files for the current plugin.
|
|
49
49
|
* @returns A promise that resolves with an array of file names.
|
|
50
50
|
*/
|
|
51
|
-
|
|
51
|
+
listFiles: async (): Promise<string[]> => {
|
|
52
52
|
return channel.send('plugin:storage:list-files', { pluginName })
|
|
53
|
-
},
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Listens for changes to the storage.
|
|
57
|
-
* When `clear()` is called, the key will be `__clear__`.
|
|
58
|
-
* @param fileName The file name to listen for changes
|
|
59
|
-
* @param callback The function to call when the storage changes for the current plugin.
|
|
60
|
-
* @returns A function to unsubscribe from the listener.
|
|
61
|
-
*/
|
|
62
|
-
onDidChange: (fileName: string, callback: (newConfig: any) => void) => {
|
|
63
|
-
const listener = (data: { name: string, fileName?: string, key?: string }) => {
|
|
64
|
-
if (data.name === pluginName &&
|
|
65
|
-
(data.fileName === fileName || data.fileName === undefined)) {
|
|
66
|
-
callback(data)
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
channel.regChannel('plugin:storage:update', listener)
|
|
71
|
-
|
|
72
|
-
return () => {
|
|
73
|
-
channel.unRegChannel('plugin:storage:update', listener)
|
|
74
|
-
}
|
|
75
53
|
}
|
|
76
54
|
}
|
|
77
55
|
}
|