Skip to content

Commit 9f6ae85

Browse files
committed
Fix activation if setting doesn't exist
1 parent 12372a7 commit 9f6ae85

File tree

1 file changed

+61
-53
lines changed

1 file changed

+61
-53
lines changed

extension/index.js

Lines changed: 61 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -515,38 +515,42 @@ function activate(context) {
515515
autoDetectColorScheme: currentAutoDetectColorScheme,
516516
};
517517
}
518-
519-
// Remove "workbench.colorCustomizations" from applyToAllProfiles if it's there to fix an issue this caused with profiles
520-
if (!previousCustomizations.removedFromApplyToAllProfiles && currentApplyToAllProfiles.includes("workbench.colorCustomizations")) {
521-
const updatedApplyToAllProfiles = currentApplyToAllProfiles.filter(setting => setting !== "workbench.colorCustomizations");
522-
await vscode.workspace.getConfiguration().update("workbench.settings.applyToAllProfiles", updatedApplyToAllProfiles, vscode.ConfigurationTarget.Global);
523-
524-
// Notify user of the change
525-
vscode.window.showInformationMessage(localize('messages.applyToAllProfiles'));
526-
527-
}
528-
// Ensure this fix is only applied once
529-
previousCustomizations.removedFromApplyToAllProfiles = true;
530-
531-
// Update settings if necessary
532-
if (currentBackground !== "#00000000" || currentGpuAcceleration !== "off") {
533-
const newColorCustomization = {
534-
...currentColorCustomizations,
535-
"terminal.background": "#00000000"
536-
};
518+
519+
try {
520+
// Remove "workbench.colorCustomizations" from applyToAllProfiles if it's there to fix an issue this caused with profiles
521+
if (!previousCustomizations.removedFromApplyToAllProfiles && currentApplyToAllProfiles.includes("workbench.colorCustomizations")) {
522+
const updatedApplyToAllProfiles = currentApplyToAllProfiles.filter(setting => setting !== "workbench.colorCustomizations");
523+
await vscode.workspace.getConfiguration().update("workbench.settings.applyToAllProfiles", updatedApplyToAllProfiles, vscode.ConfigurationTarget.Global);
524+
525+
// Notify user of the change
526+
vscode.window.showInformationMessage(localize('messages.applyToAllProfiles'));
527+
528+
}
529+
// Ensure this fix is only applied once
530+
previousCustomizations.removedFromApplyToAllProfiles = true;
531+
532+
// Update settings if necessary
533+
if (currentBackground !== "#00000000" || currentGpuAcceleration !== "off") {
534+
const newColorCustomization = {
535+
...currentColorCustomizations,
536+
"terminal.background": "#00000000"
537+
};
538+
}
537539

538540
await vscode.workspace.getConfiguration().update("workbench.colorCustomizations", newColorCustomization, vscode.ConfigurationTarget.Global);
539541
await vscode.workspace.getConfiguration().update("terminal.integrated.gpuAcceleration", "off", vscode.ConfigurationTarget.Global);
540-
}
541542

542-
if (enableAutoTheme) {
543-
// Allow VSCode to auto-detect the color theme
544-
vscode.workspace.getConfiguration().update("window.systemColorTheme", undefined, vscode.ConfigurationTarget.Global);
545-
vscode.workspace.getConfiguration().update("window.autoDetectColorScheme", true, vscode.ConfigurationTarget.Global);
546-
} else {
547-
// Sync VSCode color theme with Vibrancy theme
548-
vscode.workspace.getConfiguration().update("window.systemColorTheme", themeConfig.systemColorTheme, vscode.ConfigurationTarget.Global);
549-
vscode.workspace.getConfiguration().update("window.autoDetectColorScheme", false, vscode.ConfigurationTarget.Global);
543+
if (enableAutoTheme) {
544+
// Allow VSCode to auto-detect the color theme
545+
vscode.workspace.getConfiguration().update("window.systemColorTheme", undefined, vscode.ConfigurationTarget.Global);
546+
vscode.workspace.getConfiguration().update("window.autoDetectColorScheme", true, vscode.ConfigurationTarget.Global);
547+
} else {
548+
// Sync VSCode color theme with Vibrancy theme
549+
vscode.workspace.getConfiguration().update("window.systemColorTheme", themeConfig.systemColorTheme, vscode.ConfigurationTarget.Global);
550+
vscode.workspace.getConfiguration().update("window.autoDetectColorScheme", false, vscode.ConfigurationTarget.Global);
551+
}
552+
} catch (error) {
553+
console.error("Error updating settings:", error);
550554
}
551555

552556
// Save user customizations
@@ -557,38 +561,42 @@ function activate(context) {
557561
async function restorePreviousSettings() {
558562
const previousCustomizations = context.globalState.get('customizations');
559563

560-
// Delete terminal.background from workbench.colorCustomizations if it's #00000000
561-
const terminalColorConfig = vscode.workspace.getConfiguration().inspect("workbench.colorCustomizations");
562-
const currentColorCustomizations = terminalColorConfig?.globalValue || {};
563-
if (currentColorCustomizations["terminal.background"] === "#00000000") {
564-
delete currentColorCustomizations["terminal.background"];
565-
await vscode.workspace.getConfiguration().update("workbench.colorCustomizations", currentColorCustomizations, vscode.ConfigurationTarget.Global);
566-
}
567-
568-
if (previousCustomizations?.saved) {
569-
// Restore only the specific keys we modified
564+
try {
565+
// Delete terminal.background from workbench.colorCustomizations if it's #00000000
570566
const terminalColorConfig = vscode.workspace.getConfiguration().inspect("workbench.colorCustomizations");
571567
const currentColorCustomizations = terminalColorConfig?.globalValue || {};
568+
if (currentColorCustomizations["terminal.background"] === "#00000000") {
569+
delete currentColorCustomizations["terminal.background"];
570+
await vscode.workspace.getConfiguration().update("workbench.colorCustomizations", currentColorCustomizations, vscode.ConfigurationTarget.Global);
571+
}
572572

573-
if (previousCustomizations.terminalBackground !== undefined) {
574-
const restoredColorCustomizations = { ...currentColorCustomizations };
575-
if (previousCustomizations.terminalBackground === null || previousCustomizations.terminalBackground === "#00000000") {
576-
delete restoredColorCustomizations["terminal.background"];
577-
} else {
578-
restoredColorCustomizations["terminal.background"] = previousCustomizations.terminalBackground;
573+
if (previousCustomizations?.saved) {
574+
// Restore only the specific keys we modified
575+
const terminalColorConfig = vscode.workspace.getConfiguration().inspect("workbench.colorCustomizations");
576+
const currentColorCustomizations = terminalColorConfig?.globalValue || {};
577+
578+
if (previousCustomizations.terminalBackground !== undefined) {
579+
const restoredColorCustomizations = { ...currentColorCustomizations };
580+
if (previousCustomizations.terminalBackground === null || previousCustomizations.terminalBackground === "#00000000") {
581+
delete restoredColorCustomizations["terminal.background"];
582+
} else {
583+
restoredColorCustomizations["terminal.background"] = previousCustomizations.terminalBackground;
584+
}
585+
await vscode.workspace.getConfiguration().update("workbench.colorCustomizations", restoredColorCustomizations, vscode.ConfigurationTarget.Global);
579586
}
580-
await vscode.workspace.getConfiguration().update("workbench.colorCustomizations", restoredColorCustomizations, vscode.ConfigurationTarget.Global);
581-
}
582587

583-
await vscode.workspace.getConfiguration().update("terminal.integrated.gpuAcceleration", previousCustomizations.gpuAcceleration, vscode.ConfigurationTarget.Global);
584-
await vscode.workspace.getConfiguration().update("window.systemColorTheme", previousCustomizations.systemColorTheme, vscode.ConfigurationTarget.Global);
585-
await vscode.workspace.getConfiguration().update("window.autoDetectColorScheme", previousCustomizations.autoDetectColorScheme, vscode.ConfigurationTarget.Global);
588+
await vscode.workspace.getConfiguration().update("terminal.integrated.gpuAcceleration", previousCustomizations.gpuAcceleration, vscode.ConfigurationTarget.Global);
589+
await vscode.workspace.getConfiguration().update("window.systemColorTheme", previousCustomizations.systemColorTheme, vscode.ConfigurationTarget.Global);
590+
await vscode.workspace.getConfiguration().update("window.autoDetectColorScheme", previousCustomizations.autoDetectColorScheme, vscode.ConfigurationTarget.Global);
586591

587-
// Preserve the removedFromApplyToAllProfiles flag
588-
const removedFromApplyToAllProfiles = previousCustomizations.removedFromApplyToAllProfiles;
592+
// Preserve the removedFromApplyToAllProfiles flag
593+
const removedFromApplyToAllProfiles = previousCustomizations.removedFromApplyToAllProfiles;
589594

590-
// Clear saved state but preserve the removedFromApplyToAllProfiles flag
591-
await context.globalState.update('customizations', { removedFromApplyToAllProfiles });
595+
// Clear saved state but preserve the removedFromApplyToAllProfiles flag
596+
await context.globalState.update('customizations', { removedFromApplyToAllProfiles });
597+
}
598+
} catch (error) {
599+
console.error("Error updating settings:", error);
592600
}
593601
}
594602

0 commit comments

Comments
 (0)