Skip to content

Commit

Permalink
cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
evandor committed Sep 28, 2024
1 parent 04bf1b5 commit d261600
Show file tree
Hide file tree
Showing 15 changed files with 90 additions and 103 deletions.
6 changes: 1 addition & 5 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,10 @@ import {useAppStore} from "stores/appStore";
const $q = useQuasar()
const router = useRouter()
const route = useRoute()
const {handleError} = useNotificationHandler()
const settingsStore = useSettingsStore()
settingsStore.initialize($q.localStorage)
//const localMode = settingsStore.isEnabled('localMode')
//console.log(` ...config: localMode=${localMode}`)
console.log("")
useAppStore().init()
Expand Down
28 changes: 16 additions & 12 deletions src/app/AppService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class AppService {

async init(quasar: any, router: Router, forceRestart = false) {

console.log(`%cinitializing AppService: first start=${!this.initialized}, forceRestart=${forceRestart}, quasar set=${quasar !== undefined}, router set=${router !== undefined}`, forceRestart ? "font-weight:bold" : "")
console.log(`%cinitializing AppService: first start=${!this.initialized}, forceRestart=${forceRestart}, router set=${router !== undefined}`,"font-weight:bold")

if (this.initialized && !forceRestart) {
console.debug("stopping AppService initialization; already initialized and not forcing restart")
Expand All @@ -61,37 +61,39 @@ class AppService {

useAppStore().init()

// init of stores and some listeners
// await usePermissionsStore().initialize(useDB(quasar).localDb)


await ChromeListeners.initListeners()
console.debug('')

// Bookmarks
ChromeBookmarkListeners.initListeners()
await useBookmarksStore().init()

useBookmarksStore().init()
await BookmarksService.init()
console.debug('')

//settingsStore.initialize(quasar.localStorage);

// Snapshots
await useSnapshotsStore().initialize(useDB().snapshotsDb)
await useSnapshotsService().init()
console.debug('')

// should be initialized before search submodule
await useThumbnailsService().init(useDB().thumbnailsDb)
console.debug('')

await useContentService().init(IndexedDbContentPersistence)
console.debug('')

await useSearchStore().init().catch((err:any) => console.error(err))
console.debug('')

// init db
await IndexedDbPersistenceService.init("db")
console.log("")

// init services
await useNotificationsStore().initialize(useDB(undefined).db)
console.log("")

await useSuggestionsStore().init()
console.debug('')

Expand Down Expand Up @@ -125,17 +127,19 @@ class AppService {

console.log(`%cinitializing AppService: initCoreSerivces`, "font-weight:bold")

// if (useFeaturesStore().hasFeature(FeatureIdent.WINDOWS_MANAGEMENT)) {
await useWindowsStore().initialize()
useWindowsStore().initListeners()
// }
await useWindowsStore().initialize()
console.debug("")

useWindowsStore().initListeners()
console.debug("")

/**
* features store: passing storage for better testing.
* make sure features are not used before this line in code.
*/
const featuresStorage = useDB(quasar).featuresDb
await useFeaturesStore().initialize(featuresStorage)
console.debug("")

await useNotesStore().initialize(useDB().notesDb)
console.debug('')
Expand Down
30 changes: 14 additions & 16 deletions src/app/BrowserApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ function runHousekeeping() {

console.log("housekeeping now...")

persistenceService.cleanUpTabsets()

persistenceService.cleanUpRequests()

persistenceService.cleanUpMetaLinks()
Expand Down Expand Up @@ -104,10 +102,10 @@ class BrowserApi {
return
}
if (chrome && chrome.contextMenus) {
console.log("chrome.contextMenus", chrome.contextMenus)
//console.log("chrome.contextMenus", chrome.contextMenus)
chrome.contextMenus.removeAll(
() => {
console.debug("creating contextmenu for tabset_extension")
console.debug(" ...creating contextmenu for tabset_extension")
chrome.contextMenus.create({
id: 'tabset_extension',
title: 'Tabsets Extension',
Expand Down Expand Up @@ -140,7 +138,7 @@ class BrowserApi {
// contexts: ['all']
// })
//}
console.debug(" > context menu: save_to_currentTS")
// console.debug(" > context menu: save_to_currentTS")
chrome.contextMenus.create({
id: 'save_to_currentTS',
parentId: 'tabset_extension',
Expand All @@ -162,17 +160,17 @@ class BrowserApi {
// rest of logic in windowsStore
}

if (useFeaturesStore().hasFeature(FeatureIdent.ANNOTATIONS)) {
console.debug(" > context menu: annotate_website")
chrome.contextMenus.create({
id: 'annotate_website',
parentId: 'tabset_extension',
title: 'Annotate',
documentUrlPatterns: ['https://*/*', 'https://*/'],
contexts: ['all']
})
}
console.debug(` > context menu: save_as_tabset for ${useTabsetsStore().tabsets.size} tabset(s)`)
// if (useFeaturesStore().hasFeature(FeatureIdent.ANNOTATIONS)) {
// console.debug(" > context menu: annotate_website")
// chrome.contextMenus.create({
// id: 'annotate_website',
// parentId: 'tabset_extension',
// title: 'Annotate',
// documentUrlPatterns: ['https://*/*', 'https://*/'],
// contexts: ['all']
// })
// }
//console.debug(` > context menu: save_as_tabset for ${useTabsetsStore().tabsets.size} tabset(s)`)
const allTabsets = [...useTabsetsStore().tabsets.values()] as Tabset[]

if (allTabsets.length > 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/bookmarks
2 changes: 1 addition & 1 deletion src/core
2 changes: 1 addition & 1 deletion src/features
4 changes: 2 additions & 2 deletions src/pages/helper/FeatureToggleSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@
import {ref, watchEffect} from "vue";
import {useSettingsStore} from "stores/settingsStore";
import {useCommandExecutor} from "src/core/services/CommandExecutor";
import {ActivateFeatureCommand} from "src/features/commands/ActivateFeature";
import {ActivateFeatureCommand} from "src/features/commands/ActivateFeatureCommand";
import {FeatureIdent} from "src/app/models/FeatureIdent";
import {DeactivateFeatureCommand} from "src/features/commands/DeactivateFeature";
import {DeactivateFeatureCommand} from "src/features/commands/DeactivateFeatureCommand";
import {useFeaturesStore} from "src/features/stores/featuresStore";
import {useNotificationHandler} from "src/core/services/ErrorHandler";
import {
Expand Down
44 changes: 15 additions & 29 deletions src/pages/sidepanel/WelcomePage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ const router = useRouter()
const tabsetName = ref('')
const tabsetNameRef = ref<HTMLElement>(null as unknown as HTMLInputElement)
const windowLocation = ref('---')
const activateNotifications = ref(false)
const activateFullPageApp = ref(false)
const login = ref(false)
Expand All @@ -99,32 +97,20 @@ onMounted(() => {
LocalStorage.set(TITLE_IDENT, 'Tabsets' + stageIdentifier())
})
watchEffect(async () => {
const feature = new AppFeatures().getFeature(FeatureIdent.NOTIFICATIONS)
// if (activateNotifications.value && feature) {
// const res = await useCommandExecutor().execute(new GrantPermissionCommand('notifications'))
// if (!res.result) {
// activateNotifications.value = false
// }
// } else if (!activateNotifications.value && feature) {
// useFeaturesStore().deactivateFeature('notifications')
// }
})
function setFeature(featureIdent: FeatureIdent, val: UnwrapRef<boolean>) {
const feature = new AppFeatures().getFeature(featureIdent)
if (val && feature) {
console.log("activating", featureIdent)
useFeaturesStore().activateFeature(featureIdent.toLowerCase())
} else if (!val && feature) {
console.log("deactivateing", featureIdent)
useFeaturesStore().deactivateFeature(featureIdent.toLowerCase())
}
}
watchEffect(async () => {
setFeature(FeatureIdent.STANDALONE_APP, activateFullPageApp.value)
})
// function setFeature(featureIdent: FeatureIdent, val: UnwrapRef<boolean>) {
// const feature = new AppFeatures().getFeature(featureIdent)
// if (val && feature) {
// console.log("activating", featureIdent)
// useFeaturesStore().activateFeature(featureIdent.toLowerCase())
// } else if (!val && feature) {
// console.log("deactivateing", featureIdent)
// useFeaturesStore().deactivateFeature(featureIdent.toLowerCase())
// }
// }
// watchEffect(async () => {
// setFeature(FeatureIdent.STANDALONE_APP, activateFullPageApp.value)
// })
watchEffect(() => {
useUiStore().showLoginTable = login.value
Expand All @@ -142,7 +128,7 @@ watchEffect(() => {
const addFirstTabset = () => {
useCommandExecutor()
.executeFromUi(new CreateTabsetCommand(tabsetName.value, []))
.then((res) => {
.then((res:any) => {
useUiStore().sidePanelSetActiveView(SidePanelViews.MAIN)
router.push("/sidepanel?first=true")
})
Expand Down
3 changes: 2 additions & 1 deletion src/services/ChromeBookmarkListeners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class ChromeBookmarkListeners {
{permissions: ["bookmarks"]},
(res: boolean) => {
if (res) {
console.debug(" ...init chrome bookmark listeners")
console.debug(" ...init chrome bookmark listeners (async)")
console.debug("")
chrome.bookmarks.onCreated.addListener(this.onCreatedListener)
chrome.bookmarks.onMoved.addListener(this.onMovedListener)
chrome.bookmarks.onRemoved.addListener(this.onRemovedListener)
Expand Down
61 changes: 31 additions & 30 deletions src/services/IndexedDbPersistenceService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {IDBPDatabase, openDB, deleteDB} from "idb";
import _ from "lodash";
import {EXPIRE_DATA_PERIOD_IN_MINUTES, INDEX_DB_VERSION} from "boot/constants";
import PersistenceService from "src/services/PersistenceService";
import {Tabset, TabsetStatus} from "src/tabsets/models/Tabset";
import {MetaLink} from "src/models/MetaLink";
import {uid} from "quasar";
import {Notification, NotificationStatus} from "src/models/Notification";
Expand All @@ -12,6 +11,7 @@ import {RequestInfo} from "src/models/RequestInfo";
import {useSuggestionsStore} from "src/suggestions/stores/suggestionsStore";
import {useTabsetsStore} from "src/tabsets/stores/tabsetsStore";

// Deprecated
class IndexedDbPersistenceService implements PersistenceService {
private db: IDBPDatabase = null as unknown as IDBPDatabase

Expand All @@ -20,28 +20,29 @@ class IndexedDbPersistenceService implements PersistenceService {
}

async init(dbName: string) {
console.debug(" ...initializing indexeddb database", dbName)
// console.debug(" ...initializing indexeddb database", dbName)
this.db = await this.initDatabase(dbName)
useUiStore().dbReady = true
}

async loadTabsets(): Promise<any> {
console.debug(" ...loading tabsets indexeddb")
return await this.db.getAll('tabsets')
.then((res: any) => res.forEach((r: Tabset) => {
// make sure some fields are correctly initialized even for old(er) tabsets
if (!r.columns) {
r.columns = []
}
delete r['groups' as keyof object]
//console.log("r", ['groups' as keyof object])
useTabsetsStore().addTabset(r)
}))
}

async saveTabset(tabset: Tabset): Promise<IDBValidKey> {
return await this.db.put('tabsets', JSON.parse(JSON.stringify(tabset)), tabset.id);
}
// async loadTabsets(): Promise<any> {
// debugger
// console.debug(" ...loading tabsets indexeddb")
// return await this.db.getAll('tabsets')
// .then((res: any) => res.forEach((r: Tabset) => {
// // make sure some fields are correctly initialized even for old(er) tabsets
// if (!r.columns) {
// r.columns = []
// }
// delete r['groups' as keyof object]
// //console.log("r", ['groups' as keyof object])
// useTabsetsStore().addTabset(r)
// }))
// }
//
// async saveTabset(tabset: Tabset): Promise<IDBValidKey> {
// return await this.db.put('tabsets', JSON.parse(JSON.stringify(tabset)), tabset.id);
// }

saveRequest(url: string, requestInfo: RequestInfo): Promise<void> {
const encodedTabUrl = btoa(url)
Expand Down Expand Up @@ -124,17 +125,17 @@ class IndexedDbPersistenceService implements PersistenceService {
return this.db.get('links', encodedUrl)
}

async cleanUpTabsets(): Promise<void> {
const objectStore = this.db.transaction("tabsets", "readwrite").objectStore("tabsets");
let cursor = await objectStore.openCursor()
while (cursor) {
if (cursor.value.status === TabsetStatus.DELETED) {
console.log("cleanup: deleteing stale tabset", cursor.key)
objectStore.delete(cursor.key)
}
cursor = await cursor.continue();
}
}
// async cleanUpTabsets(): Promise<void> {
// const objectStore = this.db.transaction("tabsets", "readwrite").objectStore("tabsets");
// let cursor = await objectStore.openCursor()
// while (cursor) {
// if (cursor.value.status === TabsetStatus.DELETED) {
// console.log("cleanup: deleteing stale tabset", cursor.key)
// objectStore.delete(cursor.key)
// }
// cursor = await cursor.continue();
// }
// }


async cleanUpRequests(): Promise<void> {
Expand Down
1 change: 1 addition & 0 deletions src/services/PersistenceService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {Notification} from "src/models/Notification";
import {MetaLink} from "src/models/MetaLink";
import {RequestInfo} from "src/models/RequestInfo";

// Deprecated
interface PersistenceService {

getServiceName(): string
Expand Down
2 changes: 1 addition & 1 deletion src/stores/settingsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const useSettingsStore = defineStore('settings', () => {
watch(thumbnailQuality, (val: Object) => localStorage.set("thumbnailQuality", val))

function initialize(localStorage: any) {
console.debug(" ...initializing settingsStore")
console.debug(" ...initializing settingsStore", '✅')
const fts: string | undefined = localStorage.getItem("settings")
if (fts) {
console.debug(` ...determining activeToggles from '${fts}'`)
Expand Down
2 changes: 1 addition & 1 deletion src/tabsets
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {createPinia, setActivePinia} from "pinia";
import IndexedDbPersistenceService from "src/services/IndexedDbPersistenceService";
import {useFeaturesStore} from "src/features/stores/featuresStore";
import InMemoryFeaturesPersistence from "src/features/persistence/InMemoryFeaturesPersistence";
import {ActivateFeatureCommand} from "src/features/commands/ActivateFeature";
import {ActivateFeatureCommand} from "src/features/commands/ActivateFeatureCommand";
import {AppFeatures} from "src/app/models/AppFeatures";
import {Feature} from "src/features/models/Feature";
import {FeatureIdent} from "src/app/models/FeatureIdent";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import {createPinia, setActivePinia} from "pinia";
import IndexedDbPersistenceService from "src/services/IndexedDbPersistenceService";
import {useFeaturesStore} from "src/features/stores/featuresStore";
import InMemoryFeaturesPersistence from "src/features/persistence/InMemoryFeaturesPersistence";
import {ActivateFeatureCommand} from "src/features/commands/ActivateFeature";
import {ActivateFeatureCommand} from "src/features/commands/ActivateFeatureCommand";
import {AppFeatures} from "src/app/models/AppFeatures";
import {DeactivateFeatureCommand} from "src/features/commands/DeactivateFeature";
import {DeactivateFeatureCommand} from "src/features/commands/DeactivateFeatureCommand";
import {Feature} from "src/features/models/Feature";
import {FeatureIdent} from "src/app/models/FeatureIdent";

Expand Down

0 comments on commit d261600

Please sign in to comment.