Skip to content

Commit

Permalink
Add a toggle to control whether categories should be synchronized whe…
Browse files Browse the repository at this point in the history
…n Obsidian opens
  • Loading branch information
otaviocc committed Jan 5, 2024
1 parent 5c92b20 commit d4df7a7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/MicroPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ export default class MicroPlugin extends Plugin {
await this.loadServiceFactory()
await this.registerSynchronizationService()

this.synchronizationService.fetchTags()
if (this.settings.synchronizeCategoriesOnOpen) {
this.synchronizationService.fetchTags()
}

this.addCommand({
id: 'microblog-publish-post-command',
Expand Down
7 changes: 6 additions & 1 deletion src/stores/StoredSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export interface StoredSettings {
// Boolean indicating if pages should be added
// to the blog navigation.
includePagesInNavigation: boolean

// Boolean indicating if the plugin should synchronize
// the list of categories when Obsidian opens.
synchronizeCategoriesOnOpen: boolean
}

// Default values for the plugin.
Expand All @@ -37,5 +41,6 @@ export const defaultSettings: StoredSettings = {
blogs: {},
selectedBlogID: 'default',
synchronizedCategories: {},
includePagesInNavigation: false
includePagesInNavigation: false,
synchronizeCategoriesOnOpen: true
}
10 changes: 10 additions & 0 deletions src/views/MicroPluginSettingsView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,16 @@ export class MicroPluginSettingsView extends PluginSettingTab implements MicroPl

containerEl.createEl('h2', { text: 'Misc.' })

new Setting(containerEl)
.setName('Categories synchronization')
.setDesc('Toggle on to automatically synchronize categories when Obsidian opens.')
.addToggle(toggle => toggle
.setValue(this.viewModel.synchronizeCategoriesOnOpen)
.onChange(value => {
this.viewModel.synchronizeCategoriesOnOpen = value
})
)

new Setting(this.containerEl)
.setName('Sponsor')
.setDesc('Enjoying this plugin? Show your appreciation with a cup of coffee! 😊☕')
Expand Down
12 changes: 12 additions & 0 deletions src/views/MicroPluginSettingsViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@ export class MicroPluginSettingsViewModel {
this.plugin.saveSettings()
}

public get synchronizeCategoriesOnOpen(): boolean {
return this.settings.synchronizeCategoriesOnOpen
}

public set synchronizeCategoriesOnOpen(value: boolean) {
this.settings.synchronizeCategoriesOnOpen = value
this.plugin.saveSettings()
}

public async validate() {
console.log('Logging in')

Expand All @@ -151,6 +160,9 @@ export class MicroPluginSettingsViewModel {
this.selectedBlogID = 'default'
this.visibility = 'draft'
this.synchronizedCategories = {}
this.includePagesInNavigation = false
this.synchronizeCategoriesOnOpen = true

this.delegate?.logoutDidSucceed()
console.log('Logout successful')
}
Expand Down

0 comments on commit d4df7a7

Please sign in to comment.