@@ -462,11 +462,21 @@ async function processShareTargetData() {
462
462
// Determine flow configuration from share data
463
463
const { flowTitle, flowSteps } = determineFlowConfiguration ( shareData ) ;
464
464
465
- // Create or navigate to the flow
466
- const targetFlow = await createOrNavigateToFlow ( flowTitle , flowSteps ) ;
467
-
468
- // Load and process the shared images
469
- await loadAndProcessSharedImages ( shareCache , shareData ) ;
465
+ // If no valid command was found, create an empty flow
466
+ if ( flowTitle === null || flowSteps === null ) {
467
+ console . log ( 'Creating empty flow due to invalid URL command' ) ;
468
+ // Create a new untitled flow with no steps
469
+ const newFlow = await createNewFlow ( 'Untitled flow' , [ ] ) ;
470
+
471
+ // Load the images without auto-processing
472
+ await loadAndProcessSharedImages ( shareCache , shareData , false ) ;
473
+ } else {
474
+ // Create or navigate to the flow with the specified steps
475
+ const targetFlow = await createOrNavigateToFlow ( flowTitle , flowSteps ) ;
476
+
477
+ // Load and process the shared images
478
+ await loadAndProcessSharedImages ( shareCache , shareData , true ) ;
479
+ }
470
480
471
481
// Clean up cache after processing
472
482
await cleanupShareCache ( shareCache , shareData ) ;
@@ -480,14 +490,9 @@ async function processShareTargetData() {
480
490
481
491
// Determines the flow configuration (title and steps) based on shared data
482
492
function determineFlowConfiguration ( shareData ) {
483
- // Default flow title and steps
493
+ // Default flow title and steps - only used if no URL is provided
484
494
let flowTitle = shareData . title || 'Shared Images Flow' ;
485
- let flowSteps = [
486
- {
487
- type : 'resize-width-if-larger' ,
488
- params : [ 1000 ]
489
- }
490
- ] ;
495
+ let flowSteps = null ;
491
496
492
497
// If URL field exists and starts with web+wami://, use it for configuration
493
498
if ( shareData . url && shareData . url . trim ( ) !== '' ) {
@@ -499,10 +504,24 @@ function determineFlowConfiguration(shareData) {
499
504
if ( result ) {
500
505
flowTitle = result . title ;
501
506
flowSteps = result . steps ;
507
+ } else {
508
+ // If URL parsing failed, return null to indicate we should stay on launch page
509
+ console . log ( 'Invalid command URL, will not process images' ) ;
510
+ return { flowTitle : null , flowSteps : null } ;
502
511
}
503
512
}
504
513
}
505
514
515
+ // If no web+wami URL was provided, use these default steps
516
+ if ( flowSteps === null ) {
517
+ flowSteps = [
518
+ {
519
+ type : 'resize-width-if-larger' ,
520
+ params : [ 1000 ]
521
+ }
522
+ ] ;
523
+ }
524
+
506
525
return { flowTitle, flowSteps } ;
507
526
}
508
527
@@ -549,8 +568,9 @@ function parseWebWamiUrl(url) {
549
568
console . log ( `Creating resize flow with width ${ width } ` ) ;
550
569
steps = [ { type : 'resize-width-if-larger' , params : [ width ] } ] ;
551
570
} else {
552
- // Default to resize-width-if-larger
553
- steps = [ { type : 'resize-width-if-larger' , params : [ 1000 ] } ] ;
571
+ // If no recognized command is found, return null instead of using default steps
572
+ console . log ( `No recognized command found in URL: ${ mainCommand } ` ) ;
573
+ return null ;
554
574
}
555
575
556
576
return { title, steps } ;
@@ -598,7 +618,7 @@ async function createOrNavigateToFlow(flowTitle, flowSteps) {
598
618
}
599
619
600
620
// Loads shared images from the cache and processes them if needed
601
- async function loadAndProcessSharedImages ( shareCache , shareData ) {
621
+ async function loadAndProcessSharedImages ( shareCache , shareData , shouldAutoProcess = true ) {
602
622
const imagesToStore = [ ] ;
603
623
604
624
// Load the shared files from cache
@@ -637,13 +657,14 @@ async function loadAndProcessSharedImages(shareCache, shareData) {
637
657
return { src : URL . createObjectURL ( image . file ) , name : image . file . name } ;
638
658
} ) ) ;
639
659
640
- // Automatically run the flow
641
- const shouldAutoProcess = true ;
660
+ // Automatically run the flow only if requested
642
661
if ( shouldAutoProcess ) {
643
662
console . log ( 'Auto-processing images...' ) ;
644
663
setTimeout ( ( ) => {
645
664
runFlowButton . click ( ) ;
646
665
} , 500 ) ;
666
+ } else {
667
+ console . log ( 'Images loaded but not auto-processing due to invalid command' ) ;
647
668
}
648
669
}
649
670
}
0 commit comments