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 commands to show report, reconnect to Toggl API #149

Merged
merged 3 commits into from
Jul 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
)
Comment on lines +83 to +88
Copy link
Owner

Choose a reason for hiding this comment

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

Great QoL improvement. One addition I would add is to set the API status to ApiStatus.UNTESTED before resetting the API client, either before calling this.setToken or at the top of this.setToken. I'll add that change in the release.

// 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);
Copy link
Owner

Choose a reason for hiding this comment

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

I'll also add the notice here.

Suggested change
this.toggl.setToken(this.settings.apiToken);
new Notice("Reconnecting to Toggl...");
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