Skip to content

Commit

Permalink
2.6.0-beta-1, 0.17.6-6, embedded file loader batching
Browse files Browse the repository at this point in the history
  • Loading branch information
zsviczian committed Oct 23, 2024
1 parent 19a46e5 commit 5c70958
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 17 deletions.
Binary file modified assets/excalidraw-fonts.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion manifest-beta.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian-excalidraw-plugin",
"name": "Excalidraw",
"version": "2.5.3-beta-5",
"version": "2.6.0-beta-1",
"minAppVersion": "1.1.6",
"description": "An Obsidian plugin to edit and view Excalidraw drawings",
"author": "Zsolt Viczian",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"license": "MIT",
"dependencies": {
"@popperjs/core": "^2.11.8",
"@zsviczian/excalidraw": "0.17.6-4",
"@zsviczian/excalidraw": "0.17.6-6",
"chroma-js": "^2.4.2",
"clsx": "^2.0.0",
"@zsviczian/colormaster": "^1.2.2",
Expand Down
40 changes: 29 additions & 11 deletions src/EmbeddedFileLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,9 @@ export class EmbeddedFilesLoader {
this.isDark = excalidrawData?.scene?.appState?.theme === "dark";
}
let entry: IteratorResult<[FileId, EmbeddedFile]>;
const files: FileData[] = [];
const files: FileData[][] = [];
files.push([]);
let batch = 0;

function* loadIterator():Generator<Promise<void>> {
while (!(entry = entries.next()).done) {
Expand All @@ -632,13 +634,13 @@ export class EmbeddedFilesLoader {
hasSVGwithBitmap: data.hasSVGwithBitmap,
shouldScale: embeddedFile.shouldScale()
};
try {
files[batch].push(fileData);
/* try {
addFiles([fileData], this.isDark, false);
}
catch(e) {
errorlog({ where: "EmbeddedFileLoader.loadSceneFiles", error: e });
}
//files.push(fileData);
}*/
}
} else if (embeddedFile.isSVGwithBitmap && (depth !== 0 || isThemeChange)) {
//this will reload the image in light/dark mode when switching themes
Expand All @@ -651,13 +653,13 @@ export class EmbeddedFilesLoader {
hasSVGwithBitmap: embeddedFile.isSVGwithBitmap,
shouldScale: embeddedFile.shouldScale()
};
//files.push(fileData);
try {
files[batch].push(fileData);
/* try {
addFiles([fileData], this.isDark, false);
}
catch(e) {
errorlog({ where: "EmbeddedFileLoader.loadSceneFiles", error: e });
}
}*/
}
});
}
Expand Down Expand Up @@ -685,7 +687,7 @@ export class EmbeddedFilesLoader {
hasSVGwithBitmap: false,
shouldScale: true
};
files.push(fileData);
files[batch].push(fileData);
}
}
});
Expand Down Expand Up @@ -713,7 +715,7 @@ export class EmbeddedFilesLoader {
shouldScale: true,
size: await getImageSize(result.files[key].dataURL),
};
files.push(fileData);
files[batch].push(fileData);
}
return;
}
Expand Down Expand Up @@ -741,7 +743,7 @@ export class EmbeddedFilesLoader {
size,
shouldScale: true,
};
files.push(fileData);
files[batch].push(fileData);
}
return;
}
Expand All @@ -750,9 +752,25 @@ export class EmbeddedFilesLoader {
};
}

const addFilesTimer = setInterval(() => {
if(files[batch].length === 0) {
return;
}
try {
addFiles(files[batch], this.isDark, false);
}
catch(e) {
errorlog({ where: "EmbeddedFileLoader.loadSceneFiles", error: e });
}
files.push([]);
batch++;
}, 1200);

const iterator = loadIterator.bind(this)();
const concurency = 5;
await new PromisePool(iterator, concurency).all();

clearInterval(addFilesTimer);

this.emptyPDFDocsMap();
if (this.terminate) {
Expand All @@ -761,7 +779,7 @@ export class EmbeddedFilesLoader {
//debug({where:"EmbeddedFileLoader.loadSceneFiles",uid:this.uid,status:"add Files"});
try {
//in try block because by the time files are loaded the user may have closed the view
addFiles(files, this.isDark, true);
addFiles(files[batch], this.isDark, true);
} catch (e) {
errorlog({ where: "EmbeddedFileLoader.loadSceneFiles", error: e });
}
Expand Down
1 change: 0 additions & 1 deletion src/ExcalidrawLib.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,5 @@ declare namespace ExcalidrawLib {
): string;
function safelyParseJSON (json: string): Record<string, any> | null;
function loadSceneFonts(elements: NonDeletedExcalidrawElement[]): Promise<void>;
function initializeObsidianUtils(obsidianPlugin: ExcalidrawPlugin): void;
}

1 change: 0 additions & 1 deletion src/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ export const {
refreshTextDimensions,
getCSSFontDefinition,
loadSceneFonts,
initializeObsidianUtils,
} = excalidrawLib;

export const FONTS_STYLE_ID = "excalidraw-custom-fonts";
Expand Down
2 changes: 0 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import {
DEVICE,
sceneCoordsToViewportCoords,
FONTS_STYLE_ID,
initializeObsidianUtils,
} from "./constants/constants";
import ExcalidrawView, { TextMode, getTextMode } from "./ExcalidrawView";
import {
Expand Down Expand Up @@ -205,7 +204,6 @@ export default class ExcalidrawPlugin extends Plugin {
this.equationsMaster = new Map<FileId, string>();
this.mermaidsMaster = new Map<FileId, string>();
setExcalidrawPlugin(this);
initializeObsidianUtils(this);
/*if((process.env.NODE_ENV === 'development')) {
this.slob = new Array(200 * 1024 * 1024 + 1).join('A'); // Create a 200MB blob
}*/
Expand Down

0 comments on commit 5c70958

Please sign in to comment.