Skip to content

Commit 16bd11c

Browse files
authored
Feature/clickable notification toggle (#68)
* feat: add toggle notifications command and status bar item for health notifications seperated * chore: bump version to 0.6.1 in package.json
1 parent 3dbb6c5 commit 16bd11c

4 files changed

Lines changed: 132 additions & 18 deletions

File tree

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "simple-coding-time-tracker",
33
"displayName": "Simple Coding Time Tracker",
44
"description": "Track and visualize your coding time across projects",
5-
"version": "0.6.0",
5+
"version": "0.6.1",
66
"publisher": "noorashuvo",
77
"license": "MIT",
88
"icon": "icon-sctt.png",
@@ -86,6 +86,10 @@
8686
"command": "simpleCodingTimeTracker.clearAllData",
8787
"title": "SCTT: Clear All Time Tracking Data"
8888
},
89+
{
90+
"command": "simpleCodingTimeTracker.toggleNotifications",
91+
"title": "SCTT: Toggle Notifications"
92+
},
8993
{
9094
"command": "simpleCodingTimeTracker.toggleHealthNotifications",
9195
"title": "SCTT: Toggle Health Notifications"

src/extension.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ export function activate(context: vscode.ExtensionContext) {
2222
vscode.workspace.onDidChangeConfiguration(e => {
2323
if (e.affectsConfiguration('simpleCodingTimeTracker')) {
2424
timeTracker.updateConfiguration();
25+
// Update status bar when health notifications setting changes
26+
if (e.affectsConfiguration('simpleCodingTimeTracker.health.enableNotifications')) {
27+
statusBar.updateNow();
28+
}
2529
}
2630
})
2731
);
@@ -76,7 +80,8 @@ export function activate(context: vscode.ExtensionContext) {
7680
}
7781
});
7882

79-
// Register health notifications toggle command
83+
84+
// Register health notifications toggle command (legacy command with confirmation)
8085
let toggleHealthCommand = vscode.commands.registerCommand('simpleCodingTimeTracker.toggleHealthNotifications', async () => {
8186
const config = vscode.workspace.getConfiguration('simpleCodingTimeTracker');
8287
const currentEnabled = config.get('health.enableNotifications', true);
@@ -100,8 +105,8 @@ export function activate(context: vscode.ExtensionContext) {
100105
await config.update('health.enableNotifications', !currentEnabled, vscode.ConfigurationTarget.Global);
101106

102107
const resultMessage = !currentEnabled ?
103-
' Health notifications enabled! You\'ll receive reminders for eye rest (20min), stretching (45min), and breaks (2h).' :
104-
' Health notifications disabled. No health reminders will be shown.';
108+
'$(bell) Health notifications enabled! You\'ll receive reminders for eye rest (20min), stretching (45min), and breaks (2h).' :
109+
'$(bell-slash) Health notifications disabled. No health reminders will be shown.';
105110

106111
vscode.window.showInformationMessage(resultMessage);
107112

src/notificationStatusBar.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import * as vscode from 'vscode';
2+
3+
export class NotificationStatusBar implements vscode.Disposable {
4+
private statusBarItem: vscode.StatusBarItem;
5+
private readonly commandId = 'simpleCodingTimeTracker.toggleNotifications';
6+
private statusBarReference?: any; // Reference to main status bar for updates
7+
8+
constructor() {
9+
// Create status bar item with priority 99 to appear immediately to the right of time tracker (priority 100)
10+
// Use very specific priority to minimize gap
11+
this.statusBarItem = vscode.window.createStatusBarItem(
12+
vscode.StatusBarAlignment.Left,
13+
99.9999
14+
);
15+
16+
this.statusBarItem.command = this.commandId;
17+
this.updateStatusBar();
18+
this.statusBarItem.show();
19+
}
20+
21+
private updateStatusBar(): void {
22+
const config = vscode.workspace.getConfiguration('simpleCodingTimeTracker');
23+
const isEnabled = config.get('health.enableNotifications', true);
24+
25+
// Use minimal text with no extra spaces
26+
this.statusBarItem.text = isEnabled ? '🔔' : '🔕';
27+
// this.statusBarItem.text = isEnabled ? '$(bell)' : '$(bell-dot)';
28+
this.statusBarItem.tooltip = `Health Notifications: ${isEnabled ? 'ON' : 'OFF'} (Click to toggle)`;
29+
30+
// Keep same background as time tracker for unified appearance
31+
this.statusBarItem.backgroundColor = new vscode.ThemeColor('statusBarItem.warningBackground');
32+
}
33+
34+
public async toggle(): Promise<void> {
35+
const config = vscode.workspace.getConfiguration('simpleCodingTimeTracker');
36+
const currentEnabled = config.get('health.enableNotifications', true);
37+
38+
// Toggle the setting
39+
await config.update('health.enableNotifications', !currentEnabled, vscode.ConfigurationTarget.Global);
40+
41+
// Update the main status bar display
42+
if (this.statusBarReference) {
43+
await this.statusBarReference.updateNow();
44+
}
45+
46+
// Show brief feedback message
47+
const status = !currentEnabled ? 'enabled' : 'disabled';
48+
const icon = !currentEnabled ? '🔔' : '🔕';
49+
vscode.window.showInformationMessage(`${icon} Health notifications ${status}`);
50+
}
51+
52+
public refresh(): void {
53+
this.updateStatusBar();
54+
// Also update the main status bar when configuration changes
55+
if (this.statusBarReference) {
56+
this.statusBarReference.updateNow();
57+
}
58+
}
59+
60+
public setStatusBarReference(statusBar: any): void {
61+
this.statusBarReference = statusBar;
62+
}
63+
64+
dispose(): void {
65+
this.statusBarItem.dispose();
66+
}
67+
}

src/statusBar.ts

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,20 @@ import { SummaryViewProvider } from './summaryView';
55

66
export class StatusBar implements vscode.Disposable {
77
private statusBarItem: vscode.StatusBarItem;
8+
private notificationItem: vscode.StatusBarItem;
89
private timeTracker: TimeTracker;
910
private summaryView: SummaryViewProvider;
1011
private updateInterval: NodeJS.Timeout;
1112
private readonly commandId = 'simpleCodingTimeTracker.manualSave';
13+
private readonly notificationCommandId = 'simpleCodingTimeTracker.toggleNotifications';
1214

1315
constructor(timeTracker: TimeTracker, summaryView: SummaryViewProvider) {
1416
this.timeTracker = timeTracker;
1517
this.summaryView = summaryView;
1618
this.statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 100);
19+
this.notificationItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 99.9999);
1720

18-
// Register manual save command first
21+
// Register manual save command (clicking anywhere saves session)
1922
const commandDisposable = vscode.commands.registerCommand(this.commandId, () => {
2023
if (this.timeTracker.isActive()) {
2124
// Save current session with manual save reason
@@ -29,27 +32,41 @@ export class StatusBar implements vscode.Disposable {
2932
}
3033
});
3134

32-
// Set up status bar item
35+
// Register notification toggle command
36+
const notificationCommandDisposable = vscode.commands.registerCommand(this.notificationCommandId, () => {
37+
this.toggleNotifications();
38+
});
39+
40+
41+
// Set up main status bar item
3342
this.statusBarItem.command = this.commandId;
3443
this.statusBarItem.tooltip = 'Click to save current session and show summary';
3544
this.statusBarItem.backgroundColor = new vscode.ThemeColor('statusBarItem.warningBackground');
3645
this.statusBarItem.show();
3746

47+
// Set up notification status bar item
48+
this.notificationItem.command = this.notificationCommandId;
49+
this.notificationItem.tooltip = 'Click to toggle health notifications';
50+
this.notificationItem.backgroundColor = new vscode.ThemeColor('statusBarItem.warningBackground');
51+
this.notificationItem.show();
52+
3853
void this.updateStatusBar();
3954
this.updateInterval = setInterval(() => void this.updateStatusBar(), 1000); // Update every second
4055
} private async updateStatusBar() {
4156
const todayTotal = await this.timeTracker.getTodayTotal();
4257
const currentProjectTime = await this.timeTracker.getCurrentProjectTime();
4358
const isActive = this.timeTracker.isActive();
4459

45-
// Check health notification status
46-
const config = vscode.workspace.getConfiguration('simpleCodingTimeTracker');
47-
const healthEnabled = config.get('health.enableNotifications', true);
48-
const healthIcon = healthEnabled ? '🔔' : '🔕';
60+
// Update main status bar (time tracker only)
61+
this.statusBarItem.text = `${isActive ? '💻' : '⏸️'} ${this.formatTime(todayTotal)}`;
62+
this.statusBarItem.tooltip = await this.getTooltipText(isActive, currentProjectTime);
4963

50-
// Show status with health notification indicator
51-
this.statusBarItem.text = `${isActive ? '💻' : '⏸️'} ${this.formatTime(todayTotal)} ${healthIcon}`;
52-
this.statusBarItem.tooltip = await this.getTooltipText(isActive, currentProjectTime, healthEnabled);
64+
// Update notification status bar
65+
const config = vscode.workspace.getConfiguration('simpleCodingTimeTracker');
66+
const notificationsEnabled = config.get('health.enableNotifications', true);
67+
const notificationIcon = notificationsEnabled ? '🔔' : '🔕';
68+
this.notificationItem.text = notificationIcon;
69+
this.notificationItem.tooltip = `Health Notifications: ${notificationsEnabled ? 'ON' : 'OFF'} (Click to toggle)`;
5370
}
5471

5572
private formatTime(minutes: number): string {
@@ -59,24 +76,44 @@ export class StatusBar implements vscode.Disposable {
5976
return `${hours.toString().padStart(2, '0')}:${mins.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`;
6077
}
6178

62-
private async getTooltipText(isActive: boolean, currentProjectTime: number, healthEnabled: boolean): Promise<string> {
79+
private async getTooltipText(isActive: boolean, currentProjectTime: number): Promise<string> {
6380
const weeklyTotal = await this.timeTracker.getWeeklyTotal();
6481
const monthlyTotal = await this.timeTracker.getMonthlyTotal();
6582
const allTimeTotal = await this.timeTracker.getAllTimeTotal();
6683
const currentBranch = this.timeTracker.getCurrentBranch();
6784
const currentProject = this.timeTracker.getCurrentProject();
6885

69-
const healthStatus = healthEnabled ? 'Health notifications: ON 🔔' : 'Health notifications: OFF 🔕';
70-
86+
const config = vscode.workspace.getConfiguration('simpleCodingTimeTracker');
87+
const notificationsEnabled = config.get('health.enableNotifications', true);
88+
const notificationStatus = notificationsEnabled ? 'ON' : 'OFF';
89+
7190
return `${isActive ? 'Active' : 'Paused'} - Coding Time
7291
Project: ${currentProject}
7392
Branch: ${currentBranch}
7493
Current Project Today: ${formatTime(currentProjectTime)}
7594
This week total: ${formatTime(weeklyTotal)}
7695
This month total: ${formatTime(monthlyTotal)}
7796
All Time total: ${formatTime(allTimeTotal)}
78-
${healthStatus}
79-
Click to show summary`;
97+
Notifications: ${notificationStatus}
98+
Click to save session and show summary`;
99+
}
100+
101+
102+
// Toggle notifications method
103+
private async toggleNotifications(): Promise<void> {
104+
const config = vscode.workspace.getConfiguration('simpleCodingTimeTracker');
105+
const currentEnabled = config.get('health.enableNotifications', true);
106+
107+
// Toggle the setting
108+
await config.update('health.enableNotifications', !currentEnabled, vscode.ConfigurationTarget.Global);
109+
110+
// Update the visual state
111+
await this.updateStatusBar();
112+
113+
// Show brief feedback message
114+
const status = !currentEnabled ? 'enabled' : 'disabled';
115+
const icon = !currentEnabled ? '🔔' : '🔕';
116+
vscode.window.showInformationMessage(`${icon} Health notifications ${status}`);
80117
}
81118

82119
// Public method to force immediate update
@@ -86,6 +123,7 @@ Click to show summary`;
86123

87124
dispose() {
88125
this.statusBarItem.dispose();
126+
this.notificationItem.dispose();
89127
clearInterval(this.updateInterval);
90128
}
91129
}

0 commit comments

Comments
 (0)