From 4688b125d223187f5d01dbe1a93760645be17a70 Mon Sep 17 00:00:00 2001 From: NomarCub Date: Wed, 3 Jan 2024 21:30:21 +0100 Subject: [PATCH 1/5] bump Obisdian dependency to 1.4.11 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 326610f..8a087d3 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "builtin-modules": "3.3.0", "esbuild": "0.17.3", "eslint": "8.46.0", - "obsidian": "^0.16.3", + "obsidian": "^1.4.11", "tslib": "2.4.0", "typescript": "4.7.4" } From 11cdaab351677b5da6c4a5ca7ef088b524be237e Mon Sep 17 00:00:00 2001 From: NomarCub Date: Wed, 3 Jan 2024 21:33:23 +0100 Subject: [PATCH 2/5] use `Plugin.app` member instead of deprecated global `app` --- src/main.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main.ts b/src/main.ts index 5f7c38e..dae2220 100644 --- a/src/main.ts +++ b/src/main.ts @@ -30,7 +30,7 @@ export default class CopyUrlInPreview extends Plugin { await this.loadSettings(); this.addSettingTab(new CopyUrlInPreviewSettingTab(this.app, this)); this.registerDocument(document); - app.workspace.on("window-open", + this.app.workspace.on("window-open", (workspaceWindow, window) => { this.registerDocument(window.document); }); @@ -122,7 +122,7 @@ export default class CopyUrlInPreview extends Plugin { } storeLastHoveredLinkInEditor(event: MouseEvent) { - const editor = app.workspace.getActiveViewOfType(MarkdownView)?.editor as EditorInternalApi; + const editor = this.app.workspace.getActiveViewOfType(MarkdownView)?.editor as EditorInternalApi; if (!editor) { return; } @@ -306,7 +306,7 @@ export default class CopyUrlInPreview extends Plugin { if (protocol === "app:" && Platform.isDesktop) { // href probably also works // getResourcePath("") also works for root path - const baseFilePath = (app.vault.adapter as FileSystemAdapterWithInternalApi).getFilePath(""); + const baseFilePath = (this.app.vault.adapter as FileSystemAdapterWithInternalApi).getFilePath(""); const baseFilePathName: string = (baseFilePath as any).pathname; const urlPathName: string = (url as any).pathname; if (urlPathName.startsWith(baseFilePathName)) { @@ -316,21 +316,21 @@ export default class CopyUrlInPreview extends Plugin { menu.addItem((item: MenuItem) => item .setIcon("arrow-up-right") .setTitle("Open in default app") - .onClick(() => (app as AppWithDesktopInternalApi).openWithDefaultApp(relativePath)) + .onClick(() => (this.app as AppWithDesktopInternalApi).openWithDefaultApp(relativePath)) ); menu.addItem((item: MenuItem) => item .setIcon("arrow-up-right") .setTitle(Platform.isMacOS ? "Reveal in finder" : "Show in system explorer") .onClick(() => { - (app as AppWithDesktopInternalApi).showInFolder(relativePath); + (this.app as AppWithDesktopInternalApi).showInFolder(relativePath); }) ); menu.addItem((item: MenuItem) => item .setIcon("folder") .setTitle("Reveal file in navigation") .onClick(() => { - const abstractFilePath = app.vault.getAbstractFileByPath(relativePath.substring(1)); - (app as any).internalPlugins.getEnabledPluginById("file-explorer").revealInFolder(abstractFilePath); + const abstractFilePath = this.app.vault.getAbstractFileByPath(relativePath.substring(1)); + (this.app as any).internalPlugins.getEnabledPluginById("file-explorer").revealInFolder(abstractFilePath); }) ); } From 4afc586f2270568777442cb42003d097bbe1aaad Mon Sep 17 00:00:00 2001 From: NomarCub Date: Wed, 3 Jan 2024 21:42:26 +0100 Subject: [PATCH 3/5] bump version to 1.5.2 and minAppVersion to 1.4.11 --- manifest.json | 4 ++-- package.json | 2 +- versions.json | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/manifest.json b/manifest.json index dfd6a65..000944a 100644 --- a/manifest.json +++ b/manifest.json @@ -1,8 +1,8 @@ { "id": "copy-url-in-preview", "name": "Copy Image and URL context menu", - "version": "1.5.1", - "minAppVersion": "0.16.3", + "version": "1.5.2", + "minAppVersion": "1.4.11", "description": "Copy Image, Copy URL and Open PDF externally context menu in reading view (formerly preview mode)", "author": "NomarCub", "authorUrl": "https://github.com/NomarCub", diff --git a/package.json b/package.json index 8a087d3..85a4764 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "copy-url-in-preview", - "version": "1.5.1", + "version": "1.5.2", "description": "Copy Image, Copy URL and Open PDF externally context menu in reading view (formerly preview mode) for Obsidian (https://obsidian.md)", "main": "main.js", "scripts": { diff --git a/versions.json b/versions.json index e50c903..fbfed19 100644 --- a/versions.json +++ b/versions.json @@ -2,5 +2,6 @@ "1.0.0": "0.11.13", "1.3.2": "0.14.8", "1.3.5": "0.15.4", - "1.4.0": "0.16.3" + "1.4.0": "0.16.3", + "1.5.2": "1.4.11" } \ No newline at end of file From 1b196eae6ed722d032b67febc43892e56ce1a0d1 Mon Sep 17 00:00:00 2001 From: NomarCub Date: Wed, 3 Jan 2024 21:53:12 +0100 Subject: [PATCH 4/5] update readme, address https://github.com/NomarCub/obsidian-copy-url-in-preview/issues/31 --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 40317ef..cb544ad 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,11 @@ This plugin context the following context menus in reading view in [Obsidian](https://obsidian.md/). -This makes copying URLs in reading view like it is in editing view by deafult. For copying images in edit mode check out [Ozan's Image in Editor Plugin](https://github.com/ozntel/oz-image-in-editor-obsidian) +This makes copying URLs in reading view like it is in editing view by deafult. + +See these other plugins for related functionality: +- [Ozan's Image in Editor Plugin](https://github.com/ozntel/oz-image-in-editor-obsidian) +- [Image Toolkit](https://github.com/sissilab/obsidian-image-toolkit) Copying images: @@ -25,7 +29,7 @@ Opening PDFs externally: ![Opening PDFs externally on desktop](https://user-images.githubusercontent.com/5298006/171170626-5a94f5dc-61fc-4661-a9f2-38a0fb0181f5.gif) -All features work on mobile, but were only tested on Android: +All features work on mobile, but were only tested on Android. Mobile uses the native image sharing functionality instead of the clipboard, and it downloads online images temporarily so they can be shared. ![Copying URLs on Android](https://user-images.githubusercontent.com/5298006/125515758-bdf77074-a58c-4a6d-affa-88d031991ab2.gif) From 9aadb1f2269ef596be79f4e54596d06da827e77f Mon Sep 17 00:00:00 2001 From: NomarCub Date: Wed, 3 Jan 2024 22:40:53 +0100 Subject: [PATCH 5/5] update broken undocumented API usage for getting the vault's path, fix https://github.com/NomarCub/obsidian-copy-url-in-preview/issues/32 --- src/main.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main.ts b/src/main.ts index dae2220..a59adfd 100644 --- a/src/main.ts +++ b/src/main.ts @@ -304,10 +304,9 @@ export default class CopyUrlInPreview extends Plugin { }) ); if (protocol === "app:" && Platform.isDesktop) { - // href probably also works // getResourcePath("") also works for root path const baseFilePath = (this.app.vault.adapter as FileSystemAdapterWithInternalApi).getFilePath(""); - const baseFilePathName: string = (baseFilePath as any).pathname; + const baseFilePathName: string = baseFilePath.replace("file://", ""); const urlPathName: string = (url as any).pathname; if (urlPathName.startsWith(baseFilePathName)) { let relativePath = urlPathName.replace(baseFilePathName, "");