Skip to content
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/node_modules
/dist

/.vscode-test
.vscode-test

/test/__*

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ Use the <kbd>Background: Configuration</kbd> command or press the **Background**
|Smooth Image Rendering|Use smooth image rendering when resizing images instead of pixelated|
|Setting Scope|Where to save background settings - Global or Workspace|
|CSS|Custom CSS|
|API|Toggles API access|

<div align="right"><a href="#top"><code>▲</code></a></div>

Expand All @@ -127,6 +128,8 @@ If the path is not working, add an additional `/` after the variable.

### API

*Requires API setting to be turned on in the extension*

Add this extension to your `package.json`.

```json
Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,12 @@
"type": "string",
"editPresentation": "multilineText",
"default": ""
},
"background.API": {
"markdownDescription": "Enable API access.",
"order": 18,
"type": "boolean",
"default": false
}
}
}
Expand Down
95 changes: 54 additions & 41 deletions src/extension/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,57 +18,70 @@

import { commands } from "vscode";
import { add, get, remove, replace } from "../menu/file";
import { get as cget } from "./config";
import { reload } from "../lib/vscode";

export const api = {
install: () => commands.executeCommand("background.install"),
uninstall: () => commands.executeCommand("background.uninstall"),
install: () => cget("API") && commands.executeCommand("background.install"),
uninstall: () => cget("API") && commands.executeCommand("background.uninstall"),
reload,
get: (ui: string) => {
switch(ui){
case "window":
case "editor":
case "sidebar":
case "panel":
return get(ui);
default:
return undefined;
}
if(cget("API"))
switch(ui){
case "window":
case "editor":
case "sidebar":
case "panel":
return get(ui);
default:
return undefined;
}
else
return undefined;
},
add: async (ui: string, glob: string) => {
switch(ui){
case "window":
case "editor":
case "sidebar":
case "panel":
await add(ui, glob, true);
return true;
default:
return false;
}
if(cget("API"))
switch(ui){
case "window":
case "editor":
case "sidebar":
case "panel":
await add(ui, glob, true);
return true;
default:
return false;
}
else
return false;
},
replace: async (ui: string, old: string, glob: string) => {
switch(ui){
case "window":
case "editor":
case "sidebar":
case "panel":
await replace(ui, old, glob, true);
return true;
default:
return false;
}
if(cget("API"))
switch(ui){
case "window":
case "editor":
case "sidebar":
case "panel":
await replace(ui, old, glob, true);
return true;
default:
return false;
}
else
return false;
},
remove: async (ui: string, glob: string) => {
switch(ui){
case "window":
case "editor":
case "sidebar":
case "panel":
await remove(ui, glob, true);
return true;
default:
return false;
}
if(cget("API"))
switch(ui){
case "window":
case "editor":
case "sidebar":
case "panel":
await remove(ui, glob, true);
return true;
default:
return false;
}
else
return false;
}
}
3 changes: 2 additions & 1 deletion src/extension/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export type ConfigurationKey =
"useInvertedOpacity" |
"settingScope" |
"smoothImageRendering" |
"CSS";
"CSS" |
"API";

export type Contributes = {
commands: [{
Expand Down
6 changes: 6 additions & 0 deletions src/menu/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ const moreMenu: (selected?: number) => void = (selected?: number) => {
detail: "Where to save settings; workspace requires Auto Install to update background on switch",
handle: () => update("settingScope", get("settingScope") === "Global" ? "Workspace" : "Global").then(() => moreMenu(i++))
}),
quickPickItem({
label: "API",
description: descriptionBool("API"),
detail: "Enable/disable API access",
handle: handleBool("API", i++)
}),
separator(),
quickPickItem({
label: "$(output) Changelog",
Expand Down
2 changes: 1 addition & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const file = path.join(__dirname, "__testno__");

const vscode = require("@vscode/test-electron");

!fs.existsSync(file) || fs.unlinkSync(file);
// !fs.existsSync(file) || fs.unlinkSync(file);

vscode.runTests({
extensionDevelopmentPath: path.join(__dirname, "../"),
Expand Down
6 changes: 5 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const images = path.join(__dirname, "*.png").replace(/\\/g, '/');

module.exports = {
run: () => new Promise(async () => {
await vscode.workspace.getConfiguration('background').update('API', true, vscode.ConfigurationTarget.Global);

await wait(5);

const background = vscode.extensions.getExtension("katsute.code-background").exports;
Expand All @@ -20,7 +22,7 @@ module.exports = {
await background.remove(ui, image);
fs.writeFileSync(file, '0', "utf-8");
background.install();
}else if((num = fs.readFileSync(file, "utf-8")) === 0){
}else if((num = parseInt(fs.readFileSync(file, "utf-8"))) === 0){
vscode.window.showInformationMessage("Testing empty install");

await wait(3);
Expand Down Expand Up @@ -74,6 +76,8 @@ module.exports = {

vscode.window.showInformationMessage(`All tests completed!\n\nBackgrounds are: \nwindow: [${await background.get("window")}]\neditor: [${await background.get("editor")}]\nsidebar: [${await background.get("sidebar")}]\npanel: [${await background.get("panel")}]`);

await vscode.workspace.getConfiguration('background').update('API', false, vscode.ConfigurationTarget.Global);

fs.unlinkSync(file);
}
})
Expand Down
Loading