From 801fdec71efd012060bce604cf8b61da30fd889f Mon Sep 17 00:00:00 2001 From: oqyude Date: Sat, 11 Jul 2026 03:22:18 +0300 Subject: [PATCH] workflow and fixes --- .github/workflows/release.yml | 42 +++++++++++ src/modules/attachment-clean-paste/index.ts | 82 +++++++-------------- src/modules/base-module.ts | 6 ++ src/settings.ts | 12 ++- src/types.ts | 5 ++ 5 files changed, 90 insertions(+), 57 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..441f852 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,42 @@ +name: Release + +on: + push: + tags: + - 'v*' + +jobs: + release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + cache: 'npm' + + - name: Install dependencies + run: npm ci + + - name: Build + run: npm run build + + - name: Verify version + run: | + TAG_VERSION="${GITHUB_REF_NAME#v}" + MANIFEST_VERSION=$(node -p "require('./manifest.json').version") + if [ "$TAG_VERSION" != "$MANIFEST_VERSION" ]; then + echo "❌ Tag ($TAG_VERSION) != manifest ($MANIFEST_VERSION)" + exit 1 + fi + + - name: Create Release + uses: softprops/action-gh-release@v2 + with: + name: ${{ github.ref_name }} + files: | + main.js + manifest.json + styles.css diff --git a/src/modules/attachment-clean-paste/index.ts b/src/modules/attachment-clean-paste/index.ts index 7dc8c73..7cd7d28 100644 --- a/src/modules/attachment-clean-paste/index.ts +++ b/src/modules/attachment-clean-paste/index.ts @@ -4,7 +4,6 @@ import { MarkdownFileInfo, MarkdownView, Notice, - PluginSettingTab, Setting, normalizePath, } from 'obsidian'; @@ -33,25 +32,45 @@ export class AttachmentCleanPasteModule extends BaseModule { onload(plugin: ZeroQoLModulesPlugin, moduleSettings: Record): void { this.app = plugin.app; - const settings = moduleSettings as unknown as AttachmentCleanPasteSettings; - - plugin.addSettingTab( - new AttachmentCleanPasteSettingTab(plugin.app, plugin, MODULE_ID), - ); + const rawSettings = moduleSettings as AttachmentCleanPasteSettings; const pasteRef = plugin.app.workspace.on( 'editor-paste', - this.createPasteHandler(settings), + this.createPasteHandler(rawSettings), ); this.registerCleanup(() => plugin.app.workspace.offref(pasteRef)); const dropRef = plugin.app.workspace.on( 'editor-drop', - this.createDropHandler(settings), + this.createDropHandler(rawSettings), ); this.registerCleanup(() => plugin.app.workspace.offref(dropRef)); } + renderInlineSettings( + containerEl: HTMLElement, + settings: Record, + saveSettings: () => Promise, + ): void { + const loc = locale.modules['attachment-clean-paste']; + const extSettings = settings as unknown as AttachmentCleanPasteSettings; + + new Setting(containerEl) + .setName(loc.extensionsLabel) + .setDesc(loc.extensionsDesc) + .addTextArea((textarea) => { + textarea + .setPlaceholder(loc.extensionsPlaceholder) + .setValue(extSettings?.extensions ?? '') + .onChange(async (value) => { + settings.extensions = value; + await saveSettings(); + }); + textarea.inputEl.rows = 4; + textarea.inputEl.style.width = '100%'; + }); + } + private createPasteHandler(settings: AttachmentCleanPasteSettings) { return async ( evt: ClipboardEvent, @@ -155,50 +174,3 @@ export class AttachmentCleanPasteModule extends BaseModule { } } } - -class AttachmentCleanPasteSettingTab extends PluginSettingTab { - private plugin: ZeroQoLModulesPlugin; - private moduleId: string; - - constructor(app: App, plugin: ZeroQoLModulesPlugin, moduleId: string) { - super(app, plugin); - this.plugin = plugin; - this.moduleId = moduleId; - } - - display(): void { - const { containerEl } = this; - containerEl.empty(); - - const loc = locale.modules['attachment-clean-paste']; - - containerEl.createEl('h2', { text: loc.name }); - containerEl.createEl('p', { - text: loc.descriptionShort, - attr: { style: 'color: var(--text-muted); margin-bottom: 20px;' }, - }); - - const rawSettings = this.plugin.settings.modules[this.moduleId]?.settings as - | AttachmentCleanPasteSettings - | undefined; - - new Setting(containerEl) - .setName(loc.extensionsLabel) - .setDesc(loc.extensionsDesc) - .addTextArea((textarea) => { - textarea - .setPlaceholder(loc.extensionsPlaceholder) - .setValue(rawSettings?.extensions ?? '') - .onChange(async (value) => { - if (this.plugin.settings.modules[this.moduleId]) { - this.plugin.settings.modules[this.moduleId].settings = { - extensions: value, - }; - } - await this.plugin.saveSettings(); - }); - textarea.inputEl.rows = 4; - textarea.inputEl.style.width = '100%'; - }); - } -} diff --git a/src/modules/base-module.ts b/src/modules/base-module.ts index 3b2ce75..63ef6e7 100644 --- a/src/modules/base-module.ts +++ b/src/modules/base-module.ts @@ -21,6 +21,12 @@ export abstract class BaseModule implements QoLModule { this.cleanupFns = []; } + renderInlineSettings( + _containerEl: HTMLElement, + _settings: Record, + _saveSettings: () => Promise, + ): void {} + protected registerCleanup(fn: () => void): void { this.cleanupFns.push(fn); } diff --git a/src/settings.ts b/src/settings.ts index e316fab..8a28bc3 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -45,14 +45,14 @@ export class ZeroQSettingTab extends PluginSettingTab { }); for (const module of MODULES) { - const moduleSettings = this.plugin.settings.modules[module.id]; + const moduleCfg = this.plugin.settings.modules[module.id]; new Setting(containerEl) .setName(module.name) .setDesc(module.description) .addToggle((toggle) => toggle - .setValue(moduleSettings?.enabled ?? true) + .setValue(moduleCfg?.enabled ?? true) .onChange(async (value) => { if (!this.plugin.settings.modules[module.id]) { this.plugin.settings.modules[module.id] = { @@ -70,6 +70,14 @@ export class ZeroQSettingTab extends PluginSettingTab { } }), ); + + if (moduleCfg) { + module.renderInlineSettings( + containerEl, + moduleCfg.settings, + () => this.plugin.saveSettings(), + ); + } } } } diff --git a/src/types.ts b/src/types.ts index 33f2470..f8a81a7 100644 --- a/src/types.ts +++ b/src/types.ts @@ -16,4 +16,9 @@ export interface QoLModule { defaultSettings: Record; onload(plugin: Plugin, moduleSettings: Record): void; onunload(plugin: Plugin): void; + renderInlineSettings( + containerEl: HTMLElement, + settings: Record, + saveSettings: () => Promise, + ): void; }