Skip to content

Commit

Permalink
fix: attemp to fix multiple added status bar
Browse files Browse the repository at this point in the history
fix #45
  • Loading branch information
Mara-Li committed Nov 27, 2022
1 parent 13abc47 commit 0e322fd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
10 changes: 5 additions & 5 deletions plugin/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ export async function shareAllMarkedNotes(PublisherManager: GithubBranch, settin
* @param sharedFiles File marked to true
* @param createGitHubBranch prevent to multiple creation of branch if already exists
*/
const statusBar = new ShareStatusBar(
statusBarItems,
sharedFiles.length
);
try {
const statusBar = new ShareStatusBar(
statusBarItems,
sharedFiles.length
);
let errorCount = 0;
if (sharedFiles.length > 0) {
const publishedFiles = sharedFiles.map(
Expand Down Expand Up @@ -55,14 +55,14 @@ export async function shareAllMarkedNotes(PublisherManager: GithubBranch, settin
await noticeMessage(PublisherManager, noticeValue, settings, repoFrontmatter);
} else {
new Notice((t("errorPublish") as StringFunc)(settings.githubRepo));

}
}
} catch (error) {
console.error(error);
new Notice(
t("unablePublishMultiNotes") as string
);
statusBar.error();
}
}

Expand Down
35 changes: 23 additions & 12 deletions plugin/publishing/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { FilesManagement } from "./filesManagement";
import { Octokit } from "@octokit/core";
import { Base64 } from "js-base64";
import {deleteFromGithub} from "./delete"

import t, {StringFunc} from "../i18n";


import {
Expand Down Expand Up @@ -54,18 +54,29 @@ export default class Publisher {
if (linkedFiles.length> 1) {
const statusBarItems = this.plugin.addStatusBarItem();
const statusBar = new ShareStatusBar(statusBarItems, linkedFiles.length, true);
for (const image of linkedFiles) {
if (!fileHistory.includes(image)) {
if ((image.extension === 'md') && deepScan) {
await this.publish(image, false, ref, repoFrontmatter, fileHistory, true);
} else if (isAttachment(image.extension) && sourceFrontmatter.attachment) {
await this.uploadImage(image, ref, sourceFrontmatter, repoFrontmatter);
fileHistory.push(image);
try {
for (const image of linkedFiles) {
try {
if (!fileHistory.includes(image)) {
if ((image.extension === 'md') && deepScan) {
await this.publish(image, false, ref, repoFrontmatter, fileHistory, true);
} else if (isAttachment(image.extension) && sourceFrontmatter.attachment) {
await this.uploadImage(image, ref, sourceFrontmatter, repoFrontmatter);
fileHistory.push(image);
}
}
statusBar.increment();
} catch (e) {
new Notice((t("unablePublishNote") as StringFunc)(image.name));
console.error(e);
}
}
statusBar.increment();
statusBar.finish(8000);
} catch (e) {
noticeLog(e, this.settings);
new Notice((t('errorPublish') as StringFunc)(repoFrontmatter.repo));
statusBar.error();
}
statusBar.finish(8000);
} else { // 1 one item to send
const embed = linkedFiles[0];
if (!fileHistory.includes(embed)) {
Expand Down Expand Up @@ -105,7 +116,7 @@ export default class Publisher {
return false;
}
try {
console.log("Publishing file: " + file.path);
noticeLog("Publishing file: " + file.path, this.settings);
fileHistory.push(file)
const frontmatterSettings = getFrontmatterCondition(frontmatter, this.settings);
let embedFiles = shareFiles.getSharedEmbed(file, frontmatterSettings);
Expand All @@ -117,7 +128,7 @@ export default class Publisher {
const path = getReceiptFolder(file, this.settings, this.metadataCache, this.vault)
//if repoFrontmatter is an array, it means that the file is in a multiple repo
if (repoFrontmatter instanceof Array) {
console.log("Multiple repo", repoFrontmatter)
noticeLog("Multiple repo" + repoFrontmatter, this.settings)
const success: boolean[] = [];
for (const repo of repoFrontmatter) {
success.push(await this.uploadMultiple(file, text, ref, frontmatterSettings, path, repo, embedFiles, fileHistory, deepScan, shareFiles, autoclean));
Expand Down

0 comments on commit 0e322fd

Please sign in to comment.