Skip to content

Commit

Permalink
preparing release
Browse files Browse the repository at this point in the history
  • Loading branch information
evandor committed Sep 23, 2024
1 parent ebab7b0 commit a84ca95
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 144 deletions.
59 changes: 30 additions & 29 deletions src/app/AppService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,45 +55,45 @@ class AppService {

this.initialized = true

const appStore = useAppStore()
const settingsStore = useSettingsStore()
const bookmarksStore = useBookmarksStore()
const searchStore = useSearchStore()
const uiStore = useUiStore()

this.router = router

uiStore.appLoading = "loading tabsets..."
useUiStore().appLoading = "loading tabsets..."

appStore.init()
useAppStore().init()

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


await ChromeListeners.initListeners()

// Bookmarks
ChromeBookmarkListeners.initListeners()
await bookmarksStore.init()
await useBookmarksStore().init()
await BookmarksService.init()
console.debug('')

//settingsStore.initialize(quasar.localStorage);

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

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

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

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

// init services
await useNotificationsStore().initialize(useDB(undefined).db)
await useSuggestionsStore().init()
console.debug('')

tabsetService.setLocalStorage(localStorage)

Expand Down Expand Up @@ -122,61 +122,62 @@ class AppService {
}

private async initCoreSerivces(quasar: any, router: Router) {
const groupsStore = useGroupsStore()
const registryStore = useEntityRegistryStore()

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

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

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

await useNotesStore().initialize(useDB().notesDb)
console.debug('')

/**
* windows store
*/
await useWindowsStore().initialize()
useWindowsStore().initListeners()

/**
* Pattern: TODO
* initialize store with optional registry watcher and persistence
* run persistence init code in store init
* no persistence for service!
*/

const spacesStore = useSpacesStore()
watch(spacesStore.spaces, (newSpaces:Map<string,any>) => {
watch(useSpacesStore().spaces, (newSpaces:Map<string,any>) => {
const spacesInfo = _.map([...newSpaces.values()], (ts: any) => new SpaceInfo(ts.id, ts.name))
registryStore.spacesRegistry = spacesInfo
useEntityRegistryStore().spacesRegistry = spacesInfo
})
await spacesStore.initialize(useDB().spacesIndexedDb)
await useSpacesStore().initialize(useDB().spacesDb)
console.debug('')

const tabsetsStore = useTabsetsStore()
watch(tabsetsStore.tabsets, (newTabsets:Map<string,any>) => {
const tsInfo = _.map([...newTabsets.values()], (ts: any) => new TabsetInfo(ts.id, ts.name, ts.window, ts.tabs.length))
registryStore.tabsetRegistry = tsInfo
useEntityRegistryStore().tabsetRegistry = tsInfo
})
await tabsetsStore.initialize(useDB().tabsetsIndexedDb)
await useTabsetService().init(false)
console.debug('')
await useTabsStore2().initialize()

await useTabsStore2().initialize()
console.debug('')


const existingUrls = useTabsetsStore().getAllUrls()
await useContentService().populateSearch(existingUrls)
await useTabsetService().populateSearch()
console.debug('')


ChromeApi.init(router)

if (useFeaturesStore().hasFeature(FeatureIdent.TAB_GROUPS)) {
await groupsStore.initialize(useDB().groupsIndexedDb)
groupsStore.initListeners()
await useGroupsStore().initialize(useDB().groupsIndexedDb)
useGroupsStore().initListeners()
}

useUiStore().appLoading = undefined
Expand Down
2 changes: 1 addition & 1 deletion src/features
107 changes: 0 additions & 107 deletions src/services/IndexedDbPersistenceService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,6 @@ class IndexedDbPersistenceService implements PersistenceService {
useUiStore().dbReady = true
}

async deleteDatabase(dbName: string) {
useUiStore().dbReady = false
console.warn(" ...deleting indexeddb database: not implemented", dbName)
// if (this.db) {
// await this.db.close()
// }
// console.log("db closed, deleting now")
// deleteDB(dbName, (cb) => {
// console.log("deleting cb", cb)
// })

}

async loadTabsets(): Promise<any> {
console.debug(" ...loading tabsets indexeddb")
return await this.db.getAll('tabsets')
Expand All @@ -52,24 +39,10 @@ class IndexedDbPersistenceService implements PersistenceService {
}))
}

async reloadTabset(tabsetId: string) {
const ts = await this.db.get('tabsets', tabsetId) as Tabset | undefined
if (ts) {
console.log("reloaded tabset", ts.id, ts.tabs.length)
useTabsetsStore().tabsets.set(ts.id, ts)
} else {
console.warn("could not reload tabset with id", tabsetId)
}
}

async saveTabset(tabset: Tabset): Promise<IDBValidKey> {
return await this.db.put('tabsets', JSON.parse(JSON.stringify(tabset)), tabset.id);
}

deleteTabset(tabsetId: string): Promise<void> {
return this.db.delete('tabsets', tabsetId)
}

saveRequest(url: string, requestInfo: RequestInfo): Promise<void> {
const encodedTabUrl = btoa(url)
return this.db.put('requests', {
Expand Down Expand Up @@ -196,72 +169,6 @@ class IndexedDbPersistenceService implements PersistenceService {
}
}

// async saveBlob(id: string, url: string, data: Blob, type: BlobType, remark: string | undefined = undefined): Promise<any> {
// //const encodedTabUrl = btoa(tab.url)
// const existing = await this.db.get('blobs', id)
// const arrayToSave: object[] = []
// const savedBlob = new SavedBlob(uid(), type, url, data, remark)
// if (existing) {
// existing.push(savedBlob)
// return this.db.put('blobs', existing, id)
// } else {
// return this.db.put('blobs', [savedBlob], id)
// }
// }
//
// getBlobs(type: BlobType): Promise<any[]> {
// if (!this.db) { // can happen for some reason
// return Promise.resolve([])
// }
// try {
// console.log("hier", type)
// return this.db.getAll('blobs')
// .then((b: any[]) => {
// console.log("got b", b)
// const blobs = _.flatten(b)
// return _.filter(blobs, d => d.type === type)
// })
// } catch (ex) {
// console.log("got error in getBlobs", ex)
// return Promise.reject("got error in getBlobs")
// }
// }
//
// getBlobsForTab(tabId: string): Promise<SavedBlob[]> {
// if (!this.db) { // can happen for some reason
// return Promise.resolve([])
// }
// return this.db.get('blobs', tabId)
// }
//
// async deleteBlob(tabId: string, elementId: string) {
// let blobsForTab = await this.getBlobsForTab(tabId)
// blobsForTab = _.filter(blobsForTab, b => b.id !== elementId)
// await this.db.put('blobs', blobsForTab, tabId)
// }

addGroup(group: chrome.tabGroups.TabGroup): Promise<any> {
console.debug("adding group", group)
return this.db.add('groups', group, group.title)
.catch((err) => {
if (!err.toString().indexOf('Key already exists')) {
console.log("error adding group", group, err)
}
})
}

updateGroup(group: chrome.tabGroups.TabGroup): Promise<any> {
console.log("updating group", group)
return this.db.put('groups', group, group.title)
}

getGroups(): Promise<chrome.tabGroups.TabGroup[]> {
return this.db.getAll('groups')
}

async deleteGroupByTitle(title: string): Promise<void> {
return this.db.delete('groups', title)
}
/** messages **/


Expand All @@ -274,20 +181,6 @@ class IndexedDbPersistenceService implements PersistenceService {
console.log("creating db tabsets")
db.createObjectStore('tabsets');
}
/* if (!db.objectStoreNames.contains('tabs')) {
console.log("creating db tabs")
db.createObjectStore('tabs');
}*/
// if (!db.objectStoreNames.contains('thumbnails')) {
// console.log("creating db thumbnails")
// let store = db.createObjectStore('thumbnails');
// store.createIndex("expires", "expires", {unique: false});
// }
// if (!db.objectStoreNames.contains('content')) {
// console.log("creating db content")
// let store = db.createObjectStore('content');
// store.createIndex("expires", "expires", {unique: false});
// }
if (!db.objectStoreNames.contains('spaces')) {
console.log("creating db spaces")
db.createObjectStore('spaces');
Expand Down
1 change: 1 addition & 0 deletions src/services/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ function log(msg: string, level: number) {
"host": process.env.HOST,
"short_message": msg,
"level": level,
_app: "tabsets",
_mode: process.env.MODE,
_version: version,
_stage: process.env.TABSETS_STAGE
Expand Down
19 changes: 12 additions & 7 deletions src/services/usePersistenceService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,36 @@ import IndexedDbSnapshotPersistence from "src/snapshots/persistence/IndexedDbSna
import IndexedDbTabsetsGroupsPersistence from "src/tabsets/persistence/IndexedDbTabsetsGroupsPersistence";
import TabsetsGroupsPersistence from "src/tabsets/persistence/TabsetsGroupsPersistence";
import IndexedDbNotesPersistence from "src/notes/persistence/IndexedDbNotesPersistence";
import ThumbnailsPersistence from "src/thumbnails/persistence/ThumbnailsPersistence";
import IndexedDbThumbnailsPersistence from "src/thumbnails/persistence/IndexedDbThumbnailsPersistence";

export function useDB(quasar: QVueGlobals | undefined = undefined) {

const db: PersistenceService = IndexedDbPersistenceService

const spacesIndexedDb: SpacesPersistence = IndexedDbSpacesStorage
const spacesDb: SpacesPersistence = IndexedDbSpacesStorage

const tabsetsIndexedDb: TabsetsPersistence = IndexedDbTabsetsPersistence
const groupsIndexedDb: TabsetsGroupsPersistence = IndexedDbTabsetsGroupsPersistence

const snapshotsIndexedDb: SnapshotsPersistence = IndexedDbSnapshotPersistence
const snapshotsDb: SnapshotsPersistence = IndexedDbSnapshotPersistence
const notesDb = IndexedDbNotesPersistence

const thumbnailsDb: ThumbnailsPersistence = IndexedDbThumbnailsPersistence

let localDb = undefined as unknown as PersistenceService
let featuresLocalStorage: FeaturesPersistence = undefined as unknown as FeaturesPersistence
let featuresDb: FeaturesPersistence = undefined as unknown as FeaturesPersistence
if (quasar) {
localDb = new LocalStoragePersistenceService(quasar)
featuresLocalStorage = new LocalStorageFeaturesPersistence(quasar)
featuresDb = new LocalStorageFeaturesPersistence(quasar)
}

return {
db, localDb, spacesIndexedDb,
db, localDb, spacesDb,
tabsetsIndexedDb,
featuresLocalStorage,
snapshotsIndexedDb,
featuresDb,
snapshotsDb,
thumbnailsDb,
groupsIndexedDb,
notesDb
}
Expand Down

0 comments on commit a84ca95

Please sign in to comment.