@@ -132,14 +132,47 @@ function getInstanceJs(parentClass, addonTriggers, C3) {
132132 /** @type {import('@pipelab/core').MessageEngine['output']['body']['engine'] } */
133133 _engine
134134
135+ /** @type {import('@pipelab/core').FileFolder[] } */
136+ _fileList
137+
135138 /** @type {boolean } */
136139 _isInitialized
137140
141+ /** @type {string } */
142+ _fileError
143+
144+ /** @type {number } */
145+ _fileSize
146+
147+ /** @type {number } */
148+ _windowHeight
149+
150+ /** @type {number } */
151+ _windowWidth
152+
153+ /** @type {string } */
154+ _windowTitle
155+
156+ /** @type {number } */
157+ _windowX
158+
159+ /** @type {number } */
160+ _windowY
161+
138162 constructor ( ) {
139163 super ( ) ;
140164
141165 this . _currentTag = '' ;
142166 this . _isInitialized = false
167+ this . _fileList = [ ] ;
168+
169+ this . _fileError = ""
170+ this . _fileSize = 0
171+ this . _windowHeight = - 1
172+ this . _windowWidth = - 1
173+ this . _windowTitle = ""
174+ this . _windowX = - 1
175+ this . _windowY = - 1
143176
144177 const properties = this . _getInitProperties ( ) ;
145178 if ( properties ) {
@@ -160,26 +193,26 @@ function getInstanceJs(parentClass, addonTriggers, C3) {
160193 */
161194 wrap ( base , callback , fallback , force ) {
162195 return ( ...args ) => {
163- console . log ( 'this._isInitialized' , this . _isInitialized )
196+ // console.log('this._isInitialized', this._isInitialized)
164197 // is initialized
165198 if ( this . _isInitialized ) {
166199 // and is connected to an engine
167- console . log ( 'this.ws?.isConnected' , this . ws ?. isConnected )
200+ // console.log('this.ws?.isConnected', this.ws?.isConnected)
168201 if ( this . ws ?. isConnected ) {
169202 // execute callback
170203 return callback . call ( this , ...args ) ;
171204 } else {
172- console . log ( 'else 1' )
205+ // console.log('else 1')
173206 // do nothing (web, nwjs, unsupported, ...)
174207 return fallback
175208 ? fallback . call ( this , ...args )
176209 : callback . call ( this , ...args ) ;
177210 }
178211 } else if ( force ) {
179- console . log ( 'force' )
212+ // console.log('force')
180213 return callback . call ( this , ...args ) ;
181214 } else {
182- console . log ( 'else 2' )
215+ // console.log('else 2')
183216 return fallback
184217 ? fallback . call ( this , ...args )
185218 : callback . call ( this , ...args ) ;
@@ -453,25 +486,45 @@ function getInstanceJs(parentClass, addonTriggers, C3) {
453486 url : '/dialog/folder' ,
454487 }
455488
456- await this . ws ?. sendAndWaitForResponse ( order )
489+ /** @type {import('@pipelab/core').MakeInputOutput<import('@pipelab/core').MessageShowFolderDialog, 'output'> | undefined } */
490+ const answer = await this . ws ?. sendAndWaitForResponse ( order )
491+ console . log ( 'answer' , answer )
457492
458493 console . log ( 'C3' , C3 )
459494 console . log ( 'this' , this )
460- // this.Trigger(C3.Plugins.xxx.Cnds.OnFolderDialogOk)
495+
496+ if ( ! answer ) {
497+ await this . _triggerAsync ( C3 . Plugins . pipelab . Cnds . OnFolderDialogCancel )
498+ return
499+ }
500+
501+ if ( answer . body . canceled ) {
502+ await this . _triggerAsync ( C3 . Plugins . pipelab . Cnds . OnFolderDialogCancel )
503+ } else {
504+ this . _chosenPath = answer . body . paths [ 0 ]
505+ await this . _triggerAsync ( C3 . Plugins . pipelab . Cnds . OnFolderDialogOk )
506+ }
507+
461508 } , this . unsupportedEngine )
462509
463510 _ShowOpenDialog = this . wrap ( super . _ShowOpenDialog , async ( accept ) => {
511+ console . log ( 'accept' , accept )
464512 /**
465513 * @type {import('@pipelab/core').FileFilter[] }
466514 */
467515 const filters = accept . split ( ',' ) . map ( filter => {
516+ console . log ( 'filter' , filter )
468517 const [ name , extensions ] = filter . split ( '|' )
469- return {
470- name,
471- extensions : extensions . split ( ';' )
518+ if ( name && extensions ) {
519+ return {
520+ name,
521+ extensions : extensions . split ( ';' )
522+ }
472523 }
473524 } )
474525
526+ console . log ( 'filters' , filters )
527+
475528 /** @type {import('@pipelab/core').MakeInputOutput<import('@pipelab/core').MessageShowOpenDialog, 'input'> } */
476529 const order = {
477530 url : '/dialog/open' ,
@@ -480,18 +533,33 @@ function getInstanceJs(parentClass, addonTriggers, C3) {
480533 }
481534 }
482535
483- await this . ws ?. sendAndWaitForResponse ( order )
536+ const answer = await this . ws ?. sendAndWaitForResponse ( order )
537+
538+ if ( ! answer ) {
539+ await this . _triggerAsync ( C3 . Plugins . pipelab . Cnds . OnOpenDialogCancel )
540+ return
541+ }
542+
543+ if ( answer . body . canceled ) {
544+ await this . _triggerAsync ( C3 . Plugins . pipelab . Cnds . OnOpenDialogCancel )
545+ } else {
546+ this . _chosenPath = answer . body . paths [ 0 ]
547+ await this . _triggerAsync ( C3 . Plugins . pipelab . Cnds . OnOpenDialogOk )
548+ }
484549 } , this . unsupportedEngine )
485550
486551 _ShowSaveDialog = this . wrap ( super . _ShowSaveDialog , async ( accept ) => {
487552 /**
488553 * @type {import('@pipelab/core').FileFilter[] }
489554 */
490555 const filters = accept . split ( ',' ) . map ( filter => {
556+ console . log ( 'filter' , filter )
491557 const [ name , extensions ] = filter . split ( '|' )
492- return {
493- name,
494- extensions : extensions . split ( ';' )
558+ if ( name && extensions ) {
559+ return {
560+ name,
561+ extensions : extensions . split ( ';' )
562+ }
495563 }
496564 } )
497565
@@ -503,7 +571,19 @@ function getInstanceJs(parentClass, addonTriggers, C3) {
503571 }
504572 }
505573
506- await this . ws ?. sendAndWaitForResponse ( order )
574+ const answer = await this . ws ?. sendAndWaitForResponse ( order )
575+
576+ if ( ! answer ) {
577+ await this . _triggerAsync ( C3 . Plugins . pipelab . Cnds . OnSaveDialogCancel )
578+ return
579+ }
580+
581+ if ( answer . body . canceled ) {
582+ await this . _triggerAsync ( C3 . Plugins . pipelab . Cnds . OnSaveDialogCancel )
583+ } else {
584+ this . _chosenPath = answer . body . path
585+ await this . _triggerAsync ( C3 . Plugins . pipelab . Cnds . OnSaveDialogOk )
586+ }
507587 } , this . unsupportedEngine )
508588
509589 _AppendFile = this . wrap ( super . _AppendFile , async ( ) => {
@@ -533,8 +613,20 @@ function getInstanceJs(parentClass, addonTriggers, C3) {
533613 throw new Error ( '"_DeleteFile" Not implemented' )
534614 } , this . unsupportedEngine )
535615
536- _ListFiles = this . wrap ( super . _ListFiles , async ( ) => {
537- throw new Error ( '"_ListFiles" Not implemented' )
616+ _ListFiles = this . wrap ( super . _ListFiles , async ( path ) => {
617+ /** @type {import('@pipelab/core').MakeInputOutput<import('@pipelab/core').MessageListFiles, 'input'> } */
618+ const order = {
619+ url : '/fs/list' ,
620+ body : {
621+ path
622+ }
623+ }
624+ const files = await this . ws ?. sendAndWaitForResponse ( order )
625+
626+ if ( files ) {
627+ this . _fileList = files . body . list
628+ console . log ( 'this._fileList' , this . _fileList )
629+ }
538630 } , this . unsupportedEngine )
539631
540632 _MoveFile = this . wrap ( super . _MoveFile , async ( ) => {
@@ -558,6 +650,26 @@ function getInstanceJs(parentClass, addonTriggers, C3) {
558650
559651 const answer = await this . ws ?. sendAndWaitForResponse ( order )
560652 console . log ( 'answer' , answer )
653+
654+ const sdkInst = this . __GetBinaryDataSdkInstance ( destination ) ;
655+
656+ if ( ! sdkInst ) {
657+ throw new Error ( "SDK instance not found" )
658+ }
659+ console . log ( 'sdkInst' , sdkInst )
660+ const newBuffer = new Uint8Array ( answer ?. body . content ?? [ ] )
661+ console . log ( 'newBuffer' , newBuffer )
662+ sdkInst . setArrayBufferCopy ( newBuffer . buffer ) ;
663+ console . log ( "getArrayBufferCopy()" , sdkInst . getArrayBufferCopy ( ) )
664+
665+ console . log ( 'addonTriggers' , addonTriggers )
666+ console . log ( 'this' , this )
667+
668+ this . _currentTag = tag ;
669+ await this . _triggerAsync ( C3 . Plugins . pipelab . Cnds . OnAnyBinaryFileRead )
670+ await this . _triggerAsync ( C3 . Plugins . pipelab . Cnds . OnBinaryFileRead )
671+ this . _currentTag = ''
672+
561673 } , this . unsupportedEngine )
562674
563675 _RenameFile = this . wrap ( super . _RenameFile , async ( ) => {
@@ -658,42 +770,62 @@ function getInstanceJs(parentClass, addonTriggers, C3) {
658770 }
659771 } , this . unsupportedEngine )
660772
773+ _FetchFileSize = this . wrap ( super . _FetchFileSize , async ( path ) => {
774+ /** @type {import('@pipelab/core').MakeInputOutput<import('@pipelab/core').MessageFileSize, 'input'> } */
775+ const order = {
776+ url : '/fs/file/size' ,
777+ body : {
778+ path
779+ }
780+ }
781+
782+ /**
783+ * @type {import('@pipelab/core').MakeInputOutput<import('@pipelab/core').MessageFileSize, 'output'> }
784+ */
785+ const answer = await this . ws ?. sendAndWaitForResponse ( order )
786+ console . log ( 'answer' , answer )
787+ this . _fileSize = answer ?. body . size ?? - 1
788+ } )
789+
661790 // Cnds
662791
663792 _OnFolderDialogCancel = this . wrap ( super . _OnFolderDialogCancel , ( ) => {
664- throw new Error ( '"_OnFolderDialogCancel" Not implemented' )
793+ return true
665794 } , ( ) => false )
666795
667796 _OnFolderDialogOk = this . wrap ( super . _OnFolderDialogOk , ( ) => {
668- throw new Error ( '"_OnFolderDialogOk" Not implemented' )
797+ return true
669798 } , ( ) => false )
670799
671800 _OnOpenDialogCancel = this . wrap ( super . _OnOpenDialogCancel , ( ) => {
672- throw new Error ( '"_OnOpenDialogCancel" Not implemented' )
801+ return true
673802 } , ( ) => false )
674803
675804 _OnOpenDialogOk = this . wrap ( super . _OnOpenDialogOk , ( ) => {
676- throw new Error ( '"_OnOpenDialogOk" Not implemented' )
805+ return true
677806 } , ( ) => false )
678807
679808 _OnSaveDialogCancel = this . wrap ( super . _OnSaveDialogCancel , ( ) => {
680- throw new Error ( '"_OnSaveDialogCancel" Not implemented' )
809+ return true
681810 } , ( ) => false )
682811
683812 _OnSaveDialogOk = this . wrap ( super . _OnSaveDialogOk , ( ) => {
684- throw new Error ( '"_OnSaveDialogOk" Not implemented' )
813+ return true
685814 } , ( ) => false )
686815
687816 _OnAnyBinaryFileRead = this . wrap ( super . _OnAnyBinaryFileRead , ( ) => {
688- throw new Error ( '"_OnAnyBinaryFileRead" Not implemented' )
817+ return true
689818 } , ( ) => false )
690819
691820 _OnAnyBinaryFileWrite = this . wrap ( super . _OnAnyBinaryFileWrite , ( ) => {
692821 throw new Error ( '"_OnAnyBinaryFileWrite" Not implemented' )
693822 } , ( ) => false )
694823
695- _OnBinaryFileRead = this . wrap ( super . _OnBinaryFileRead , ( ) => {
696- throw new Error ( '"_OnBinaryFileRead" Not implemented' )
824+ _OnBinaryFileRead = this . wrap ( super . _OnBinaryFileRead , ( tag ) => {
825+ if ( this . _currentTag === tag ) {
826+ return true
827+ }
828+ return false
697829 } , ( ) => false )
698830
699831 _OnBinaryFileWrite = this . wrap ( super . _OnBinaryFileWrite , ( ) => {
@@ -729,8 +861,7 @@ function getInstanceJs(parentClass, addonTriggers, C3) {
729861 } )
730862
731863 _ChosenPath = this . wrap ( super . _ChosenPath , ( ) => {
732- console . error ( '"_ChosenPath" Not implemented' )
733- return ''
864+ return this . _chosenPath ?? ''
734865 } )
735866
736867 _AppFolder = this . wrap ( super . _AppFolder , ( ) => {
@@ -749,28 +880,23 @@ function getInstanceJs(parentClass, addonTriggers, C3) {
749880 } )
750881
751882 _FileError = this . wrap ( super . _FileError , ( ) => {
752- console . error ( '"_FileError" Not implemented' )
753- return ''
883+ return this . _fileError
754884 } )
755885
756886 _FileSize = this . wrap ( super . _FileSize , ( ) => {
757- console . error ( '"_FileSize" Not implemented' )
758- return - 1
887+ return this . _fileSize
759888 } )
760889
761890 _FileTag = this . wrap ( super . _FileTag , ( ) => {
762- console . error ( '"_FileTag" Not implemented' )
763- return ''
891+ return this . _currentTag ?? ""
764892 } )
765893
766- _ListAt = this . wrap ( super . _ListAt , ( ) => {
767- console . error ( '"_ListAt" Not implemented' )
768- return ''
894+ _ListAt = this . wrap ( super . _ListAt , ( index ) => {
895+ return this . _fileList [ index ] ?. name ?? ''
769896 } )
770897
771898 _ListCount = this . wrap ( super . _ListCount , ( ) => {
772- console . error ( '"_ListCount" Not implemented' )
773- return - 1
899+ return this . _fileList . length
774900 } )
775901
776902 _ProjectFilesFolder = this . wrap ( super . _ProjectFilesFolder , ( ) => {
@@ -788,29 +914,23 @@ function getInstanceJs(parentClass, addonTriggers, C3) {
788914 } )
789915
790916 _WindowHeight = this . wrap ( super . _WindowHeight , ( ) => {
791- console . error ( '"_WindowHeight" Not implemented' )
792- return - 1
917+ return this . _windowHeight
793918 } )
794919
795920 _WindowWidth = this . wrap ( super . _WindowWidth , ( ) => {
796- console . error ( '"_WindowWidth" Not implemented' )
797- return - 1
921+ return this . _windowWidth
798922 } )
799923
800924 _WindowTitle = this . wrap ( super . _WindowTitle , ( ) => {
801- console . error ( '"_WindowTitle" Not implemented' )
802- return ''
925+ return this . _windowTitle
803926 } )
804927
805928 _WindowX = this . wrap ( super . _WindowX , ( ) => {
806- console . error ( '"_WindowX" Not implemented' )
807- return - 1
929+ return this . _windowX
808930 } )
809931
810932 _WindowY = this . wrap ( super . _WindowY , ( ) => {
811- this . _WindowX
812- console . error ( '"this" Not implemented' )
813- return - 1
933+ return this . _windowY
814934 } )
815935
816936 _IsEngine = this . wrap ( super . _IsEngine , ( engine ) => {
0 commit comments