@@ -10,6 +10,7 @@ export type CopyProgress = {
1010 totalBytes : string
1111 progress : number
1212 cachedPath ?: string
13+ error ?: string
1314}
1415
1516export class FileSelectedHandler {
@@ -54,16 +55,21 @@ type CopyHandlers = {
5455 onStart : ( path : string , size : bigint ) => void
5556 onEvent : ( event : CopyProgress ) => void
5657 onComplete : ( path : string ) => void
58+ onError ?: ( message : string ) => void
5759}
5860
5961function bindCopyChannel (
6062 channel : { onmessage : ( event : CopyProgress ) => void } ,
6163 handlers : CopyHandlers
6264) {
6365 channel . onmessage = ( event : CopyProgress ) => {
64- if ( event . progress === 0 && event . cachedPath ) {
65- handlers . onStart ( event . cachedPath , BigInt ( event . totalBytes ) )
66- } else if ( event . progress === 1 && event . cachedPath ) {
66+ if ( event . error ) {
67+ handlers . onError ?.( event . error )
68+ return
69+ }
70+ if ( event . cachedPath && ( event . progress === 0 || event . progress === 0.0 ) ) {
71+ handlers . onStart ( event . cachedPath , BigInt ( event . totalBytes || '0' ) )
72+ } else if ( event . cachedPath && event . progress >= 1 ) {
6773 handlers . onComplete ( event . cachedPath )
6874 } else {
6975 handlers . onEvent ( event )
@@ -74,7 +80,8 @@ function bindCopyChannel(
7480export async function selectSendDocument (
7581 onStart : ( path : string , size : bigint ) => void ,
7682 onEvent : ( event : CopyProgress ) => void ,
77- onComplete : ( path : string ) => void
83+ onComplete : ( path : string ) => void ,
84+ onError ?: ( message : string ) => void
7885) : Promise < FileSelectedHandler | null > {
7986 if ( ! IS_TAURI ) {
8087 const selected = await openDialog ( { multiple : true , directory : false } )
@@ -89,7 +96,7 @@ export async function selectSendDocument(
8996
9097 const { Channel } = await import ( '@tauri-apps/api/core' )
9198 const channel = new Channel < CopyProgress > ( )
92- bindCopyChannel ( channel , { onStart, onEvent, onComplete } )
99+ bindCopyChannel ( channel , { onStart, onEvent, onComplete, onError } )
93100 const response = await invoke < boolean | undefined > (
94101 'plugin:native-utils|select_send_document' ,
95102 {
@@ -103,7 +110,8 @@ export async function selectSendDocument(
103110export async function selectSendFolder (
104111 onStart : ( path : string , size : bigint ) => void ,
105112 onEvent : ( event : CopyProgress ) => void ,
106- onComplete : ( path : string ) => void
113+ onComplete : ( path : string ) => void ,
114+ onError ?: ( message : string ) => void
107115) : Promise < FileSelectedHandler | null > {
108116 if ( ! IS_TAURI ) {
109117 const selected = await openDialog ( { multiple : false , directory : true } )
@@ -117,7 +125,7 @@ export async function selectSendFolder(
117125
118126 const { Channel } = await import ( '@tauri-apps/api/core' )
119127 const channel = new Channel < CopyProgress > ( )
120- bindCopyChannel ( channel , { onStart, onEvent, onComplete } )
128+ bindCopyChannel ( channel , { onStart, onEvent, onComplete, onError } )
121129 const response = await invoke < boolean > (
122130 'plugin:native-utils|select_send_folder' ,
123131 {
@@ -132,13 +140,14 @@ export async function selectSendFolder(
132140export async function consumeShareIntent (
133141 onStart : ( path : string , size : bigint ) => void ,
134142 onEvent : ( event : CopyProgress ) => void ,
135- onComplete : ( path : string ) => void
143+ onComplete : ( path : string ) => void ,
144+ onError ?: ( message : string ) => void
136145) : Promise < FileSelectedHandler | null > {
137146 if ( ! IS_TAURI ) return null
138147
139148 const { Channel } = await import ( '@tauri-apps/api/core' )
140149 const channel = new Channel < CopyProgress > ( )
141- bindCopyChannel ( channel , { onStart, onEvent, onComplete } )
150+ bindCopyChannel ( channel , { onStart, onEvent, onComplete, onError } )
142151 const response = await invoke < boolean | undefined > (
143152 'plugin:native-utils|consume_share_intent' ,
144153 { channel }
0 commit comments