@talex-touch/utils 1.0.36 → 1.0.37
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/box-sdk.ts +13 -21
package/package.json
CHANGED
package/plugin/sdk/box-sdk.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* Provides a unified API for plugins to control the CoreBox window behavior,
|
|
5
5
|
* including visibility, size, input field control, and input value access.
|
|
6
6
|
*/
|
|
7
|
+
import type { ITouchClientChannel } from '@talex-touch/utils/channel'
|
|
7
8
|
import { ensureRendererChannel } from './channel'
|
|
8
9
|
|
|
9
10
|
/**
|
|
@@ -193,32 +194,23 @@ export interface BoxSDK {
|
|
|
193
194
|
*
|
|
194
195
|
* @internal
|
|
195
196
|
*/
|
|
196
|
-
export function createBoxSDK(channel:
|
|
197
|
-
const send: (eventName: string, payload?: any) => Promise<any> =
|
|
198
|
-
typeof channel?.sendToMain === 'function'
|
|
199
|
-
? channel.sendToMain.bind(channel)
|
|
200
|
-
: typeof channel?.send === 'function'
|
|
201
|
-
? channel.send.bind(channel)
|
|
202
|
-
: (() => {
|
|
203
|
-
throw new Error('[Box SDK] Channel send function not available')
|
|
204
|
-
})()
|
|
205
|
-
|
|
197
|
+
export function createBoxSDK(channel: ITouchClientChannel): BoxSDK {
|
|
206
198
|
return {
|
|
207
199
|
hide(): void {
|
|
208
|
-
send('core-box:hide').catch((error: any) => {
|
|
200
|
+
channel.send('core-box:hide').catch((error: any) => {
|
|
209
201
|
console.error('[Box SDK] Failed to hide CoreBox:', error)
|
|
210
202
|
})
|
|
211
203
|
},
|
|
212
204
|
|
|
213
205
|
show(): void {
|
|
214
|
-
send('core-box:show').catch((error: any) => {
|
|
206
|
+
channel.send('core-box:show').catch((error: any) => {
|
|
215
207
|
console.error('[Box SDK] Failed to show CoreBox:', error)
|
|
216
208
|
})
|
|
217
209
|
},
|
|
218
210
|
|
|
219
211
|
async expand(options?: BoxExpandOptions): Promise<void> {
|
|
220
212
|
try {
|
|
221
|
-
await send('core-box:expand', options || {})
|
|
213
|
+
await channel.send('core-box:expand', options || {})
|
|
222
214
|
}
|
|
223
215
|
catch (error) {
|
|
224
216
|
console.error('[Box SDK] Failed to expand CoreBox:', error)
|
|
@@ -228,7 +220,7 @@ export function createBoxSDK(channel: any): BoxSDK {
|
|
|
228
220
|
|
|
229
221
|
async shrink(): Promise<void> {
|
|
230
222
|
try {
|
|
231
|
-
await send('core-box:expand', { mode: 'collapse' })
|
|
223
|
+
await channel.send('core-box:expand', { mode: 'collapse' })
|
|
232
224
|
}
|
|
233
225
|
catch (error) {
|
|
234
226
|
console.error('[Box SDK] Failed to shrink CoreBox:', error)
|
|
@@ -238,7 +230,7 @@ export function createBoxSDK(channel: any): BoxSDK {
|
|
|
238
230
|
|
|
239
231
|
async hideInput(): Promise<void> {
|
|
240
232
|
try {
|
|
241
|
-
await send('core-box:hide-input')
|
|
233
|
+
await channel.send('core-box:hide-input')
|
|
242
234
|
}
|
|
243
235
|
catch (error) {
|
|
244
236
|
console.error('[Box SDK] Failed to hide input:', error)
|
|
@@ -248,7 +240,7 @@ export function createBoxSDK(channel: any): BoxSDK {
|
|
|
248
240
|
|
|
249
241
|
async showInput(): Promise<void> {
|
|
250
242
|
try {
|
|
251
|
-
await send('core-box:show-input')
|
|
243
|
+
await channel.send('core-box:show-input')
|
|
252
244
|
}
|
|
253
245
|
catch (error) {
|
|
254
246
|
console.error('[Box SDK] Failed to show input:', error)
|
|
@@ -258,7 +250,7 @@ export function createBoxSDK(channel: any): BoxSDK {
|
|
|
258
250
|
|
|
259
251
|
async getInput(): Promise<string> {
|
|
260
252
|
try {
|
|
261
|
-
const result = await send('core-box:get-input')
|
|
253
|
+
const result = await channel.send('core-box:get-input')
|
|
262
254
|
return result?.data?.input || result?.input || ''
|
|
263
255
|
}
|
|
264
256
|
catch (error) {
|
|
@@ -269,7 +261,7 @@ export function createBoxSDK(channel: any): BoxSDK {
|
|
|
269
261
|
|
|
270
262
|
async setInput(value: string): Promise<void> {
|
|
271
263
|
try {
|
|
272
|
-
await send('core-box:set-input', { value })
|
|
264
|
+
await channel.send('core-box:set-input', { value })
|
|
273
265
|
}
|
|
274
266
|
catch (error) {
|
|
275
267
|
console.error('[Box SDK] Failed to set input:', error)
|
|
@@ -279,7 +271,7 @@ export function createBoxSDK(channel: any): BoxSDK {
|
|
|
279
271
|
|
|
280
272
|
async clearInput(): Promise<void> {
|
|
281
273
|
try {
|
|
282
|
-
await send('core-box:clear-input')
|
|
274
|
+
await channel.send('core-box:clear-input')
|
|
283
275
|
}
|
|
284
276
|
catch (error) {
|
|
285
277
|
console.error('[Box SDK] Failed to clear input:', error)
|
|
@@ -289,7 +281,7 @@ export function createBoxSDK(channel: any): BoxSDK {
|
|
|
289
281
|
|
|
290
282
|
async allowInput(): Promise<void> {
|
|
291
283
|
try {
|
|
292
|
-
await send('core-box:allow-input')
|
|
284
|
+
await channel.send('core-box:allow-input')
|
|
293
285
|
}
|
|
294
286
|
catch (error) {
|
|
295
287
|
console.error('[Box SDK] Failed to enable input monitoring:', error)
|
|
@@ -299,7 +291,7 @@ export function createBoxSDK(channel: any): BoxSDK {
|
|
|
299
291
|
|
|
300
292
|
async allowClipboard(types: number): Promise<void> {
|
|
301
293
|
try {
|
|
302
|
-
await send('core-box:allow-clipboard', types)
|
|
294
|
+
await channel.send('core-box:allow-clipboard', types)
|
|
303
295
|
}
|
|
304
296
|
catch (error) {
|
|
305
297
|
console.error('[Box SDK] Failed to enable clipboard monitoring:', error)
|