Skip to content

Commit 46b9f13

Browse files
committed
migration path III
1 parent d5d027a commit 46b9f13

File tree

4 files changed

+66
-55
lines changed

4 files changed

+66
-55
lines changed

commands/AddTabToTabsetCommand.ts

Lines changed: 58 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
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

171181
AddTabToTabsetCommand.prototype.toString = function cmdToString() {
172-
return `AddTabToTabsetCommand: {tab=${this.tab.toString()}}`;
173-
};
182+
return `AddTabToTabsetCommand: {tab=${this.tab.toString()}}`
183+
}

pages/SidePanelTabsetPage.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ const saveInTabset = () => {
197197
198198
const startTabsetNote = () => {
199199
const url = chrome && chrome.runtime && chrome.runtime.getURL ?
200-
chrome.runtime.getURL('www/index.html') + "#/mainpanel/notes/?tsId=" + tabsetId + "&edit=true" :
201-
"#/mainpanel/notes/?tsId=" + tabsetId + "&edit=true"
200+
chrome.runtime.getURL('www/index.html') + "#/mainpanel/notes/?tsId=" + (tabsetId?.toString() || '') + "&edit=true" :
201+
"#/mainpanel/notes/?tsId=" + (tabsetId?.toString() || '') + "&edit=true"
202202
NavigationService.openOrCreateTab([url])
203203
}
204204

services/TabsetService2.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ export function useTabsetService() {
9999
selectTabset(tabset.id)
100100
useTabsetService().addToSearchIndex(tabset.id, tabs)
101101
return new SaveOrReplaceResult(false, tabset, false)
102-
} catch (err) {
103-
return Promise.reject("problem updating or creating tabset: " + err)
102+
} catch (err:any) {
103+
return Promise.reject("problem updating or creating tabset: " + err.toString())
104104
}
105105
}
106106

@@ -128,8 +128,8 @@ export function useTabsetService() {
128128
tabset: tabsetCopy,
129129
merged: false
130130
}
131-
} catch (err) {
132-
return Promise.reject("problem copying tabset: " + err)
131+
} catch (err:any) {
132+
return Promise.reject("problem copying tabset: " + err.toString())
133133
}
134134
}
135135

@@ -429,6 +429,7 @@ export function useTabsetService() {
429429
try {
430430
tab.tags.push(new URL(tab.url).hostname.replace("www.", ""))
431431
} catch (err) {
432+
// ignore
432433
}
433434

434435
if (useIndex !== undefined && useIndex >= 0) {

widgets/PanelTabListContextMenu.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<q-icon size="xs" name="o_info" color="accent"/>
1111
</q-item-section>
1212
<q-item-section>
13-
Show Tab Details (dev)
13+
Tab Details (dev)
1414
</q-item-section>
1515
</q-item>
1616
</template>

0 commit comments

Comments
 (0)