Skip to content

Commit

Permalink
TAB-484 savepoint
Browse files Browse the repository at this point in the history
  • Loading branch information
evandor committed Feb 5, 2024
1 parent e8a6fed commit 67cd7ec
Show file tree
Hide file tree
Showing 27 changed files with 551 additions and 376 deletions.
2 changes: 1 addition & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ if (isSignInWithEmailLink(auth, window.location.href)) {
logtail.info("found email link redirection")
})
.catch((error) => {
console.error("error", error)
console.error("error in email link redirection", error)
logtail.error("error in email link redirection", error)
useSuggestionsStore().addSuggestion(Suggestion.getStaticSuggestion(StaticSuggestionIdent.RESTART_SUGGESTED))
});
Expand Down
21 changes: 7 additions & 14 deletions src/components/SidePanelFooter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@

<q-btn
icon="o_grid_view"
data-testid="buttonManageWindows"
:class="rightButtonClass()"
flat
color="black"
Expand Down Expand Up @@ -159,12 +160,12 @@
import {SidePanelView, useUiStore} from "src/stores/uiStore";
import {useTabsStore} from "src/stores/tabsStore";
import {Tab} from "src/models/Tab";
import {onMounted, ref, watch, watchEffect} from "vue";
import {ref, watchEffect} from "vue";
import {useRouter} from "vue-router";
import {usePermissionsStore} from "src/stores/permissionsStore";
import {FeatureIdent} from "src/models/AppFeature";
import NavigationService from "src/services/NavigationService";
import {LocalStorage, openURL, uid, useQuasar} from "quasar";
import {openURL, uid, useQuasar} from "quasar";
import {useUtils} from "src/services/Utils";
import {useWindowsStore} from "src/stores/windowsStore";
import {useSuggestionsStore} from "stores/suggestionsStore";
Expand All @@ -176,10 +177,9 @@ import {ToastType} from "src/models/Toast";
import SidePanelFooterLeftButtons from "components/helper/SidePanelFooterLeftButtons.vue";
import {useAuthStore} from "stores/authStore";
import {Account} from "src/models/Account";
import {NotificationType, useNotificationHandler} from "src/services/ErrorHandler";
import {useNotificationHandler} from "src/services/ErrorHandler";
import SidePanelLoginWidget from "components/helper/SidePanelLoginWidget.vue";
import SidePanelWindowMarkupTable from "components/helper/SidePanelWindowMarkupTable.vue";
//import {Browser} from '@capacitor/browser';
import {Window} from "src/models/Window"
const {handleSuccess, handleError} = useNotificationHandler()
Expand Down Expand Up @@ -207,7 +207,7 @@ const account = ref<Account | undefined>(undefined)
const randomKey = ref<string>(uid())
watchEffect(() => {
const windowId = useWindowsStore().currentWindow?.id || 0
const windowId = useWindowsStore().currentChromeWindow?.id || 0
if (useWindowsStore().windowForId(windowId)?.open) {
//console.log("setting showWindowTable to ", useWindowsStore().windowForId(windowId)?.open)
showWindowTable.value = useWindowsStore().windowForId(windowId)?.open || false
Expand All @@ -218,13 +218,6 @@ watchEffect(() => {
account.value = authStore.getAccount()
})
watchEffect(() => {
if (useWindowsStore().currentWindows.length === 1) {
console.log("setting showWindowTable to false (one window only)")
showWindowTable.value = false
}
})
watchEffect(() => {
const suggestions = useSuggestionsStore().getSuggestions(
[SuggestionState.NEW, SuggestionState.DECISION_DELAYED, SuggestionState.NOTIFICATION])
Expand Down Expand Up @@ -255,7 +248,7 @@ watchEffect(() => {
if (!inBexMode()) {
return
}
const windowId = useWindowsStore().currentWindow?.id || 0
const windowId = useWindowsStore().currentChromeWindow?.id || 0
currentChromeTab.value = useTabsStore().getCurrentChromeTab(windowId) || useTabsStore().currentChromeTab
})
Expand Down Expand Up @@ -360,7 +353,7 @@ const toggleShowWindowTable = () => {
if (showWindowTable.value) {
randomKey.value = uid()
}
const windowId = useWindowsStore().currentWindow?.id || 0
const windowId = useWindowsStore().currentChromeWindow?.id || 0
const currentWindow: Window | undefined = useWindowsStore().windowForId(windowId)
if (currentWindow) {
currentWindow.open = showWindowTable.value
Expand Down
2 changes: 1 addition & 1 deletion src/components/dialogues/helper/NewTabsetDialogBody.vue
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ const createNewTabset = () => {
console.log("createNewTabset", addAllOpenTabs.value, tabsStore.tabs, windowModel.value)
let tabsToUse = addAllOpenTabs.value ? tabsStore.tabs : []
if (props.windowId) {
const window:chrome.windows.Window | undefined = useWindowsStore().currentWindowForId(props.windowId)
const window:chrome.windows.Window | undefined = useWindowsStore().currentChromeWindow(props.windowId)
if (window) {
tabsToUse = window.tabs as chrome.tabs.Tab[]
windowModel.value = newTabsetName.value
Expand Down
90 changes: 45 additions & 45 deletions src/components/helper/SidePanelWindowMarkupTable.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div class="col-12 text-right">
<div class="col-12 text-right bg-grey-1">

<Transition name="bounceInLeft" appear>

Expand Down Expand Up @@ -36,7 +36,7 @@
style="max-height:15px">
<!-- <td>{{ row['index' as keyof object] }}</td>-->
<!-- <td>{{ row['state' as keyof object] }}</td>-->
<td class="text-left" :class="windowNameRowClass(row)" style="cursor:move">
<td class="text-left" :class="windowNameRowClass(row)" style="cursor:move" :data-testid="'windowDataColumn_name_' + row['id' as keyof object]">
{{ row['name' as keyof object] }}
<q-popup-edit v-model="row['name' as keyof object]"
@save="(val:string, initial:string) => setWindowName(row, val)"
Expand All @@ -45,8 +45,9 @@
dense autofocus counter
@keyup.enter="scope.set"/>
</q-popup-edit>
<q-tooltip class="tooltip-small">{{row['hostList' as keyof object]}}</q-tooltip>
</td>
<td>
<td :data-testid="'windowDataColumn_tabsCount_' + row['id' as keyof object]">
{{ row['tabsCount' as keyof object] }}
</td>
<td>
Expand All @@ -59,7 +60,7 @@
</q-icon>
<q-icon name="open_in_new"
class="q-ml-sm cursor-pointer"
:class="useWindowsStore().currentWindow?.id === row['id' as keyof object] ? 'text-grey' : 'text-blue-8 cursor-pointer'"
:class="useWindowsStore().currentChromeWindow?.id === row['id' as keyof object] ? 'text-grey' : 'text-blue-8 cursor-pointer'"
@click="openWindow(row['id' as keyof object])">
<q-tooltip :delay=500 class="tooltip-small">Open this window</q-tooltip>
</q-icon>
Expand Down Expand Up @@ -114,6 +115,9 @@ import TabsetService from "src/services/TabsetService";
import {useSuggestionsStore} from "stores/suggestionsStore";
import MqttService from "src/services/mqtt/MqttService";
import AppService from "src/services/AppService";
import {useNotificationHandler} from "src/services/ErrorHandler";
const {handleSuccess, handleError} = useNotificationHandler()
const $q = useQuasar()
Expand All @@ -124,46 +128,41 @@ const windowsToOpen = ref<string>('')
const windowsToOpenOptions = ref<object[]>([])
const hoveredWindow = ref<number | undefined>(undefined)
const windowsUpdatedListener = (message:any, sender:chrome.runtime.MessageSender, sendResponse:any) => {
if (message.name === 'window-updated') {
console.log("got message 'window-updated'", message)
useWindowsStore().setup('got window-updated message')
.then(() => rows.value = calcWindowRows())
//useUiStore().windowsChanged = message
}
return true
}
onMounted(() => {
rows.value = calcWindowRows()
})
watch(() => useWindowsStore().currentWindows, (newWindows, oldWindows) => {
watch(() => useWindowsStore().currentChromeWindows, (newWindows, oldWindows) => {
console.log("windows changed", newWindows, oldWindows)
rows.value = calcWindowRows()
})
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.name === 'window-updated') {
console.log("got message 'window-updated'", message)
useWindowsStore().setup('got window-updated message')
.then(() => rows.value = calcWindowRows())
//useUiStore().windowsChanged = message
}
return true
//console.log("====>: chrome.runtime.onMessage.hasListeners(windowsUpdatedListener)", chrome.runtime.onMessage.hasListener(windowsUpdatedListener))
chrome.runtime.onMessage.addListener(windowsUpdatedListener)
chrome.tabs.onRemoved.addListener((tabId: number, removeInfo: chrome.tabs.TabRemoveInfo) => {
console.log ("***here we are", tabId, removeInfo)
useWindowsStore().setup('got window-updated message')
.then(() => rows.value = calcWindowRows())
.catch((err) => handleError(err))
})
// watchEffect(() => {
// const windowChangedEvent = useUiStore().windowsChanged
// if (windowChangedEvent) {
// const data = windowChangedEvent['data' as keyof object]
// console.log("ui store: windowsChanged", data)
//
// setTimeout(() => {rows.value = calcWindowRows()}, 1000)
// // const windowId = data['windowId' as keyof object]
// // const title = data['title' as keyof object]
// // const index = data['index' as keyof object]
// //
// // const w = _.find(rows.value, r => r['id' as keyof object] === windowId)
// // if (w) {
// // console.log("found w", w)
// // w['title' as keyof object] = title
// // w['index' as keyof object] = index
// // }
//
// useUiStore().windowsChanged = undefined
// }
// })
chrome.tabs.onCreated.addListener((tab: chrome.tabs.Tab) => {
console.log ("***here we are2", tab)
useWindowsStore().setup('got window-updated message')
.then(() => rows.value = calcWindowRows())
.catch((err) => handleError(err))
})
watchEffect(() => {
// adding potentially new windows from 'open in window' logic
Expand All @@ -172,7 +171,7 @@ watchEffect(() => {
if (ts.window !== "current") {
const found = _.find(rows.value, (r: object) => ts.window === r['name' as keyof object])
if (!found) {
console.log("about to add new window with title", ts.window)
//console.debug (" about to add new window with title", ts.window)
windowsToOpenOptions.value.push({
label: ts.window,
value: ts.id
Expand All @@ -182,10 +181,9 @@ watchEffect(() => {
}
})
watchEffect(() => {
const res = useWindowsStore().currentWindow && useWindowsStore().currentWindow.id ?
useWindowsStore().windowNameFor(useWindowsStore().currentWindow.id || 0) || 'n/a' :
const res = useWindowsStore().currentChromeWindow && useWindowsStore().currentChromeWindow.id ?
useWindowsStore().windowNameFor(useWindowsStore().currentChromeWindow.id || 0) || 'n/a' :
'n/a'
currentWindowName.value = res
})
Expand All @@ -204,7 +202,7 @@ const openNewWindow = (w: object) => {
}
const openWindow = (windowId: number) => {
if (useWindowsStore().currentWindow?.id !== windowId) {
if (useWindowsStore().currentChromeWindow?.id !== windowId) {
chrome.windows.update(windowId, {drawAttention: true, focused: true},
(callback) => {
})
Expand Down Expand Up @@ -233,11 +231,11 @@ const closeWindow = (windowId: number) => {
}
const calcWindowRows = () => {
console.log("calculating window Rows")
const result = _.map(useWindowsStore().currentWindows as chrome.windows.Window[], (cw: chrome.windows.Window) => {
//console.log("calculating window Rows")
const result = _.map(useWindowsStore().currentChromeWindows as chrome.windows.Window[], (cw: chrome.windows.Window) => {
const windowFromStore: Window | undefined = useWindowsStore().windowForId(cw.id || -2)
console.debug(`setting window ${cw.id} ['${windowFromStore?.title}'] (#${cw.tabs?.length} tabs) -> #${windowFromStore?.index}`)
// console.debug(`setting window ${cw.id} ['${windowFromStore?.title}'] (#${cw.tabs?.length} tabs, #${windowFromStore?.hostList.size} hosts) -> #${windowFromStore?.index}`)
return {
id: cw.id,
Expand All @@ -252,7 +250,8 @@ const calcWindowRows = () => {
sessionId: cw.sessionId,
state: cw.state,
type: cw.type,
windowIcon: "*"
windowIcon: "*",
hostList: windowFromStore?.hostList
}
})
Expand All @@ -264,9 +263,10 @@ const setWindowName = (windowRow: object, newName: string) => {
console.log("setWindowName", windowRow, newName)
if (newName && newName.toString().trim().length > 0) {
const id = windowRow['id' as keyof object]
chrome.windows.get(id, (cw) => {
chrome.windows.get(id, {populate: true}, (cw) => {
console.log("cw", cw)
useWindowsStore().upsertWindow(cw, newName.toString().trim(), windowRow['index' as keyof object])
if (useWindowsStore().currentWindow?.id === id) {
if (useWindowsStore().currentChromeWindow?.id === id) {
currentWindowName.value = newName
//console.log("setting window name to ", currentWindowName.value)
useWindowsStore().currentWindowName = newName
Expand Down
14 changes: 7 additions & 7 deletions src/components/helper/SidePanelWindowTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,20 @@ onMounted(() => {
rows.value = calcWindowRows()
})
watch(() => useWindowsStore().currentWindows, (newWindows, oldWindows) => {
watch(() => useWindowsStore().currentChromeWindows, (newWindows, oldWindows) => {
console.log("windows changed", newWindows, oldWindows)
rows.value = calcWindowRows()
})
watchEffect(() => {
const res = useWindowsStore().currentWindow && useWindowsStore().currentWindow.id ?
useWindowsStore().windowNameFor(useWindowsStore().currentWindow.id || 0) || 'n/a' :
useWindowsStore().windowNameFor(useWindowsStore().currentChromeWindow.id || 0) || 'n/a' :
'n/a'
currentWindowName.value = res
})
const openWindow = (windowId: number) => {
if (useWindowsStore().currentWindow?.id !== windowId) {
if (useWindowsStore().currentChromeWindow?.id !== windowId) {
chrome.windows.update(windowId, {drawAttention: true, focused: true},
(callback) => {
})
Expand All @@ -142,7 +142,7 @@ const hideWindow = (windowId: number) => {
}
const restoreWindow = (windowId: number) => {
if (useWindowsStore().currentWindow?.id !== windowId) {
if (useWindowsStore().currentChromeWindow?.id !== windowId) {
chrome.windows.update(windowId, {state: "normal"})
useWindowsStore().refreshCurrentWindows()
}
Expand All @@ -156,7 +156,7 @@ const closeWindow = (windowId: number) => {
const calcWindowRows = () => {
let index = 100
const usedIndices: number[] = []
const result = _.map(useWindowsStore().currentWindows as chrome.windows.Window[], (cw: chrome.windows.Window) => {
const result = _.map(useWindowsStore().currentChromeWindows as chrome.windows.Window[], (cw: chrome.windows.Window) => {
const windowFromStore: Window | undefined = useWindowsStore().windowForId(cw.id || -3)
if (!windowFromStore || !windowFromStore.index) {
console.log("found windowfromstore without index", windowFromStore)
Expand Down Expand Up @@ -195,9 +195,9 @@ const calcWindowRows = () => {
const setWindowName = (windowRow: object, newName: string) => {
if (newName && newName.toString().trim().length > 0) {
const id = windowRow['id' as keyof object]
chrome.windows.get(id, (cw) => {
chrome.windows.get(id, {populate: true}, (cw) => {
useWindowsStore().upsertWindow(cw, newName.toString().trim(), windowRow['index' as keyof object])
if (useWindowsStore().currentWindow?.id === id) {
if (useWindowsStore().currentChromeWindow?.id === id) {
currentWindowName.value = newName
//console.log("setting window name to ", currentWindowName.value)
useWindowsStore().currentWindowName = newName
Expand Down
4 changes: 2 additions & 2 deletions src/models/Window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ export class Window {
public title: string | undefined = undefined,
public index: number = 0,
public open = false,
public hostList: Set<string> = new Set()) {
public hostList: string[] = []) { // could not use sets due to issues

this.created = new Date().getTime()
}

}

Window.prototype.toString = function tabToString() {
return `Window: {id=${this.id}, browserWindow=${this.browserWindow !== undefined}, title=${this.title}, index=${this.index}, open=${this.open}, #hostList=${this.hostList.size}}`;
return `Window: {id=${this.id}, browserWindow=${this.browserWindow !== undefined}, title=${this.title}, index=${this.index}, open=${this.open}, #hostList=${this.hostList.length}}`;
};
8 changes: 3 additions & 5 deletions src/pages/SidePanelPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ watchEffect(() => {
})
watchEffect(() => {
const windowId = useWindowsStore().currentWindow?.id || 0
const windowId = useWindowsStore().currentChromeWindow?.id || 0
currentChromeTab.value = useTabsStore().getCurrentChromeTab(windowId) || useTabsStore().currentChromeTab
})
Expand Down Expand Up @@ -616,6 +616,7 @@ function inIgnoredMessages(message: any) {
return message.msg === "html2text" ||
message.msg === "captureThumbnail" ||
message.msg === "capture-annotation" ||
message.name === "window-updated" ||
message.msg === "html2links"
}
Expand Down Expand Up @@ -720,10 +721,6 @@ if ($q.platform.is.chrome) {
// } else {
// chrome.tabs.sendMessage(message.data.tabId, "cs-iframe-open")
// }
} else if (message.name === 'window-updated') {
console.log("got message 'window-updated'!", message)
//useWindowsStore().setup('got window-updated message')
//useUiStore().windowsChanged = message
} else if (message.name === 'mqtt-url-changed') {
console.log("got message 'mqtt-url-changed'", message)
MqttService.reset().then(() => MqttService.init(message.data.mqttUrl))
Expand Down Expand Up @@ -862,6 +859,7 @@ const showAddTabButton = (tabset: Tabset, currentChromeTab: chrome.tabs.Tab) =>
currentChromeTab.url !== 'chrome://newtab/' &&
currentChromeTab.url.indexOf('/www/index.html#/mainpanel/notes/') < 0 &&
currentChromeTab.url !== '' &&
currentChromeTab.url.indexOf('https://tabsets.web.app/?apiKey=') < 0 &&
tabsStore.currentTabsetId === tabset.id
//isCurrentTab()
}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/SidePanelSpacesPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ watchEffect(() => {
watchEffect(() => {
//currentChromeTab.value = useTabsStore().currentChromeTab
const windowId = useWindowsStore().currentWindow?.id || 0
const windowId = useWindowsStore().currentChromeWindow?.id || 0
currentChromeTab.value = useTabsStore().getCurrentChromeTab(windowId) || useTabsStore().currentChromeTab
})
Expand Down
Loading

0 comments on commit 67cd7ec

Please sign in to comment.