@talex-touch/utils 1.0.35 → 1.0.36

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.36",
4
4
  "private": false,
5
5
  "description": "Tuff series utils",
6
6
  "author": "TalexDreamSoul",
@@ -194,28 +194,31 @@ export interface BoxSDK {
194
194
  * @internal
195
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
- }
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
+ })()
202
205
 
203
206
  return {
204
207
  hide(): void {
205
- sendFn('core-box:hide').catch((error: any) => {
208
+ send('core-box:hide').catch((error: any) => {
206
209
  console.error('[Box SDK] Failed to hide CoreBox:', error)
207
210
  })
208
211
  },
209
212
 
210
213
  show(): void {
211
- sendFn('core-box:show').catch((error: any) => {
214
+ send('core-box:show').catch((error: any) => {
212
215
  console.error('[Box SDK] Failed to show CoreBox:', error)
213
216
  })
214
217
  },
215
218
 
216
219
  async expand(options?: BoxExpandOptions): Promise<void> {
217
220
  try {
218
- await sendFn('core-box:expand', options || {})
221
+ await send('core-box:expand', options || {})
219
222
  }
220
223
  catch (error) {
221
224
  console.error('[Box SDK] Failed to expand CoreBox:', error)
@@ -225,7 +228,7 @@ export function createBoxSDK(channel: any): BoxSDK {
225
228
 
226
229
  async shrink(): Promise<void> {
227
230
  try {
228
- await sendFn('core-box:expand', { mode: 'collapse' })
231
+ await send('core-box:expand', { mode: 'collapse' })
229
232
  }
230
233
  catch (error) {
231
234
  console.error('[Box SDK] Failed to shrink CoreBox:', error)
@@ -235,7 +238,7 @@ export function createBoxSDK(channel: any): BoxSDK {
235
238
 
236
239
  async hideInput(): Promise<void> {
237
240
  try {
238
- await sendFn('core-box:hide-input')
241
+ await send('core-box:hide-input')
239
242
  }
240
243
  catch (error) {
241
244
  console.error('[Box SDK] Failed to hide input:', error)
@@ -245,7 +248,7 @@ export function createBoxSDK(channel: any): BoxSDK {
245
248
 
246
249
  async showInput(): Promise<void> {
247
250
  try {
248
- await sendFn('core-box:show-input')
251
+ await send('core-box:show-input')
249
252
  }
250
253
  catch (error) {
251
254
  console.error('[Box SDK] Failed to show input:', error)
@@ -255,7 +258,7 @@ export function createBoxSDK(channel: any): BoxSDK {
255
258
 
256
259
  async getInput(): Promise<string> {
257
260
  try {
258
- const result = await sendFn('core-box:get-input')
261
+ const result = await send('core-box:get-input')
259
262
  return result?.data?.input || result?.input || ''
260
263
  }
261
264
  catch (error) {
@@ -266,7 +269,7 @@ export function createBoxSDK(channel: any): BoxSDK {
266
269
 
267
270
  async setInput(value: string): Promise<void> {
268
271
  try {
269
- await sendFn('core-box:set-input', { value })
272
+ await send('core-box:set-input', { value })
270
273
  }
271
274
  catch (error) {
272
275
  console.error('[Box SDK] Failed to set input:', error)
@@ -276,7 +279,7 @@ export function createBoxSDK(channel: any): BoxSDK {
276
279
 
277
280
  async clearInput(): Promise<void> {
278
281
  try {
279
- await sendFn('core-box:clear-input')
282
+ await send('core-box:clear-input')
280
283
  }
281
284
  catch (error) {
282
285
  console.error('[Box SDK] Failed to clear input:', error)
@@ -286,7 +289,7 @@ export function createBoxSDK(channel: any): BoxSDK {
286
289
 
287
290
  async allowInput(): Promise<void> {
288
291
  try {
289
- await sendFn('core-box:allow-input')
292
+ await send('core-box:allow-input')
290
293
  }
291
294
  catch (error) {
292
295
  console.error('[Box SDK] Failed to enable input monitoring:', error)
@@ -296,7 +299,7 @@ export function createBoxSDK(channel: any): BoxSDK {
296
299
 
297
300
  async allowClipboard(types: number): Promise<void> {
298
301
  try {
299
- await sendFn('core-box:allow-clipboard', types)
302
+ await send('core-box:allow-clipboard', types)
300
303
  }
301
304
  catch (error) {
302
305
  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
  })