diff --git a/src/constants.ts b/src/constants.ts index d9690b4..35caec9 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -44,7 +44,8 @@ export const DEFAULT_SETTINGS: PluginSettings = { newCardPosition: CardPosition.Top, movedCardPosition: CardPosition.Top, verboseLogging: false, - prepopulateTitle: false + prepopulateTitle: false, + openInDesktop: false }; export const DEFAULT_DATA: PluginData = { diff --git a/src/interfaces.ts b/src/interfaces.ts index 397ad99..81f9326 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -26,6 +26,7 @@ export interface PluginSettings { movedCardPosition: CardPosition; verboseLogging: boolean; prepopulateTitle: boolean; + openInDesktop: boolean; } export enum PluginError { diff --git a/src/settings.ts b/src/settings.ts index 71ccf32..4d68384 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -1,4 +1,4 @@ -import { App, PluginSettingTab, Setting } from 'obsidian'; +import { App, PluginSettingTab, Setting, Platform } from 'obsidian'; import { CardPosition, LeafSide, PluginSettings } from './interfaces'; import { GLOBAL_UI, TRELLO_TOKEN_URL } from './constants'; @@ -28,6 +28,7 @@ export class TrelloSettings extends PluginSettingTab { this.buildMovedCardPositionSetting(this.containerEl, settings); this.buildVerboseLoggingSetting(this.containerEl, settings); this.prepopulateTitleConfigSetting(this.containerEl, settings); + this.openInDesktopSetting(this.containerEl, settings); }); } @@ -63,6 +64,20 @@ export class TrelloSettings extends PluginSettingTab { }); } + private openInDesktopSetting(containerEl: HTMLElement, settings: PluginSettings): void { + if (Platform.isMacOS || Platform.isWin) { + this.plugin.log('TrelloSettings.openInDesktopSetting', '-> Adding open in desktop config setting'); + new Setting(containerEl) + .setName('Open in Trello desktop') + .setDesc('Opens Trello card in desktop application on macOS or Windows') + .addToggle((toggle) => { + toggle.setValue(settings.openInDesktop).onChange((value) => { + this.plugin.state.updateSetting('openInDesktop', value); + }); + }); + } + } + private prepopulateTitleConfigSetting(containerEl: HTMLElement, settings: PluginSettings): void { this.plugin.log( 'TrelloSettings.buildConfigSetting', diff --git a/src/view/view.ts b/src/view/view.ts index 185f714..549dda4 100644 --- a/src/view/view.ts +++ b/src/view/view.ts @@ -214,10 +214,16 @@ export class TrelloView extends ItemView { private renderCardTitle(card: TrelloCard, parent: HTMLElement): void { this.plugin.log('TrelloView.renderCardTitle', ''); const cardName = parent.createEl('h3', { text: card.name }); - const cardLink = cardName.createEl('a', { - attr: { href: card.url, 'aria-label': 'View on Trello' } + + let cardLink = String(card.url); + if (this.plugin.state.getSetting('openInDesktop') === true) { + cardLink = card.url.replace('https', 'trello'); + } + + const cardLinkEl = cardName.createEl('a', { + attr: { href: cardLink, 'aria-label': 'View on Trello' } }); - setIcon(cardLink, 'navigate-glyph'); + setIcon(cardLinkEl, 'navigate-glyph'); } /**