Skip to content

Commit

Permalink
Merge pull request #149 from leoccyao/show-report-command
Browse files Browse the repository at this point in the history
Add commands to show report, reconnect to Toggl API
  • Loading branch information
mcndt authored Jul 14, 2024
2 parents 0af2388 + 16ef5e4 commit 51ba08f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/toggl/TogglService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
29 changes: 29 additions & 0 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,35 @@ 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",
});

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

0 comments on commit 51ba08f

Please sign in to comment.