@talex-touch/utils 1.0.35 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@talex-touch/utils",
3
- "version": "1.0.35",
3
+ "version": "1.0.37",
4
4
  "private": false,
5
5
  "description": "Tuff series utils",
6
6
  "author": "TalexDreamSoul",
@@ -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,29 +194,23 @@ export interface BoxSDK {
193
194
  *
194
195
  * @internal
195
196
  */
196
- export function createBoxSDK(channel: any): BoxSDK {
197
- const sendFn = channel.sendToMain || channel.send
198
-
199
- if (!sendFn) {
200
- throw new Error('[Box SDK] Channel send function not available')
201
- }
202
-
197
+ export function createBoxSDK(channel: ITouchClientChannel): BoxSDK {
203
198
  return {
204
199
  hide(): void {
205
- sendFn('core-box:hide').catch((error: any) => {
200
+ channel.send('core-box:hide').catch((error: any) => {
206
201
  console.error('[Box SDK] Failed to hide CoreBox:', error)
207
202
  })
208
203
  },
209
204
 
210
205
  show(): void {
211
- sendFn('core-box:show').catch((error: any) => {
206
+ channel.send('core-box:show').catch((error: any) => {
212
207
  console.error('[Box SDK] Failed to show CoreBox:', error)
213
208
  })
214
209
  },
215
210
 
216
211
  async expand(options?: BoxExpandOptions): Promise<void> {
217
212
  try {
218
- await sendFn('core-box:expand', options || {})
213
+ await channel.send('core-box:expand', options || {})
219
214
  }
220
215
  catch (error) {
221
216
  console.error('[Box SDK] Failed to expand CoreBox:', error)
@@ -225,7 +220,7 @@ export function createBoxSDK(channel: any): BoxSDK {
225
220
 
226
221
  async shrink(): Promise<void> {
227
222
  try {
228
- await sendFn('core-box:expand', { mode: 'collapse' })
223
+ await channel.send('core-box:expand', { mode: 'collapse' })
229
224
  }
230
225
  catch (error) {
231
226
  console.error('[Box SDK] Failed to shrink CoreBox:', error)
@@ -235,7 +230,7 @@ export function createBoxSDK(channel: any): BoxSDK {
235
230
 
236
231
  async hideInput(): Promise<void> {
237
232
  try {
238
- await sendFn('core-box:hide-input')
233
+ await channel.send('core-box:hide-input')
239
234
  }
240
235
  catch (error) {
241
236
  console.error('[Box SDK] Failed to hide input:', error)
@@ -245,7 +240,7 @@ export function createBoxSDK(channel: any): BoxSDK {
245
240
 
246
241
  async showInput(): Promise<void> {
247
242
  try {
248
- await sendFn('core-box:show-input')
243
+ await channel.send('core-box:show-input')
249
244
  }
250
245
  catch (error) {
251
246
  console.error('[Box SDK] Failed to show input:', error)
@@ -255,7 +250,7 @@ export function createBoxSDK(channel: any): BoxSDK {
255
250
 
256
251
  async getInput(): Promise<string> {
257
252
  try {
258
- const result = await sendFn('core-box:get-input')
253
+ const result = await channel.send('core-box:get-input')
259
254
  return result?.data?.input || result?.input || ''
260
255
  }
261
256
  catch (error) {
@@ -266,7 +261,7 @@ export function createBoxSDK(channel: any): BoxSDK {
266
261
 
267
262
  async setInput(value: string): Promise<void> {
268
263
  try {
269
- await sendFn('core-box:set-input', { value })
264
+ await channel.send('core-box:set-input', { value })
270
265
  }
271
266
  catch (error) {
272
267
  console.error('[Box SDK] Failed to set input:', error)
@@ -276,7 +271,7 @@ export function createBoxSDK(channel: any): BoxSDK {
276
271
 
277
272
  async clearInput(): Promise<void> {
278
273
  try {
279
- await sendFn('core-box:clear-input')
274
+ await channel.send('core-box:clear-input')
280
275
  }
281
276
  catch (error) {
282
277
  console.error('[Box SDK] Failed to clear input:', error)
@@ -286,7 +281,7 @@ export function createBoxSDK(channel: any): BoxSDK {
286
281
 
287
282
  async allowInput(): Promise<void> {
288
283
  try {
289
- await sendFn('core-box:allow-input')
284
+ await channel.send('core-box:allow-input')
290
285
  }
291
286
  catch (error) {
292
287
  console.error('[Box SDK] Failed to enable input monitoring:', error)
@@ -296,7 +291,7 @@ export function createBoxSDK(channel: any): BoxSDK {
296
291
 
297
292
  async allowClipboard(types: number): Promise<void> {
298
293
  try {
299
- await sendFn('core-box:allow-clipboard', types)
294
+ await channel.send('core-box:allow-clipboard', types)
300
295
  }
301
296
  catch (error) {
302
297
  console.error('[Box SDK] Failed to enable clipboard monitoring:', error)
@@ -181,11 +181,19 @@ export function createDivisionBoxSDK(channel: any): DivisionBoxSDK {
181
181
 
182
182
  registerListener()
183
183
 
184
+ const send: (eventName: string, payload?: any) => Promise<any> =
185
+ typeof channel?.sendToMain === 'function'
186
+ ? channel.sendToMain.bind(channel)
187
+ : typeof channel?.send === 'function'
188
+ ? channel.send.bind(channel)
189
+ : (() => {
190
+ throw new Error('[DivisionBox SDK] Channel send function not available')
191
+ })()
192
+
184
193
  return {
185
194
  async open(config: DivisionBoxConfig): Promise<SessionInfo> {
186
195
  // Send to main process
187
- const sendFn = channel.sendToMain || channel.send
188
- const result = await sendFn('division-box:open', config)
196
+ const result = await send('division-box:open', config)
189
197
 
190
198
  if (!result.success) {
191
199
  throw new Error(result.error?.message || 'Failed to open DivisionBox')
@@ -195,8 +203,7 @@ export function createDivisionBoxSDK(channel: any): DivisionBoxSDK {
195
203
  },
196
204
 
197
205
  async close(sessionId: string, options?: CloseOptions): Promise<void> {
198
- const sendFn = channel.sendToMain || channel.send
199
- const result = await sendFn('division-box:close', { sessionId, options })
206
+ const result = await send('division-box:close', { sessionId, options })
200
207
 
201
208
  if (!result.success) {
202
209
  throw new Error(result.error?.message || 'Failed to close DivisionBox')
@@ -212,8 +219,7 @@ export function createDivisionBoxSDK(channel: any): DivisionBoxSDK {
212
219
  },
213
220
 
214
221
  async updateState(sessionId: string, key: string, value: any): Promise<void> {
215
- const sendFn = channel.sendToMain || channel.send
216
- const result = await sendFn('division-box:update-state', {
222
+ const result = await send('division-box:update-state', {
217
223
  sessionId,
218
224
  key,
219
225
  value
@@ -225,8 +231,7 @@ export function createDivisionBoxSDK(channel: any): DivisionBoxSDK {
225
231
  },
226
232
 
227
233
  async getState(sessionId: string, key: string): Promise<any> {
228
- const sendFn = channel.sendToMain || channel.send
229
- const result = await sendFn('division-box:get-state', {
234
+ const result = await send('division-box:get-state', {
230
235
  sessionId,
231
236
  key
232
237
  })