Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to open Trello card in desktop app #57

Merged
merged 8 commits into from
Feb 29, 2024
3 changes: 2 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
1 change: 1 addition & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface PluginSettings {
movedCardPosition: CardPosition;
verboseLogging: boolean;
prepopulateTitle: boolean;
openInDesktop: boolean;
}

export enum PluginError {
Expand Down
17 changes: 16 additions & 1 deletion src/settings.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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);
});
}

Expand Down Expand Up @@ -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');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with hiding this setting on other platforms, as long as we also override the saved settings on other platforms. I think a check in plugin.ts after loading settings, but before initializing the state:

    // Set up data and default data.
    const savedData: PluginData | undefined = await this.loadData();
    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);

    // Add something like this
    if (!Platform.isWin && !Platform.isMacOS) {
        data.settings.openInDesktop = false;
    }

    this.state = new PluginState(this, data);

It's not a big deal but I know I use a synced obsidian vault on multiple platforms. I wouldn't want someone to enable it on a Mac, then open Obsidian on Linux and have everything be broken.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nathonius OK, I will need to test this, and it's a busy week, leave it with me

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nathonius Added, but I am finding it really hard to test, as everything still shows on iPad and actually still opens in the iPad Trello app anyway 🤷 . Do you have a way to test on Linux?

Copy link
Owner

@nathonius nathonius Feb 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I can test on a Linux desktop. Will do that in the next day or two. Maybe Android would work too? I can modify to allow the setting there and see if it opens the Trello app.

new Setting(containerEl)
.setName('Open in Trello desktop')
.setDesc('Opens Trello card in desktop application on macOS or Windows')
.addToggle((toggle) => {
ChrisChinchilla marked this conversation as resolved.
Show resolved Hide resolved
toggle.setValue(settings.openInDesktop).onChange((value) => {
this.plugin.state.updateSetting('openInDesktop', value);
});
});
}
}

private prepopulateTitleConfigSetting(containerEl: HTMLElement, settings: PluginSettings): void {
this.plugin.log(
'TrelloSettings.buildConfigSetting',
Expand Down
12 changes: 9 additions & 3 deletions src/view/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
ChrisChinchilla marked this conversation as resolved.
Show resolved Hide resolved
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' }
ChrisChinchilla marked this conversation as resolved.
Show resolved Hide resolved
});
setIcon(cardLink, 'navigate-glyph');
setIcon(cardLinkEl, 'navigate-glyph');
}

/**
Expand Down
Loading