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 install notification sometimes not installing backgrounds #66

Merged
merged 1 commit into from
Nov 23, 2022
Merged
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
41 changes: 17 additions & 24 deletions src/command/config/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,25 @@ import { sn } from "../../lib/str";

// config

const add: (ui: UI, glob: string) => void = (ui: UI, glob: string) => {
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);
update(`${ui}Backgrounds`, files.filter(unique))
.then(() => cm({label: '␀', ui})); // reopen menu
await update(`${ui}Backgrounds`, files.filter(unique), undefined, skipWarning);
cm({label: '␀', ui}); // reopen menu
};

const replace: (ui: UI, old: string, glob: string, remove?: boolean) => void = (ui: UI, old: string, glob: string) => {
const replace: (ui: UI, old: string, glob: string, remove?: boolean) => 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)
files[i] = glob;
update(`${ui}Backgrounds`, files.filter(unique), undefined, old === glob)
.then(() => cm({label: '␀', ui})); // reopen menu
await update(`${ui}Backgrounds`, files.filter(unique), undefined, old === glob);
cm({label: '␀', ui}); // reopen menu
};

const remove: (ui: UI, glob: string) => void = (ui: UI, glob: string) => {
update(
`${ui}Backgrounds`,
(get(`${ui}Backgrounds`) as string[])
.filter((f) => f !== glob)
.filter(unique)
)
.then(() => cm({label: '␀', ui})); // reopen files
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
};

// exts
Expand Down Expand Up @@ -116,11 +111,10 @@ export const menu: (item: CommandQuickPickItem) => void = (item: CommandQuickPic
openLabel: "Select Image",
filters: {"Images": extensions()}
}).then((files?: vscode.Uri[]) => {
if(files){
for(const file of files)
add(item.ui!, file.fsPath.replace(/\\/g, '/'));
files.length > 0 && notify();
}
if(files)
Promise
.all(files.map(file => add(item.ui!, file.fsPath.replace(/\\/g, '/'), true)))
.then(() => files.length > 0 && notify());
});
}
}),
Expand All @@ -134,11 +128,10 @@ export const menu: (item: CommandQuickPickItem) => void = (item: CommandQuickPic
canSelectMany: true,
openLabel: "Select Folder"
}).then((files?: vscode.Uri[]) => {
if(files){
for(const file of files)
add(item.ui!, `${file.fsPath.replace(/\\/g, '/')}/**`);
files.length > 0 && notify();
}
if(files)
Promise
.all(files.map(file => add(item.ui!, `${file.fsPath.replace(/\\/g, '/')}/**`, true)))
.then(() => files.length > 0 && notify());
});
}
}),
Expand Down