@@ -82,18 +82,24 @@ export class SettingsViewProvider {
8282 const config = vscode . workspace . getConfiguration ( 'simpleCodingTimeTracker' ) ;
8383
8484 try {
85- // Most settings should be saved to Workspace scope (default behavior in package.json)
86- await config . update ( 'inactivityTimeout' , settings . inactivityTimeout , vscode . ConfigurationTarget . Workspace ) ;
87- await config . update ( 'focusTimeout' , settings . focusTimeout , vscode . ConfigurationTarget . Workspace ) ;
88- await config . update ( 'statusBar.showSeconds' , settings . statusBarShowSeconds , vscode . ConfigurationTarget . Workspace ) ;
89- await config . update ( 'statusBar.icon' , settings . statusBarIcon , vscode . ConfigurationTarget . Workspace ) ;
90- await config . update ( 'statusBar.backgroundStyle' , settings . statusBarBackgroundStyle , vscode . ConfigurationTarget . Workspace ) ;
91- await config . update ( 'statusBar.color' , settings . statusBarColor , vscode . ConfigurationTarget . Workspace ) ;
92- await config . update ( 'health.enableNotifications' , settings . healthEnableNotifications , vscode . ConfigurationTarget . Workspace ) ;
93- await config . update ( 'health.modalNotifications' , settings . healthModalNotifications , vscode . ConfigurationTarget . Workspace ) ;
94- await config . update ( 'health.eyeRestInterval' , settings . healthEyeRestInterval , vscode . ConfigurationTarget . Workspace ) ;
95- await config . update ( 'health.stretchInterval' , settings . healthStretchInterval , vscode . ConfigurationTarget . Workspace ) ;
96- await config . update ( 'health.breakThreshold' , settings . healthBreakThreshold , vscode . ConfigurationTarget . Workspace ) ;
85+ // Determine the target scope: Workspace if available, otherwise Global
86+ // This prevents "Unable to write to Workspace Settings because no workspace is opened" error
87+ const hasWorkspace = vscode . workspace . workspaceFile !== undefined ;
88+ const configTarget = hasWorkspace ? vscode . ConfigurationTarget . Workspace : vscode . ConfigurationTarget . Global ;
89+
90+ // Most settings should be saved to Workspace scope if available (default behavior in package.json)
91+ // Otherwise fall back to Global scope
92+ await config . update ( 'inactivityTimeout' , settings . inactivityTimeout , configTarget ) ;
93+ await config . update ( 'focusTimeout' , settings . focusTimeout , configTarget ) ;
94+ await config . update ( 'statusBar.showSeconds' , settings . statusBarShowSeconds , configTarget ) ;
95+ await config . update ( 'statusBar.icon' , settings . statusBarIcon , configTarget ) ;
96+ await config . update ( 'statusBar.backgroundStyle' , settings . statusBarBackgroundStyle , configTarget ) ;
97+ await config . update ( 'statusBar.color' , settings . statusBarColor , configTarget ) ;
98+ await config . update ( 'health.enableNotifications' , settings . healthEnableNotifications , configTarget ) ;
99+ await config . update ( 'health.modalNotifications' , settings . healthModalNotifications , configTarget ) ;
100+ await config . update ( 'health.eyeRestInterval' , settings . healthEyeRestInterval , configTarget ) ;
101+ await config . update ( 'health.stretchInterval' , settings . healthStretchInterval , configTarget ) ;
102+ await config . update ( 'health.breakThreshold' , settings . healthBreakThreshold , configTarget ) ;
97103
98104 // Only enableDevCommands has "scope": "application" in package.json, so it must be saved to Global
99105 await config . update ( 'enableDevCommands' , settings . enableDevCommands , vscode . ConfigurationTarget . Global ) ;
@@ -118,15 +124,22 @@ export class SettingsViewProvider {
118124 const config = vscode . workspace . getConfiguration ( 'simpleCodingTimeTracker' ) ;
119125
120126 try {
121- // Reset workspace-scoped settings
122- await config . update ( 'inactivityTimeout' , undefined , vscode . ConfigurationTarget . Workspace ) ;
123- await config . update ( 'focusTimeout' , undefined , vscode . ConfigurationTarget . Workspace ) ;
124- await config . update ( 'statusBar.showSeconds' , undefined , vscode . ConfigurationTarget . Workspace ) ;
125- await config . update ( 'health.enableNotifications' , undefined , vscode . ConfigurationTarget . Workspace ) ;
126- await config . update ( 'health.modalNotifications' , undefined , vscode . ConfigurationTarget . Workspace ) ;
127- await config . update ( 'health.eyeRestInterval' , undefined , vscode . ConfigurationTarget . Workspace ) ;
128- await config . update ( 'health.stretchInterval' , undefined , vscode . ConfigurationTarget . Workspace ) ;
129- await config . update ( 'health.breakThreshold' , undefined , vscode . ConfigurationTarget . Workspace ) ;
127+ // Determine the target scope: Workspace if available, otherwise Global
128+ const hasWorkspace = vscode . workspace . workspaceFile !== undefined ;
129+ const configTarget = hasWorkspace ? vscode . ConfigurationTarget . Workspace : vscode . ConfigurationTarget . Global ;
130+
131+ // Reset workspace-scoped settings (or global if no workspace)
132+ await config . update ( 'inactivityTimeout' , undefined , configTarget ) ;
133+ await config . update ( 'focusTimeout' , undefined , configTarget ) ;
134+ await config . update ( 'statusBar.showSeconds' , undefined , configTarget ) ;
135+ await config . update ( 'statusBar.icon' , undefined , configTarget ) ;
136+ await config . update ( 'statusBar.backgroundStyle' , undefined , configTarget ) ;
137+ await config . update ( 'statusBar.color' , undefined , configTarget ) ;
138+ await config . update ( 'health.enableNotifications' , undefined , configTarget ) ;
139+ await config . update ( 'health.modalNotifications' , undefined , configTarget ) ;
140+ await config . update ( 'health.eyeRestInterval' , undefined , configTarget ) ;
141+ await config . update ( 'health.stretchInterval' , undefined , configTarget ) ;
142+ await config . update ( 'health.breakThreshold' , undefined , configTarget ) ;
130143
131144 // Reset global-scoped settings
132145 await config . update ( 'enableDevCommands' , undefined , vscode . ConfigurationTarget . Global ) ;
0 commit comments