Skip to content

Commit

Permalink
Merge pull request #10 from shmolf/leverage-different-event
Browse files Browse the repository at this point in the history
fix: leverage solution provided by liamcain
  • Loading branch information
shmolf authored Apr 22, 2023
2 parents 9a4049d + b30632d commit 2aa32fa
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/Plugin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Plugin } from 'obsidian';
import { Plugin, WorkspaceWindow } from 'obsidian';
import { UrlSettingsTab } from './PluginSettingsTab';

interface PluginSettings {
Expand All @@ -9,7 +9,7 @@ interface PluginSettings {
}

export const DEFAULT_SETTINGS: Partial<PluginSettings> = {
imageUrl: 'protocol:://domain.tld/path/to/image.png',
imageUrl: 'protocol://domain.tld/path/to/image.png',
opacity: 0.3,
bluriness: 'low',
inputContrast: false,
Expand All @@ -22,9 +22,8 @@ export default class BackgroundPlugin extends Plugin {
await this.loadSettings();

this.addSettingTab(new UrlSettingsTab(this.app, this));

this.app.workspace.onLayoutReady(() => this.UpdateBackground());
this.app.workspace.on('active-leaf-change', () => this.UpdateBackground());
this.app.workspace.onLayoutReady(() => this.UpdateBackground(document));
this.app.workspace.on('window-open', (win: WorkspaceWindow) => this.UpdateBackground(win.doc));
}

async loadSettings() {
Expand All @@ -37,13 +36,9 @@ export default class BackgroundPlugin extends Plugin {
}

UpdateBackground(doc: Document = activeDocument) {
const containers = doc.querySelectorAll('.cm-editor') as NodeListOf<HTMLElement>;

containers.forEach((container) => {
container.style.setProperty('--obsidian-editor-background-image', `url('${this.settings.imageUrl}')`);
container.style.setProperty('--obsidian-editor-background-opacity', `${this.settings.opacity}`);
container.style.setProperty('--obsidian-editor-background-bluriness', `blur(${this.settings.bluriness})`);
container.style.setProperty('--obsidian-editor-background-input-contrast', this.settings.inputContrast ? '#ffffff17' : 'none');
});
doc.body.style.setProperty('--obsidian-editor-background-image', `url('${this.settings.imageUrl}')`);
doc.body.style.setProperty('--obsidian-editor-background-opacity', `${this.settings.opacity}`);
doc.body.style.setProperty('--obsidian-editor-background-bluriness', `blur(${this.settings.bluriness})`);
doc.body.style.setProperty('--obsidian-editor-background-input-contrast', this.settings.inputContrast ? '#ffffff17' : 'none');
}
}

0 comments on commit 2aa32fa

Please sign in to comment.