From 0246016b48be40c6dc9913c6ea4a798a0dace5d4 Mon Sep 17 00:00:00 2001 From: Guilherme Cattani Date: Sat, 28 Jun 2025 13:39:07 +0200 Subject: [PATCH] Add new line support, bugfixes Fixed a bug where the container was duplicated on error Removed the default background for upcoming since it can't adhere to the user theme --- manifest.json | 2 +- package.json | 2 +- src/countdownToMarkdownRenderChild.ts | 16 ++++++++++++++-- src/settings.ts | 4 ++-- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/manifest.json b/manifest.json index c5efd07..b45ce84 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "countdown-to", "name": "Countdown To", - "version": "1.4.0", + "version": "1.4.1", "minAppVersion": "0.15.0", "description": "Create countdown progress bars in your notes", "author": "Gui Cattani", diff --git a/package.json b/package.json index fbe109c..1ff0d7c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "obsidian-countdown-to", - "version": "1.3.0", + "version": "1.4.1", "description": "Create countdown progress bars in your notes", "main": "main.js", "scripts": { diff --git a/src/countdownToMarkdownRenderChild.ts b/src/countdownToMarkdownRenderChild.ts index 60ad546..6ef81ff 100644 --- a/src/countdownToMarkdownRenderChild.ts +++ b/src/countdownToMarkdownRenderChild.ts @@ -61,6 +61,7 @@ export class CountdownToMarkdownRenderChild extends MarkdownRenderChild { const isUpcoming = startDate > DateTime.now(); if (isUpcoming) { containerEl.addClass('countdown-to-upcoming'); + document.documentElement.style.setProperty( '--countdown-to-upcoming-bg', this.plugin.settings.defaultUpcomingBackgroundColor @@ -113,7 +114,12 @@ export class CountdownToMarkdownRenderChild extends MarkdownRenderChild { if (params.title) { const titleEl = containerEl.createDiv({ cls: 'countdown-to-title' }); - titleEl.setText(params.title); + const titleLines = params.title.split('\\n'); + titleLines.forEach(line => { + const lineEl = titleEl.createDiv({ cls: 'countdown-to-title-line' }); + lineEl.setText(line); + }); + containerEl.prepend(titleEl); } @@ -149,6 +155,7 @@ export class CountdownToMarkdownRenderChild extends MarkdownRenderChild { } } catch (error) { + this.containerEl.empty(); const containerEl = this.containerEl.createDiv({ cls: ['countdown-to-plugin', 'countdown-to-container'] }); containerEl.setText('Error rendering countdown to: ' + error.message); } @@ -246,7 +253,12 @@ export class CountdownToMarkdownRenderChild extends MarkdownRenderChild { infoText = infoText.replace(/{total}/g, this.formatDuration(totalDuration)) } - countdownTo.infoEl.setText(infoText); + countdownTo.infoEl.empty(); + const infoLines = infoText.split('\\n'); + infoLines.forEach(line => { + const lineEl = countdownTo.infoEl.createDiv({ cls: 'countdown-to-info-line' }); + lineEl.setText(line); + }); } } diff --git a/src/settings.ts b/src/settings.ts index 791bbc1..95b147f 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -18,7 +18,7 @@ export interface CountdownToSettings { export const DEFAULT_SETTINGS: CountdownToSettings = { defaultBarColor: '#4CAF50', defaultTrailColor: '#e0e0e0', - defaultUpcomingBackgroundColor: '#e3e3e3', + defaultUpcomingBackgroundColor: '#gggggg', // invalid color so that we know the user didn't set it defaultBarType: 'Line', defaultProgressType: 'Forward', defaultOnCompleteText: '{title} is done!', @@ -202,7 +202,7 @@ export class CountdownToSettingTab extends PluginSettingTab { new Setting(containerEl) .setName('Default upcoming background color') - .setDesc('Default background color for countdowns that are upcoming (start date in the future)') + .setDesc('Default background color for countdowns that are upcoming (start date in the future). Needs manual reload of notes to take effect.') .addColorPicker(color => color .setValue(this.plugin.settings.defaultUpcomingBackgroundColor) .onChange(async (value) => {