Skip to content

Commit

Permalink
1.1.0 (#10)
Browse files Browse the repository at this point in the history
* chore: move backgrounder to main plugin class

* feat: add thumbnail zoom setting

* feat: improve zoom

* chore: refactor image loading queue

* feat: make thumbnails self-loading with a global queue

* fix: add missing function

* fix: ts config includes

* chore: add responsive wrapper

* chore: improve styles, improve thumbnail queueing
  • Loading branch information
AriTheElk authored Dec 17, 2024
1 parent 0204ac4 commit 65b5bb9
Show file tree
Hide file tree
Showing 12 changed files with 349 additions and 156 deletions.
7 changes: 5 additions & 2 deletions src/ImagePicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ import {
VALID_IMAGE_EXTENSIONS,
VIEW_TYPE_IMAGE_PICKER,
} from './constants'
import { Backgrounder } from './backend/Backgrounder'

export class ImagePicker extends Plugin {
settings: ImagePickerSettings
images: TFile[] = []
indexer: Indexer = new Indexer(this)
backgrounder: Backgrounder = new Backgrounder(this)

log = (...args: any[]) => {

Check warning on line 23 in src/ImagePicker.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

Unexpected any. Specify a different type
if (this.settings?.debugMode) {
Expand Down Expand Up @@ -47,6 +49,7 @@ export class ImagePicker extends Plugin {
this.app.vault.off('create', this.onFileCreate)
this.app.vault.off('modify', this.onFileChange)
this.app.vault.off('delete', this.onFileDelete)
this.backgrounder.clear()
}
/**
* When a file is created, add it to the index and
Expand Down Expand Up @@ -129,12 +132,12 @@ export class ImagePicker extends Plugin {
}
}

async loadSettings() {
loadSettings = async () => {
this.log('Loading settings...')
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData())
}

async saveSettings() {
saveSettings = async () => {
this.log('Saving settings:', this.settings)
await this.saveData(this.settings)
}
Expand Down
1 change: 1 addition & 0 deletions src/ImagePickerSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface ImagePickerSettings {
imageFolder: string
animateGifs: boolean
debugMode: boolean
zoom: number
}

export class ImagePickerSettingTab extends PluginSettingTab {
Expand Down
8 changes: 8 additions & 0 deletions src/backend/Backgrounder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,12 @@ export class Backgrounder {
this.running = false
this.run()
}

/**
* Clears the queue
*/
clear = () => {
this.queue = []
this.log('Cleared queue')
}
}
10 changes: 3 additions & 7 deletions src/backend/Indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import {
} from '../utils'
import ImagePicker from '../main'

import { Backgrounder } from './Backgrounder'

export interface IndexerRoot {
[path: string]: IndexerNode
}
Expand Down Expand Up @@ -54,10 +52,8 @@ class IndexerDB extends Dexie {
export class Indexer {
private memory: IndexerRoot = {}
private db: IndexerDB = new IndexerDB()
private backgrounder: Backgrounder

constructor(public plugin: ImagePicker) {
this.backgrounder = new Backgrounder(this.plugin)
this.getIndex().then((root) => {
this.log('Loaded index:', root)
})
Expand Down Expand Up @@ -111,7 +107,7 @@ export class Indexer {
this.memory[node.path] = { ...node, thumbnail: id }
this.log('Generated thumbnail:', id)

this.backgrounder.enqueue({
this.plugin.backgrounder.enqueue({
type: 'saveIndex',
disableDoubleQueue: true,
action: this.saveIndex,
Expand Down Expand Up @@ -151,7 +147,7 @@ export class Indexer {
}

this.memory = merge({}, this.memory, root)
this.backgrounder.enqueue({
this.plugin.backgrounder.enqueue({
type: 'saveIndex',
disableDoubleQueue: true,
action: this.saveIndex,
Expand All @@ -170,7 +166,7 @@ export class Indexer {
await this.db.thumbnails.delete(node.thumbnail)
}
this.notifySubscribers()
this.backgrounder.enqueue({
this.plugin.backgrounder.enqueue({
type: 'saveIndex',
disableDoubleQueue: true,
action: this.saveIndex,
Expand Down
Loading

0 comments on commit 65b5bb9

Please sign in to comment.