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

Add extension API #176

Merged
merged 7 commits into from
Jul 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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 @@ -8,7 +8,7 @@
"theme": "dark"
},
"publisher": "Katsute",
"version": "2.5.8",
"version": "2.6.0",
"private": true,
"engines": {
"vscode": "^1.80.0"
Expand Down
10 changes: 7 additions & 3 deletions src/command/config/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,18 @@ import { notify } from "../install";

// config

const add: (ui: UI, glob: string, skipWarning?: boolean) => Promise<void> = async (ui: UI, glob: string, skipWarning: boolean = false) => {
export const view: (ui: UI) => string[] = (ui: UI) => {
return get(`${ui}Backgrounds`) as string[];
}

export const add: (ui: UI, glob: string, skipWarning?: boolean) => Promise<void> = async (ui: UI, glob: string, skipWarning: boolean = false) => {
const files: string[] = get(`${ui}Backgrounds`) as string[];
files.push(glob);
await update(`${ui}Backgrounds`, files.filter(unique), undefined, skipWarning);
skipWarning || cm({label: '␀', ui}); // reopen menu
};

const replace: (ui: UI, old: string, glob: string, remove?: boolean) => Promise<void> = async (ui: UI, old: string, glob: string) => {
export const replace: (ui: UI, old: string, glob: string) => Promise<void> = async (ui: UI, old: string, glob: string) => {
const files: string[] = get(`${ui}Backgrounds`) as string[];
for(let i = 0, l = files.length; i < l; i++)
if(files[i] === old)
Expand All @@ -47,7 +51,7 @@ const replace: (ui: UI, old: string, glob: string, remove?: boolean) => Promise<
cm({label: '␀', ui}); // reopen menu
};

const remove: (ui: UI, glob: string) => Promise<void> = async (ui: UI, glob: string) => {
export const remove: (ui: UI, glob: string) => Promise<void> = async (ui: UI, glob: string) => {
await update(`${ui}Backgrounds`, (get(`${ui}Backgrounds`) as string[]).filter((f) => f !== glob).filter(unique));
cm({label: '␀', ui}); // reopen files
};
Expand Down
52 changes: 51 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const cp: (files: [string, string][], asterisk?: boolean) => string = (files: [s
return commands.join(" && ");
};

export const activate: (context: vscode.ExtensionContext) => void = (context: vscode.ExtensionContext) => {
export const activate: (context: vscode.ExtensionContext) => any = (context: vscode.ExtensionContext) => {
// internal files
if(require.main && require.main.filename){
// %appdata%/Local/Programs/Microsoft VS Code/resources/app/out/vs/workbench/workbench.desktop.main.js
Expand Down Expand Up @@ -110,6 +110,56 @@ export const activate: (context: vscode.ExtensionContext) => void = (context: vs

context.subscriptions.push(statusbar);
statusbar.show();

return {
get: (ui: string) => {
switch(ui){
case "window":
case "editor":
case "sidebar":
case "panel":
return file.view(ui);
default:
return undefined;
}
},
add: async (ui: string, glob: string) => {
switch(ui){
case "window":
case "editor":
case "sidebar":
case "panel":
await file.add(ui, glob);
return true;
default:
return false;
}
},
replace: async (ui: string, old: string, glob: string) => {
switch(ui){
case "window":
case "editor":
case "sidebar":
case "panel":
await file.replace(ui, old, glob);
return true;
default:
return false;
}
},
remove: async (ui: string, glob: string) => {
switch(ui){
case "window":
case "editor":
case "sidebar":
case "panel":
await file.remove(ui, glob);
return true;
default:
return false;
}
}
}
Fixed Show fixed Hide fixed
};

//
Expand Down