From c5e437504790d4389b5e00f63db4da7145a8a138 Mon Sep 17 00:00:00 2001 From: Chris Chinchilla Date: Sat, 3 Feb 2024 12:28:44 +0100 Subject: [PATCH 1/5] Add ability to open Trello card in desktop app --- src/constants.ts | 3 ++- src/interfaces.ts | 1 + src/settings.ts | 17 ++++++++++++++++- src/view/view.ts | 12 +++++++++--- 4 files changed, 28 insertions(+), 5 deletions(-) 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'); } /** From c0d3d7c5703426980874fd785491fcb37e09a70f Mon Sep 17 00:00:00 2001 From: Chris Chinchilla Date: Fri, 16 Feb 2024 08:51:36 +0100 Subject: [PATCH 2/5] Fix typo --- src/plugin.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugin.ts b/src/plugin.ts index 3d70ea4..baf3ae6 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -118,7 +118,7 @@ export class TrelloPlugin extends Plugin { log(context: string, message: string, logLevel: LogLevel = LogLevel.Info): void { if (this.state.getSetting('verboseLogging')) { - const log = `OBISIDAN-TRELLO: (${context}) ${message}`; + const log = `OBSIDIAN-TRELLO: (${context}) ${message}`; switch (logLevel) { case LogLevel.Warn: console.warn(log); From 51b51caba94b89049f65553496595d02ac78a376 Mon Sep 17 00:00:00 2001 From: Chris Chinchilla Date: Mon, 19 Feb 2024 09:22:56 +0100 Subject: [PATCH 3/5] Update src/settings.ts Co-authored-by: Nathan --- src/settings.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/settings.ts b/src/settings.ts index 4d68384..ba5cc7a 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -69,7 +69,7 @@ export class TrelloSettings extends PluginSettingTab { 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') + .setDesc('Opens cards in Trello desktop application on macOS or Windows') .addToggle((toggle) => { toggle.setValue(settings.openInDesktop).onChange((value) => { this.plugin.state.updateSetting('openInDesktop', value); From 56ee4347fa078a37f0d3e05d1f685d36b941a06d Mon Sep 17 00:00:00 2001 From: Chris Chinchilla Date: Tue, 20 Feb 2024 11:26:23 +0100 Subject: [PATCH 4/5] Provide a contextual link --- src/view/view.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/view/view.ts b/src/view/view.ts index 549dda4..6422482 100644 --- a/src/view/view.ts +++ b/src/view/view.ts @@ -1,5 +1,5 @@ import { CUSTOM_ICONS, TRELLO_ERRORS, TRELLO_VIEW_TYPE } from '../constants'; -import { ItemView, MarkdownRenderer, Notice, WorkspaceLeaf, setIcon } from 'obsidian'; +import { ItemView, MarkdownRenderer, Notice, WorkspaceLeaf, setIcon, Platform } from 'obsidian'; import { PluginError, PluginUISettings, @@ -215,14 +215,21 @@ export class TrelloView extends ItemView { this.plugin.log('TrelloView.renderCardTitle', ''); const cardName = parent.createEl('h3', { text: card.name }); - let cardLink = String(card.url); + let cardLink = card.url; + let cardLinkEl = HTMLAnchorElement.prototype; + 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' } - }); + if (Platform.isMacOS || Platform.isWin) { + cardLinkEl = cardName.createEl('a', { + attr: { href: cardLink, 'aria-label': 'View in Trello Desktop' } + }); + } else { + cardLinkEl = cardName.createEl('a', { + attr: { href: cardLink, 'aria-label': 'View on Trello' } + }); + } setIcon(cardLinkEl, 'navigate-glyph'); } From 5050a70e016d958000d06400abfdd8b89bc4a1a1 Mon Sep 17 00:00:00 2001 From: Chris Chinchilla Date: Tue, 20 Feb 2024 11:26:37 +0100 Subject: [PATCH 5/5] Remove setting on non-compatible OSs --- src/plugin.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/plugin.ts b/src/plugin.ts index baf3ae6..610e196 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -10,7 +10,7 @@ import { TRELLO_VIEW_TYPE } from './constants'; import { LeafSide, PluginData, PluginError, TrelloBoard, TrelloCard } from './interfaces'; -import { Notice, Plugin, TFile, WorkspaceLeaf, addIcon } from 'obsidian'; +import { Notice, Plugin, TFile, WorkspaceLeaf, addIcon, Platform } from 'obsidian'; import { Observable, Subject, concat, forkJoin, iif, of } from 'rxjs'; import { concatMap, map, take, tap } from 'rxjs/operators'; @@ -40,6 +40,11 @@ export class TrelloPlugin extends Plugin { const data: PluginData = Object.assign({}, DEFAULT_DATA, savedData); data.settings = Object.assign({}, DEFAULT_SETTINGS, savedData?.settings); data.settings.customUi = Object.assign({}, DEFAULT_SETTINGS.customUi, savedData?.settings.customUi); + + if (!Platform.isWin && !Platform.isMacOS) { + data.settings.openInDesktop = false; + } + this.state = new PluginState(this, data); // Create new API instance