Skip to content

Commit

Permalink
improvements overview page etc
Browse files Browse the repository at this point in the history
  • Loading branch information
evandor committed Aug 31, 2024
1 parent ce52d06 commit 2494b9b
Show file tree
Hide file tree
Showing 14 changed files with 220 additions and 357 deletions.
2 changes: 1 addition & 1 deletion src/app/AppEventDispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {RestoreTabsetCommand} from "src/tabsets/commands/RestoreTabset";
class AppEventDispatcher {

dispatchEvent(name: string, params: object) {
console.debug(" >>> dispatching event", name, params)
// console.debug(" >>> dispatching event", name, params)
try {
switch (name) {
case 'add-to-search':
Expand Down
136 changes: 3 additions & 133 deletions src/app/listeners/BrowserListeners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,32 +211,10 @@ class BrowserListeners {
this.inProgress = true
}

createThumbnails(b: boolean) {
console.log("thumbnails active set to ", b)
this.thumbnailsActive = b
}

onCreated(tab: chrome.tabs.Tab) {
// if (!useTabsStore().listenersOn) {
// console.debug(`onCreated: tab ${tab.id}: >>> listeners off, returning <<<`)
// return
// }
this.eventTriggered()
console.debug(`onCreated: tab ${tab.id}: >>> ${tab.pendingUrl}`, tab)
// console.debug(`onCreated: tab ${tab.id}: >>> ${tab.pendingUrl}`, tab)
//sendMsg('window-updated', {initiated: "ChromeListeners#onCreated"})

let foundSession = false
_.forEach([...useTabsetsStore().tabsets.values()] as Tabset[], (ts: Tabset) => {
if (ts.type === TabsetType.SESSION) {
foundSession = true
console.debug("pushing to", ts.id, tab)
ts.tabs.push(new Tab(uid(), tab))
}
})
if (!foundSession) {
console.debug("pushing to pending", tab)
//tabsStore.pendingTabset.tabs.push(new Tab(uid(), tab))
}
}

async onUpdated(number: number, info: chrome.tabs.TabChangeInfo, chromeTab: chrome.tabs.Tab) {
Expand All @@ -252,11 +230,9 @@ class BrowserListeners {

this.eventTriggered()

if (!info.status || (Object.keys(info).length > 1)) {
if (info.status === "complete") {
console.debug(`onUpdated: tab ${number}: >>> ${JSON.stringify(info)} <<<`)

// handle pending Tabset
//this.handleUpdate(tabsStore.pendingTabset as Tabset, chromeTab)
this.handleUpdateInjectScripts(info, chromeTab)

// handle existing tabs
Expand All @@ -277,78 +253,11 @@ class BrowserListeners {
}
}

// handle sessions
let foundSession = false
_.forEach([...useTabsetsStore().tabsets.values()] as Tabset[], (ts: Tabset) => {
if (ts.type === TabsetType.SESSION) {
foundSession = true
this.handleUpdate(ts, chromeTab)
}
})

// matching tabs for url
if (chromeTab.url) {
useTabsetsUiStore().setMatchingTabsFor(chromeTab.url)
}

// handle windowsStore related pages
//sendMsg('window-updated', {initiated: "ChromeListeners#onUpdated"})
}
}

/**
*
* @param tabset: usually the "pendingTabset", or any one which is a session
* @param tab
* @private
*/
private handleUpdate(tabset: Tabset, tab: chrome.tabs.Tab) {
// find tab which was created by "onCreate" moments ago
const index = _.findIndex(tabset?.tabs, t => t.chromeTabId === tab.id);
if (index >= 0) {
const existingPendingTab = tabset.tabs[index]
const updatedTab = new Tab(uid(), tab)

//console.log("updatedTab A", updatedTab)

// (chrome) Group
//console.log("updating updatedTab group for group id", updatedTab.groupId)
updatedTab.groupName = useGroupsStore().currentGroupForId(updatedTab.groupId)?.title || '?' + updatedTab.groupId + '?'
//console.log("group set to", updatedTab.groupName)

updatedTab.setHistoryFrom(existingPendingTab)
if (existingPendingTab.url !== updatedTab.url && existingPendingTab.url !== 'chrome://newtab/') {
if (existingPendingTab.url) {
updatedTab.addToHistory(existingPendingTab.url)
}
}
const urlExistsAlready = _.filter(tabset.tabs, pT => pT.url === tab.url).length >= 2
if (urlExistsAlready) {
tabset.tabs.splice(index, 1);
//console.log("Tabset spliced", tabset.tabs)
} else {
tabset.tabs.splice(index, 1, updatedTab);
//console.log("Tabset spliced and deleted", tabset.tabs)
}

} else {
console.debug(`onUpdated: tab ${tab.id}: pending tab cannot be found in ${tabset.name}`)
if (tab.url !== undefined) {

const newTab = new Tab(uid(), tab)

// (chrome) Group
if (tab.groupId >= 0) {
console.log("updating updatedTab group for group id", tab.groupId)
//newTab.group = useGroupsStore().groupForId(tab.groupId)
//const g = await browser.tabGroups.get(tab.groupId)

newTab.groupName = useGroupsStore().currentGroupForId(tab.groupId)?.title || '???'
}

console.debug(`onUpdated: tab ${tab.id}: missing tab added for url ${tab.url}`)
tabset.tabs.push(newTab)
}
}
}

Expand All @@ -363,46 +272,7 @@ class BrowserListeners {
if (tab.url && tab.url.startsWith("https://shared.tabsets.net")) {
return
}

const scripts: string[] = []

// chrome.scripting.insertCSS({
// target: {tabId: tab.id},
// css: "body { border-top: 2px dotted red; }"
// })
// .then((res) => console.log("res", res))
// .catch((res) => console.log("err", res))

BrowserApi.addIndicatorIcon(tab.id, tab.url)

if (useFeaturesStore().hasFeature(FeatureIdent.ANNOTATIONS)) {
scripts.push("highlight-annotations.js")
}
//scripts.push("tabsets-content-script.js")
if (scripts.length > 0 && tab.id !== null) { // && !this.injectedScripts.get(.chromeTabId)) {

chrome.tabs.get(tab.id, (chromeTab: chrome.tabs.Tab) => {
if (chrome.runtime.lastError) {
console.warn("got runtime error:" + chrome.runtime.lastError);
}
if (tab.id && !tab.url?.startsWith("chrome")) {
scripts.forEach((script: string) => {
//console.debug("executing scripts", tab.id, script)


// @ts-ignore
chrome.scripting.executeScript({
target: {tabId: tab.id || 0, allFrames: false},
files: [script]
}, (callback: any) => {
if (chrome.runtime.lastError) {
console.warn("could not execute script: " + chrome.runtime.lastError.message, info.url);
}
});
})
}
})
}
}

onRemoved(number: number, info: chrome.tabs.TabRemoveInfo) {
Expand Down Expand Up @@ -450,7 +320,7 @@ class BrowserListeners {
}

onHighlighted(info: chrome.tabs.TabHighlightInfo) {
console.debug(`onHighlighted: tab ${info.tabIds} highlighted: ${JSON.stringify(info)}`)
//console.debug(`onHighlighted: tab ${info.tabIds} highlighted: ${JSON.stringify(info)}`)
}

onZoomChange(info: chrome.tabs.ZoomChangeInfo) {
Expand Down
4 changes: 2 additions & 2 deletions src/app/models/AppFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ export class AppFeatures {
'account_tree', '', ['all']),

new Feature(FeatureIdent.NEWEST_TABS, FeatureType.OPTIONAL,
'Newest Tabs',
'A quick access view for your newest tabs',
'Latest Tabs',
'A quick access view for your latest tabs',
'schedule', '', ['all']),

new Feature(FeatureIdent.RESEARCH_SESSIONS, FeatureType.OPTIONAL,
Expand Down
19 changes: 10 additions & 9 deletions src/components/SidePanelFooter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ import {Tabset, TabsetStatus} from "src/tabsets/models/Tabset";
import {ToastType} from "src/core/models/Toast";
import SidePanelFooterLeftButtons from "components/helper/SidePanelFooterLeftButtons.vue";
import {useAuthStore} from "stores/authStore";
import {Account} from "src/models/Account";
import {useNotificationHandler} from "src/core/services/ErrorHandler";
import SidePanelStatsMarkupTable from "components/helper/SidePanelStatsMarkupTable.vue"
import {Window} from "src/windows/models/Window"
Expand Down Expand Up @@ -303,7 +302,7 @@ const additionalActions = (windowName: string) => {
const updateWindows = () => {
useWindowsStore().setup('got window-updated message', true)
useWindowsStore().setup('window-updated', true)
.then(() => windowRows.value = calcWindowRows())
}
Expand All @@ -322,19 +321,21 @@ if (inBexMode()) {
chrome.tabs.onRemoved.addListener((tabId: number, removeInfo: chrome.tabs.TabRemoveInfo) => {
//console.log("***here we are", tabId, removeInfo)
useWindowsStore().setup('got window-updated message')
useWindowsStore().setup('on removed in SidePanelFooter')
.then(() => windowRows.value = calcWindowRows())
.catch((err) => handleError(err))
})
chrome.tabs.onUpdated.addListener((tabId: number, changeInfo: chrome.tabs.TabChangeInfo, tab: chrome.tabs.Tab) => {
useWindowsStore().setup('got window-updated message')
.then(() => windowRows.value = calcWindowRows())
.catch((err) => {
console.log("could not yet calcWindowRows: " + err)
//handleError(err)
})
//console.log(`on updated: ${tabId}, ${JSON.stringify(changeInfo)}`)
if (changeInfo.status === "complete") {
useWindowsStore().setup('on updated in SidePanelFooter')
.then(() => windowRows.value = calcWindowRows())
.catch((err) => {
console.log("could not yet calcWindowRows: " + err)
})
}
})
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/helper/SidePanelFooterLeftButtons.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
label="Newest Tabs"
icon="o_schedule"
:size="buttonSize"
tooltip="Newest Tabs List"/>
tooltip="Latest Tabs List"/>
<SidePanelFooterViewMenuItem :side-panel-view="SidePanelViews.TOP_10_TABS_LIST"
label="Top 10 Tabs"
icon="o_workspace_premium"
Expand Down Expand Up @@ -75,7 +75,7 @@
:side-panel-view="SidePanelViews.NEWEST_TABS_LIST"
:size="props.size"
icon="o_schedule"
tooltip="Newest Tabs List"/>
tooltip="Latest Tabs List"/>

<SidePanelFooterLeftButton
:side-panel-view="SidePanelViews.TABS_AS_TREE"
Expand Down
2 changes: 1 addition & 1 deletion src/models/SidePanelViews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class SidePanelViews {
static readonly RSS_LIST = new SidePanelViews('rssList', '/sidepanel/rsslist',
() => useFeaturesStore().hasFeature(FeatureIdent.RSS));

static readonly NEWEST_TABS_LIST = new SidePanelViews('newestList', '/sidepanel/newestList',
static readonly NEWEST_TABS_LIST = new SidePanelViews('latestList', '/sidepanel/latestList',
() => useFeaturesStore().hasFeature(FeatureIdent.NEWEST_TABS));

static readonly TOP_10_TABS_LIST = new SidePanelViews('top10List', '/sidepanel/top10List',
Expand Down
Loading

0 comments on commit 2494b9b

Please sign in to comment.