Skip to content

Commit

Permalink
release: 0.38.2
Browse files Browse the repository at this point in the history
  • Loading branch information
RyotaUshio committed Mar 17, 2024
1 parent e5b9db8 commit 688f2b9
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion manifest-beta.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "pdf-plus",
"name": "PDF++",
"version": "0.38.1",
"version": "0.38.2",
"minAppVersion": "1.4.16",
"description": "The most Obsidian-native PDF annotation tool ever.",
"author": "Ryota Ushio",
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "pdf-plus",
"name": "PDF++",
"version": "0.38.1",
"version": "0.38.2",
"minAppVersion": "1.4.16",
"description": "The most Obsidian-native PDF annotation tool ever.",
"author": "Ryota Ushio",
Expand Down
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
@@ -1,6 +1,6 @@
{
"name": "obsidian-pdf-plus",
"version": "0.38.1",
"version": "0.38.2",
"description": "The most Obsidian-native PDF annotation tool ever.",
"scripts": {
"dev": "node esbuild.config.mjs",
Expand Down
22 changes: 18 additions & 4 deletions src/modals/external-pdf-modals.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PDFPlusModal } from 'modals';
import { Notice, Platform, Setting, normalizePath } from 'obsidian';
import { FuzzyFolderSuggest } from 'utils';
import { FuzzyFolderSuggest, getPathSeparator } from 'utils';


export class ExternalPDFModal extends PDFPlusModal {
Expand Down Expand Up @@ -237,6 +237,7 @@ export class ExternalPDFModal extends PDFPlusModal {

async createDummyFiles() {
let failed: string[] = [];
const promises: Promise<any>[] = [];

const createDummyFile = async (url: string, filePath: string) => {
const availableFilePath = this.app.vault.getAvailablePath(filePath.slice(0, -4), 'pdf')
Expand All @@ -245,26 +246,39 @@ export class ExternalPDFModal extends PDFPlusModal {
};

if (this.source === 'file' && this.folderPath) {
const sep = getPathSeparator();
for (const url of this.urls) {
const filePath = normalizePath(this.folderPath + '/' + url.split('/').pop());
const filePath = normalizePath(this.folderPath + '/' + url.split(sep).pop());
if (!filePath.endsWith('.pdf')) {
failed.push(url);
continue;
}

createDummyFile(url, filePath);
promises.push(
createDummyFile(url, filePath).catch((err) => {
failed.push(url);
console.error(err);
})
);
}
} else if (this.source === 'web' && this.filePath && this.urls.length) {
const filePath = normalizePath(this.filePath);
if (!filePath.endsWith('.pdf')) {
failed = this.urls;
} else {
createDummyFile(this.urls[0], filePath);
promises.push(
createDummyFile(this.urls[0], filePath).catch((err) => {
failed = this.urls;
console.error(err);
})
);
}
} else {
failed = this.urls;
}

await Promise.all(promises);

if (failed.length) {
new Notice(`${this.plugin.manifest.name}: Failed to create dummy files for the following URLs: ${failed.join(', ')}`);
} else {
Expand Down
5 changes: 5 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ export function getModifierNameInPlatform(mod: Modifier): string {
return 'Ctrl';
}

/** Returns the platform-specific path separator. */
export function getPathSeparator() {
return Platform.isWin ? '\\' : '/';
}

export function findReferenceCache(cache: CachedMetadata, start: number, end: number): ReferenceCache | undefined {
return cache.links?.find((link) => start <= link.position.start.offset && link.position.end.offset <= end)
?? cache.embeds?.find((embed) => start <= embed.position.start.offset && embed.position.end.offset <= end);
Expand Down

0 comments on commit 688f2b9

Please sign in to comment.