From 83831c60922043eb85fa4f974bcea1c63352c0a8 Mon Sep 17 00:00:00 2001 From: Leo Yao <45076643+leoccyao@users.noreply.github.com> Date: Tue, 2 Jan 2024 11:55:17 -0500 Subject: [PATCH 1/3] Add command to show report --- main.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/main.ts b/main.ts index c4b2ae6..70da7bb 100644 --- a/main.ts +++ b/main.ts @@ -72,6 +72,23 @@ export default class MyPlugin extends Plugin { this.app.workspace.onLayoutReady(this.initLeaf.bind(this)); } + this.addCommand({ + callback: async () => { + const existing = this.app.workspace.getLeavesOfType(VIEW_TYPE_REPORT); + if (existing.length) { + this.app.workspace.revealLeaf(existing[0]); + return; + } + await this.app.workspace.getRightLeaf(false).setViewState({ + active: true, + type: VIEW_TYPE_REPORT, + }); + this.app.workspace.revealLeaf(this.app.workspace.getLeavesOfType(VIEW_TYPE_REPORT)[0]); + }, + id: "show-report-view", + name: "Open report view", + }); + // Enable processing codeblocks for rendering in-note reports this.registerCodeBlockProcessor(); } From 04f325f5b562591b6f23fe2ffe60f541498bdb14 Mon Sep 17 00:00:00 2001 From: Leo Yao <45076643+leoccyao@users.noreply.github.com> Date: Tue, 2 Jan 2024 20:49:15 -0500 Subject: [PATCH 2/3] Add command to refresh Toggl API connection --- main.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/main.ts b/main.ts index 70da7bb..c44d045 100644 --- a/main.ts +++ b/main.ts @@ -89,6 +89,18 @@ export default class MyPlugin extends Plugin { name: "Open report view", }); + this.addCommand({ + checkCallback: (checking: boolean) => { + if (!checking) { + this.toggl.setToken(this.settings.apiToken); + } else { + return this.settings.apiToken != null || this.settings.apiToken != ""; + } + }, + id: "refresh-api", + name: "Refresh API Connection", + }); + // Enable processing codeblocks for rendering in-note reports this.registerCodeBlockProcessor(); } From 16ef5e4b453dafd4c92b0fe1132886e97eefd72c Mon Sep 17 00:00:00 2001 From: Leo Yao <45076643+leoccyao@users.noreply.github.com> Date: Tue, 2 Jan 2024 20:49:33 -0500 Subject: [PATCH 3/3] Reconnect to Toggl on status bar click --- lib/toggl/TogglService.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/toggl/TogglService.ts b/lib/toggl/TogglService.ts index 142480b..0394c19 100644 --- a/lib/toggl/TogglService.ts +++ b/lib/toggl/TogglService.ts @@ -79,6 +79,13 @@ export default class TogglService { this._statusBarItem = this._plugin.addStatusBarItem(); this._statusBarItem = this._plugin.addStatusBarItem(); this._statusBarItem.setText("Connecting to Toggl..."); + + this._plugin.registerDomEvent( + this._statusBarItem, "click", () => { + new Notice('Reconnecting to Toggl...') + this.setToken(this._plugin.settings.apiToken) + } + ) // Store a reference to the manager in a svelte store to avoid passing // of references around the component trees. togglService.set(this);