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

Fix/migrate3-deprecate #481

Merged
merged 3 commits into from
Nov 17, 2021
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
Binary file added .DS_Store
Binary file not shown.
12 changes: 6 additions & 6 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
"workbench.statusBar.visible": true,
"peacock.color": "1857a4",
"workbench.colorCustomizations": {
"sash.hoverBorder": "#1f6fd0",
"activityBar.activeBackground": "#1f6fd0",
"activityBar.activeBorder": "#ee90bb",
"activityBar.background": "#1f6fd0",
"sash.hoverBorder": "#1857a4",
"activityBar.activeBackground": "#1857a4",
"activityBar.activeBorder": "#530c2c",
"activityBar.background": "#1857a4",
"activityBar.foreground": "#e7e7e7",
"activityBar.inactiveForeground": "#e7e7e799",
"activityBarBadge.background": "#ee90bb",
"activityBarBadge.foreground": "#15202b",
"activityBarBadge.background": "#530c2c",
"activityBarBadge.foreground": "#e7e7e7",
"titleBar.activeBackground": "#1857a4",
"titleBar.activeForeground": "#e7e7e7",
"titleBar.inactiveBackground": "#1857a499",
Expand Down
Binary file removed docs/.vuepress/public/assets/affected-settings.jpg
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ features:
details: Color your Visual Studio Code editor uniquely when you are using the remote integration features.
- title: Live Share
details: Color your Visual Studio Code editor uniquely when you are in a Live Share session as a Guest or a Host
footer: MIT Licensed | Copyright © 2019-present John Papa | current version 3.11.0
footer: MIT Licensed | Copyright © 2019-present John Papa | current version 4.0.0
---
9 changes: 8 additions & 1 deletion docs/changelog/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ meta:

All notable changes to the code will be documented in this file.

## 4.0.0

- Deprecated - minimal risk
- Migration To Version < 4.0.0
- Version 3+ of Peacock stores the color in the settings `peacock.color`. When migrating from version 2.5, the peacock color was in a memento. When migrating from version < 2.5, the color was not stored, but can often be derived through a calculation by grabbing the color from one of the `workbench.colorCustomizations` that Peacock uses. Once the color is determined, peacock removes the memento, and writes the color to the settings `peacock.color`. Fixes [#230](https://github.com/johnpapa/vscode-peacock/issues/230) and addresses [#258](https://github.com/johnpapa/vscode-peacock/issues/258). This is an aggressive approach, as it is possible to have a color customization that peacock uses, and if it sees this, it will set Peacock up to use it. This logic is marked as deprecated but will not be removed until version 4.0 is released and enough time has passed reasonably for people to migrate. That time is now.
- If anyone has not yet migrated in the 2 years the migration existed, then Peacock will not set a color. This is easily fixed by the user using a Peacock command to set the color.

## 3.11.0

- [Granular control over accent borders](https://github.com/johnpapa/vscode-peacock/issues/472#issuecomment-945950855)
Expand Down Expand Up @@ -145,7 +152,7 @@ Fixes

- Migration occurs when colors are in user settings but not in workspace.
- Fixes [263](https://github.com/johnpapa/vscode-peacock/issues/263)
- During migration, Peacock is checking if the current workspace has a color set in the old style. This could be a `activityBar.background`, `titleBar.background`, or `statusBar.background`. PeacockVS Code's API merges default settings, users settings and workspace settings. Therefore, this migration logic was sometimes getting a migrating, and it should not. Peacock should only migrate to the new `peacock.color settings (which make sit much easier to determine what the color is definitively) if there is a color in the workspace settings. The fix for this was to write logic that gets the workspace colors only. This is done in a new function named`getWorkspaceColorIfExists`.
- During migration, Peacock is checking if the current workspace has a color set in the old style. This could be a `activityBar.background`, `titleBar.background`, or `statusBar.background`. VS Code's API merges default settings, users settings and workspace settings. Therefore, this migration logic was sometimes getting migrated, and it should not. Peacock should only migrate to the new `peacock.color settings (which makes it much easier to determine what the color is definitively) if there is a color in the workspace settings. The fix for this was to write logic that gets the workspace colors only. This is done in a new function named`getWorkspaceColorIfExists`.

Changes

Expand Down
61 changes: 6 additions & 55 deletions docs/guide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ Favorite colors require a user-defined name (`name`) and a value ( `value` ), as

When opening the Favorites command in the command palette, Peacock now previews (applies) the color as you cycle through them. If you cancel (press ESC), your colors revert to what you had prior to trying the Favorites command

![Animated GIF](/assets/named-colors.gif)
![favorites](/assets/named-colors.gif)

#### Save Favorite Color

Expand All @@ -121,9 +121,10 @@ The `Peacock: Save Current Color as Favorite Color` feature allows you to save t

### Affected Elements

You can tell peacock which parts of VS Code will be affected by when you select a color. You can do this by checking the appropriate setting that applies to the elements you want to be colored. The choices are:
You can tell peacock which parts of VS Code will be affected by when you select a color. You can do this by checking the appropriate setting that applies to the elements you want to be colored. These include examples such as affectEditorGroupBorder, affectPanelBorder, affectSideBarBorder, affectSashHover.

![affected elements](/assets/affected-settings.png)

![Animated GIF](/assets/affected-settings.jpg)

### Element Adjustments

Expand All @@ -146,7 +147,7 @@ An example of using this might be to make the Activity Bar slightly lighter than

This results in the Activity Bar being slightly lighter than the Status Bar and Title Bar (see below).

![Animated GIF](/assets/element-adjustments.png)
![Element Adjustments](/assets/element-adjustments.png)

### Keep Foreground Color

Expand Down Expand Up @@ -199,7 +200,7 @@ Peacock integrates with other extensions, as described in this section.

### VS Live Share Integration

![Animated GIF](/assets/peacock-live-share-demo.gif)
![live share](/assets/peacock-live-share-demo.gif)

Peacock detects when the [Live Share](https://marketplace.visualstudio.com/items?itemName=MS-vsliveshare.vsliveshare&wt.mc_id=vscodepeacock-github-jopapa) extension is installed and automatically adds two commands that allow the user to change color of their Live Share sessions as a Host or a Guest, depending on their role.

Expand Down Expand Up @@ -395,56 +396,6 @@ Peacock takes advantage of a memento (a value stored between sessions and not in
| -------------------------------- | ------ | ---------------------------------------------------------------------------------------------------------- |
| peacockMementos.favoritesVersion | Global | The version of Peacock. Helps identify when the list of favorites should be written to the user's settings |

## Migration

Migration notes between versions are documented here.

> Note: If at any time Peacock is writing colors unexpectedly, it may be due to a migration (see migration notes below). However, as always, you can run the command `Peacock: Reset Workspace Colors` and all color settings will be removed from the `.vscode/settings.json` file.

### To Version 3+

Version 3+ of Peacock stores the color in the settings `peacock.color`. When migrating from version 2.5, the peacock color was in a memento. When migrating from version < 2.5, the color was not stored, but can often be derived through a calculation by grabbing the color from one of the `workbench.colorCustomizations` that Peacock uses.

Once the color is determined, peacock removes the memento, and writes the color to the settings `peacock.color`. Fixes [#230](https://github.com/johnpapa/vscode-peacock/issues/230) and addresses [#258](https://github.com/johnpapa/vscode-peacock/issues/258)

This is an aggressive approach, as it is possible to have a color customization that peacock uses, and if it sees this, it will set Peacock up to use it.

This logic is marked as deprecated but will not be removed until version 4.0 is released and enough time has passed reasonably for people to migrate.

Examples:

1. If this is detected at startup with `#ff0`, then the `peacock.color` will bet set to match it.

```json
// .vscode/settings.json
{
"workbench.colorCustomizations": {
"activityBar.background": "#ff0"
}
}
```

2. If this is detected at startup and there is a peacock memento, then the `peacock.color` will set set to match the memento color.

```json
// .vscode/settings.json
{}
```

3. If this is detected at startup and there is no peacock memento, no migration will occur.

```json
// .vscode/settings.json
{}
```

4. If there already is a `peacock.color`, no migration will occur.

```json
// .vscode/settings.json
{}
```

## Try the Code

If you want to try the extension out start by cloning this repo, `cd` into the folder, and then run `npm install`.
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-peacock",
"displayName": "Peacock",
"description": "Subtly change the workspace color of your workspace. Ideal when you have multiple VS Code instances and you want to quickly identify which is which.",
"version": "3.11.0",
"version": "4.0.0",
"publisher": "johnpapa",
"license": "SEE LICENSE IN LICENSE.md",
"repository": {
Expand Down
44 changes: 0 additions & 44 deletions src/configuration/read-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,50 +437,6 @@ function getColorAndAdjustment(elementColors: IElementColors) {
return { color, adjustment };
}

export function getWorkspaceColorIfExists() {
// Get the workspace color customizations
const config = getColorCustomizationConfigFromWorkspace();

// Pull out just the three main colors from the workspace
const elementColors = {
[ElementNames.activityBar]: config[ColorSettings.activityBar_background],
[ElementNames.statusBar]: config[ColorSettings.statusBar_background],
[ElementNames.titleBar]: config[ColorSettings.titleBar_activeBackground],
};

if (!elementColors.activityBar && !elementColors.statusBar && !elementColors.titleBar) {
// There is no color
return undefined;
}

// Get the adjustments so we can reverse the affects of them
const elementAdjustments = getElementAdjustments();

// Calculate the colors without the adjustments
const originalElementColors: IElementColors = {
[ElementNames.activityBar]: getOriginalColor(
elementColors[ElementNames.activityBar],
elementAdjustments[ElementNames.activityBar],
),
[ElementNames.statusBar]: getOriginalColor(
elementColors[ElementNames.statusBar],
elementAdjustments[ElementNames.statusBar],
),
[ElementNames.titleBar]: getOriginalColor(
elementColors[ElementNames.titleBar],
elementAdjustments[ElementNames.titleBar],
),
};

// We just want one color, so we an realistically calculate what that color is
const color =
originalElementColors.activityBar ||
originalElementColors.statusBar ||
originalElementColors.titleBar;

return color;
}

export function getOriginalColorsForAllElements() {
const config = getColorCustomizationConfig();
// const config = getColorCustomizationConfigFromWorkspace(); // TODO: do we always only want workspac colors?
Expand Down
9 changes: 0 additions & 9 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import { Logger } from './logging';
import { addLiveShareIntegration } from './live-share';
import { addRemoteIntegration } from './remote';
import { saveFavoritesVersionGlobalMemento, getMementos } from './mementos';
import { migrateFromMementoToSettingsAsNeeded } from './migration';

const { commands, workspace } = vscode;

Expand All @@ -50,14 +49,6 @@ export async function activate(context: vscode.ExtensionContext) {
await initializeTheStarterSetOfFavorites();

if (workspace.workspaceFolders) {
/**
* Check if we need to migrate.
* If we do migrate, we write to the settings,
* so we need to do this after we are already
* listening for settings changes.
*/
await migrateFromMementoToSettingsAsNeeded();

Logger.info('Peacock is in a workspace, so Peacock functionality is available.');
/**
* We only run this logic if we are in a workspace
Expand Down
52 changes: 0 additions & 52 deletions src/migration.ts

This file was deleted.

41 changes: 19 additions & 22 deletions testworkspace/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
// Place your settings in this file to overwrite default and user settings.
{
"peacock.cacheBust": "827478",
"peacock.color": "#dd0531",
"peacock.color": "#f9e64f",
"workbench.colorCustomizations": {
"activityBar.activeBackground": "#fa1b49",
"activityBar.activeBorder": "#155e02",
"activityBar.background": "#fa1b49",
"activityBar.foreground": "#e7e7e7",
"activityBar.inactiveForeground": "#e7e7e799",
"activityBarBadge.background": "#155e02",
"activityBarBadge.foreground": "#e7e7e7",
"editorGroup.border": "#fa1b49",
"panel.border": "#fa1b49",
"sash.hoverBorder": "#fa1b49",
"sideBar.border": "#fa1b49",
"statusBar.background": "#dd0531",
"statusBar.foreground": "#e7e7e7",
"statusBarItem.hoverBackground": "#fa1b49",
"statusBarItem.remoteBackground": "#dd0531",
"statusBarItem.remoteForeground": "#e7e7e7",
"titleBar.activeBackground": "#dd0531",
"titleBar.activeForeground": "#e7e7e7",
"titleBar.inactiveBackground": "#dd053199",
"titleBar.inactiveForeground": "#e7e7e799"
"activityBar.activeBackground": "#fbed80",
"activityBar.activeBorder": "#06b9a5",
"activityBar.background": "#fbed80",
"activityBar.foreground": "#15202b",
"activityBar.inactiveForeground": "#15202b99",
"activityBarBadge.background": "#06b9a5",
"activityBarBadge.foreground": "#15202b",
"sash.hoverBorder": "#fbed80",
"statusBar.background": "#f9e64f",
"statusBar.foreground": "#15202b",
"statusBarItem.hoverBackground": "#f7df1e",
"statusBarItem.remoteBackground": "#f9e64f",
"statusBarItem.remoteForeground": "#15202b",
"titleBar.activeBackground": "#f9e64f",
"titleBar.activeForeground": "#15202b",
"titleBar.inactiveBackground": "#f9e64f99",
"titleBar.inactiveForeground": "#15202b99"
},
"peacock.remoteColor": ""
}
}