1- import Command from " src/core/domain/Command" ;
2- import { ExecutionResult } from " src/core/domain/ExecutionResult" ;
3- import { Tab } from " src/tabsets/models/Tab" ;
4- import _ from " lodash" ;
5- import { useTabsetService } from " src/tabsets/services/TabsetService2" ;
6- import { Tabset , TabsetSharing } from " src/tabsets/models/Tabset" ;
7- import { useUtils } from " src/core/services/Utils" ;
8- import { useGroupsStore } from " src/tabsets/stores/groupsStore" ;
9- import PlaceholderUtils from " src/tabsets/utils/PlaceholderUtils" ;
10- import AppEventDispatcher from " src/app/AppEventDispatcher" ;
11- import { useTabsetsStore } from " src/tabsets/stores/tabsetsStore" ;
12- import ContentUtils from " src/core/utils/ContentUtils" ;
13- import BrowserApi from " src/app/BrowserApi" ;
14- import { useThumbnailsService } from " src/thumbnails/services/ThumbnailsService" ;
15- import { useLogger } from " src/services/Logger" ;
16- import { useContentStore } from " src/content/stores/contentStore" ;
17- import { TabReference , TabReferenceType } from " src/content/models/TabReference" ;
18- import { uid } from " quasar" ;
19- import { useFeaturesStore } from " src/features/stores/featuresStore" ;
20- import { FeatureIdent } from " src/app/models/FeatureIdent" ;
21- import { useRequestsStore } from " src/requests/stores/requestsStore" ;
22- import { useRequestsService } from " src/requests/services/RequestsService" ;
23-
24- const { sendMsg} = useUtils ( )
25- const { info} = useLogger ( )
1+ import Command from ' src/core/domain/Command'
2+ import { ExecutionResult } from ' src/core/domain/ExecutionResult'
3+ import { Tab } from ' src/tabsets/models/Tab'
4+ import _ from ' lodash'
5+ import { useTabsetService } from ' src/tabsets/services/TabsetService2'
6+ import { Tabset , TabsetSharing } from ' src/tabsets/models/Tabset'
7+ import { useUtils } from ' src/core/services/Utils'
8+ import { useGroupsStore } from ' src/tabsets/stores/groupsStore'
9+ import PlaceholderUtils from ' src/tabsets/utils/PlaceholderUtils'
10+ import AppEventDispatcher from ' src/app/AppEventDispatcher'
11+ import { useTabsetsStore } from ' src/tabsets/stores/tabsetsStore'
12+ import ContentUtils from ' src/core/utils/ContentUtils'
13+ import BrowserApi from ' src/app/BrowserApi'
14+ import { useThumbnailsService } from ' src/thumbnails/services/ThumbnailsService'
15+ import { useLogger } from ' src/services/Logger'
16+ import { useContentStore } from ' src/content/stores/contentStore'
17+ import { TabReference , TabReferenceType } from ' src/content/models/TabReference'
18+ import { uid } from ' quasar'
19+ import { useFeaturesStore } from ' src/features/stores/featuresStore'
20+ import { FeatureIdent } from ' src/app/models/FeatureIdent'
21+ import { useRequestsStore } from ' src/requests/stores/requestsStore'
22+ import { useRequestsService } from ' src/requests/services/RequestsService'
23+
24+ const { sendMsg } = useUtils ( )
25+ const { info } = useLogger ( )
2626
2727// No undo command, tab can be deleted manually easily
2828
@@ -43,7 +43,7 @@ export class AddTabToTabsetCommand implements Command<any> {
4343 this . tabset = useTabsetsStore ( ) . getCurrentTabset
4444 }
4545 if ( ! this . tabset ) {
46- throw new Error ( " could not set current tabset" )
46+ throw new Error ( ' could not set current tabset' )
4747 }
4848 }
4949
@@ -61,17 +61,17 @@ export class AddTabToTabsetCommand implements Command<any> {
6161
6262 if ( ! this . allowDuplicates ) {
6363 const exists = _ . findIndex ( tabsetOrFolder . tabs , ( t : any ) => t . url === this . tab . url ) >= 0
64- console . debug ( " checking 'tab exists' yields" , exists )
64+ console . debug ( ' checking \ 'tab exists\ ' yields' , exists )
6565 if ( exists && ! this . ignoreDuplicates ) {
66- return Promise . reject ( " tab already exists in this tabset" )
66+ return Promise . reject ( ' tab already exists in this tabset' )
6767 } else if ( exists ) {
68- return Promise . resolve ( new ExecutionResult ( "" , "" ) )
68+ return Promise . resolve ( new ExecutionResult ( '' , '' ) )
6969 }
7070 }
7171
7272 try {
7373 // manage (chrome) Group
74- console . log ( " updating tab group for group id" , this . tab . groupId )
74+ console . log ( ' updating tab group for group id' , this . tab . groupId )
7575 const currentGroup = useGroupsStore ( ) . currentGroupForId ( this . tab . groupId )
7676 this . tab . groupName = currentGroup ?. title || undefined
7777 if ( currentGroup ) {
@@ -86,7 +86,7 @@ export class AddTabToTabsetCommand implements Command<any> {
8686 const article = useContentStore ( ) . currentTabArticle
8787 if ( article && article [ 'title' as keyof object ] &&
8888 article [ 'textContent' as keyof object ] ) {
89- const content :string = article [ 'textContent' as keyof object ]
89+ const content : string = article [ 'textContent' as keyof object ]
9090 if ( content . length > 500 ) {
9191 this . tab . tabReferences . push ( new TabReference ( uid ( ) , TabReferenceType . READING_MODE , article [ 'title' as keyof object ] , [ article ] , this . tab . url ) )
9292 //this.tab.url = chrome.runtime.getURL(`/www/index.html#/mainpanel/readingmode/${this.tab.id}`)
@@ -113,24 +113,34 @@ export class AddTabToTabsetCommand implements Command<any> {
113113 let content : any = undefined
114114 if ( this . tab . chromeTabId ) {
115115 // saving content excerpt and meta data
116- try {
117- const contentResult = await chrome . tabs . sendMessage ( this . tab . chromeTabId , 'getExcerpt' )
118- const tokens = ContentUtils . html2tokens ( contentResult . html )
116+ // try {
117+ // const contentResult = await chrome.tabs.sendMessage(this.tab.chromeTabId, 'getExcerpt')
118+ // const tokens = ContentUtils.html2tokens(contentResult.html)
119+ // content = [...tokens].join(" ")
120+ // await useTabsetService().saveText(this.tab, content, contentResult.metas)
121+ // } catch (err) {
122+ // console.warn("got error when saving content and metadata:", err, this.tab?.url)
123+ // }
124+
125+ const tabContent = useContentStore ( ) . getCurrentTabContent
126+ const tabMetas = useContentStore ( ) . getCurrentTabMetas
127+ if ( tabContent ) {
128+ const tokens = ContentUtils . html2tokens ( tabContent )
119129 content = [ ...tokens ] . join ( " " )
120- await useTabsetService ( ) . saveText ( this . tab , content , contentResult . metas )
121- } catch ( err ) {
122- console . warn ( "got error when saving content and metadata:" , err , this . tab ?. url )
130+ await useTabsetService ( ) . saveText ( this . tab , content , tabMetas )
123131 }
132+
133+
124134 //res = new ExecutionResult("result", "Link was added")
125135 const res2 = await useTabsetService ( ) . saveTabset ( this . tabset ! )
126- res = new ExecutionResult ( res2 , " Link was added" )
136+ res = new ExecutionResult ( res2 , ' Link was added' )
127137
128138 // saving thumbnail
129139 useThumbnailsService ( ) . captureVisibleTab ( this . tab . id )
130140
131141 } else {
132142 const res2 = await useTabsetService ( ) . saveTabset ( this . tabset ! )
133- res = new ExecutionResult ( res2 , " Link was added" )
143+ res = new ExecutionResult ( res2 , ' Link was added' )
134144
135145 }
136146
@@ -149,25 +159,25 @@ export class AddTabToTabsetCommand implements Command<any> {
149159 tabsets : [ this . tabset ! . id ] ,
150160 favIconUrl : this . tab . favIconUrl || ''
151161 } )
152- info ( " tab created" )
153- localStorage . setItem ( " test.tabId" , this . tab . id )
154- sendMsg ( 'tab-added' , { tabsetId : this . tabset ! . id } )
162+ info ( ' tab created' )
163+ localStorage . setItem ( ' test.tabId' , this . tab . id )
164+ sendMsg ( 'tab-added' , { tabsetId : this . tabset ! . id } )
155165
156- const req = useRequestsStore ( ) . getCurrentTabRequest
166+ const req = useRequestsStore ( ) . getCurrentTabRequest
157167 if ( req && req . url === this . tab . url ) {
158168 useRequestsService ( ) . logWebRequest ( JSON . parse ( JSON . stringify ( req ) ) )
159169 }
160170
161171 return res
162- } catch ( err ) {
163- console . warn ( " hier: " , err )
164- return Promise . reject ( " error: " + err )
172+ } catch ( err : any ) {
173+ console . warn ( ' hier: ' , err )
174+ return Promise . reject ( ' error: ' + err . toString ( ) )
165175 }
166176 }
167177
168178
169179}
170180
171181AddTabToTabsetCommand . prototype . toString = function cmdToString ( ) {
172- return `AddTabToTabsetCommand: {tab=${ this . tab . toString ( ) } }` ;
173- } ;
182+ return `AddTabToTabsetCommand: {tab=${ this . tab . toString ( ) } }`
183+ }
0 commit comments