@@ -357,30 +357,41 @@ export const useSessionCommands = (input: {
357357 return [
358358 {
359359 id : "session.share" ,
360- title : input . language . t ( "command.session.share" ) ,
361- description : input . language . t ( "command.session.share.description" ) ,
360+ title : input . info ( ) ?. share ?. url ? "Copy share link" : input . language . t ( "command.session.share" ) ,
361+ description : input . info ( ) ?. share ?. url
362+ ? "Copy share URL to clipboard"
363+ : input . language . t ( "command.session.share.description" ) ,
362364 category : input . language . t ( "command.category.session" ) ,
363365 slash : "share" ,
364- disabled : ! input . params . id || ! ! input . info ( ) ?. share ?. url ,
366+ disabled : ! input . params . id ,
365367 onSelect : async ( ) => {
366368 if ( ! input . params . id ) return
367- await input . sdk . client . session
368- . share ( { sessionID : input . params . id } )
369- . then ( ( res ) => {
370- navigator . clipboard . writeText ( res . data ! . share ! . url ) . catch ( ( ) =>
369+ const copy = ( url : string , existing : boolean ) =>
370+ navigator . clipboard
371+ . writeText ( url )
372+ . then ( ( ) =>
373+ showToast ( {
374+ title : existing
375+ ? input . language . t ( "session.share.copy.copied" )
376+ : input . language . t ( "toast.session.share.success.title" ) ,
377+ description : input . language . t ( "toast.session.share.success.description" ) ,
378+ variant : "success" ,
379+ } ) ,
380+ )
381+ . catch ( ( ) =>
371382 showToast ( {
372383 title : input . language . t ( "toast.session.share.copyFailed.title" ) ,
373384 variant : "error" ,
374385 } ) ,
375386 )
376- } )
377- . then ( ( ) =>
378- showToast ( {
379- title : input . language . t ( "toast.session.share.success.title" ) ,
380- description : input . language . t ( "toast.session.share.success.description" ) ,
381- variant : "success" ,
382- } ) ,
383- )
387+ const url = input . info ( ) ?. share ?. url
388+ if ( url ) {
389+ await copy ( url , true )
390+ return
391+ }
392+ await input . sdk . client . session
393+ . share ( { sessionID : input . params . id } )
394+ . then ( ( res ) => copy ( res . data ! . share ! . url , false ) )
384395 . catch ( ( ) =>
385396 showToast ( {
386397 title : input . language . t ( "toast.session.share.failed.title" ) ,
0 commit comments