Skip to content

Commit

Permalink
fix default opacity on invert, fix install reload
Browse files Browse the repository at this point in the history
  • Loading branch information
Katsute committed Aug 17, 2024
1 parent b2eda95 commit 8f5cb08
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
* Bump @types/node from 22.1.0 to 22.2.0 [#388](https://github.com/KatsuteDev/Background/pull/388) ([@dependabot](https://github.com/dependabot))
* Bump @types/node from 22.2.0 to 22.3.0 [#389](https://github.com/KatsuteDev/Background/pull/389) ([@dependabot](https://github.com/dependabot))
* Bump @vscode/vsce from 2.31.1 to 2.32.0 [#390](https://github.com/KatsuteDev/Background/pull/390) ([@dependabot](https://github.com/dependabot))
* Bump @types/node from 22.3.0 to 22.4.0 [#391](https://github.com/KatsuteDev/Background/pull/391) ([@dependabot](https://github.com/dependabot))
* Bump esbuild from 0.23.0 to 0.23.1 [#393](https://github.com/KatsuteDev/Background/pull/393) ([@dependabot](https://github.com/dependabot))
* Bump @vscode/vsce from 2.32.0 to 3.0.0 [#392](https://github.com/KatsuteDev/Background/pull/392) ([@dependabot](https://github.com/dependabot))

**Full Changelog**: [`2.10.4...3.0.0`](https://github.com/KatsuteDev/Background/compare/2.10.4...3.0.0)

Expand Down
35 changes: 33 additions & 2 deletions package-lock.json

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

14 changes: 7 additions & 7 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,15 @@ export const activate: (context: ExtensionContext) => any = (context: ExtensionC

// migrate

if(!configuration().has("useInvertedOpacity")){
commands.executeCommand("workbench.action.reloadWindow"); // outdated manifest, force reload
}

if(context.globalState.get("migratedOpacity") !== true){ // if not yet migrated
if(get("backgroundOpacity", {scope: "global", includeDefault: false})){ // has opacity set
if(configuration().has("useInvertedOpacity")){
update("useInvertedOpacity", true, undefined, true) // update setting
.then(() => context.globalState.update("migratedOpacity", true)) // set migrated (changed)
.then(() => window.showInformationMessage("Background opacity settings have been migrated to the latest version."));
}else{
commands.executeCommand("workbench.action.reloadWindow"); // outdated manifest, force reload
}
update("useInvertedOpacity", true, undefined, true) // update setting
.then(() => context.globalState.update("migratedOpacity", true)) // set migrated (changed)
.then(() => window.showInformationMessage("Background opacity settings have been migrated to the latest version."));
}else{
context.globalState.update("migratedOpacity", true); // set migrated (no change)
}
Expand Down
7 changes: 6 additions & 1 deletion src/extension/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ export const get: (key: ConfigurationKey, options?: {
default: option!.defaultValue
};

// default override for inverted
if(key === "backgroundOpacity" && get("useInvertedOpacity")){
values.default = [0.9, 0.9, 0.9, 0.9];
}

let value: any;

value = Array.isArray(values.default) && (scope === "workspace" || target() === ConfigurationTarget.Workspace)
Expand All @@ -72,7 +77,7 @@ export const get: (key: ConfigurationKey, options?: {

value ??= includeDefault ? values.default : undefined; // assign default if current value is undefined and includeDefault is true

if(Array.isArray(values.default)){ // background[,,,] setting
if(Array.isArray(values.default) && Array.isArray(value)){ // background[,,,] setting
if(values.default.length === 0){ // backgrounds[]
return value;
}else if(ui){ // background setting[,,,]
Expand Down
2 changes: 1 addition & 1 deletion src/menu/opacity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const show: (ui: UI) => void = (ui: UI) => {
title: title("Opacity", ui),
placeHolder: "Background opacity",
value: current.toString(),
prompt: `Background opacity (${current}). 0 is fully visible and 1 is invisible.`,
prompt: `Background opacity (${current}). ${(get("useInvertedOpacity") ? 0 : 1)} is fully visible and ${(get("useInvertedOpacity") ? 1 : 0)} is invisible.`,
validateInput: (value: string) => {
if(isNaN(+value))
return "Not a number";
Expand Down

0 comments on commit 8f5cb08

Please sign in to comment.