From c6224ae76e6f6692e2c5efb70ea39c15b7bdd827 Mon Sep 17 00:00:00 2001 From: Devon22 Date: Sat, 14 Feb 2026 18:49:03 +0800 Subject: [PATCH] 2.0.7 --- manifest.json | 2 +- package-lock.json | 4 +-- package.json | 2 +- src/fullscreen.ts | 70 +++++++++++++++++++++++++++++++++++++++-------- versions.json | 2 +- 5 files changed, 63 insertions(+), 17 deletions(-) diff --git a/manifest.json b/manifest.json index 83bc546..f4fe278 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "mediaviewer", "name": "Media Viewer", - "version": "2.0.6", + "version": "2.0.7", "minAppVersion": "1.1.0", "description": "View and manage media files within your notes.", "author": "Devon22", diff --git a/package-lock.json b/package-lock.json index fbe2068..609e3f1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "mediaviewer", - "version": "2.0.6", + "version": "2.0.7", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "mediaviewer", - "version": "2.0.6", + "version": "2.0.7", "license": "MIT", "dependencies": { "@esbuild/linux-x64": "0.17.3", diff --git a/package.json b/package.json index c4623b3..d29bb1d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mediaviewer", - "version": "2.0.6", + "version": "2.0.7", "description": "This is a sample plugin for Obsidian (https://obsidian.md)", "main": "main.js", "scripts": { diff --git a/src/fullscreen.ts b/src/fullscreen.ts index ba27ea2..1738872 100644 --- a/src/fullscreen.ts +++ b/src/fullscreen.ts @@ -1,4 +1,4 @@ -import { App, Modal, getFrontMatterInfo, TFile, Notice, Platform } from 'obsidian'; +import { App, Modal, getFrontMatterInfo, TFile, Notice, Platform, Menu } from 'obsidian'; import MediaViewPlugin from './main'; import { MediaViewSettings } from './settings'; import { t } from './translations'; @@ -9,6 +9,7 @@ interface Media { links?: string[]; path?: string; title?: string; + file?: TFile; } export class FullScreenModal extends Modal { @@ -161,7 +162,9 @@ export class FullScreenModal extends Modal { mediaLinks.set(url, [fullMatch]); mediaUrls.push({ type: type, - url: url + url: url, + path: file ? file.path : undefined, + file: file || undefined }); } } @@ -226,10 +229,24 @@ export class FullScreenModal extends Modal { const img = container.createEl('img'); img.src = media.url; img.onclick = () => this.showMedia(index); + img.oncontextmenu = (e) => { + if (media.file) { + const menu = new Menu(); + this.app.workspace.trigger('file-menu', menu, media.file, 'media-viewer'); + menu.showAtMouseEvent(e); + } + }; } else { if (media.url.match(/\.(mp4|mkv|mov|webm)/i)) { const video = container.createEl('video'); video.onclick = () => this.showMedia(index); + video.oncontextmenu = (e) => { + if (media.file) { + const menu = new Menu(); + this.app.workspace.trigger('file-menu', menu, media.file, 'media-viewer'); + menu.showAtMouseEvent(e); + } + }; if (!Platform.isAndroidApp) { video.src = media.url; const videoIcon = container.createDiv('mv-video-indicator'); @@ -561,17 +578,13 @@ export class FullScreenModal extends Modal { const clickXPercent = clickX / rect.width; const clickYPercent = clickY / rect.height; - if (this.fullMediaView.clientWidth > this.fullMediaView.clientHeight) { - if (this.fullImage.naturalHeight < this.fullMediaView.clientHeight) { - this.fullImage.style.maxWidth = 'none'; - } - } else { - if (this.fullImage.naturalWidth < this.fullMediaView.clientWidth) { - this.fullImage.style.maxHeight = 'none'; - } - } + // 根據圖片與視窗的長寬比來決定放大模式 + const imageAspect = this.fullImage.naturalWidth / this.fullImage.naturalHeight; + const screenAspect = this.fullMediaView.clientWidth / this.fullMediaView.clientHeight; - if (this.fullImage.offsetWidth < this.fullMediaView.clientWidth) { + // 如果圖片比視窗更"細長" (Aspect Ratio 較小),則寬度填滿 (Fit Width),垂直捲動 + // 如果圖片比視窗更"扁平" (Aspect Ratio 較大),則高度填滿 (Fit Height),水平捲動 + if (imageAspect < screenAspect) { this.fullImage.style.width = '100vw'; this.fullImage.style.height = 'auto'; this.fullMediaView.style.overflowX = 'hidden'; @@ -663,6 +676,25 @@ export class FullScreenModal extends Modal { this.scope.register(null, 'Escape', () => { this.hideMedia(); }); + + // 右鍵選單 + this.fullImage.oncontextmenu = (e) => { + const media = this.mediaUrls[this.currentIndex]; + if (media.file) { + const menu = new Menu(); + this.app.workspace.trigger('file-menu', menu, media.file, 'media-viewer'); + menu.showAtMouseEvent(e); + } + }; + + this.fullVideo.oncontextmenu = (e) => { + const media = this.mediaUrls[this.currentIndex]; + if (media.file) { + const menu = new Menu(); + this.app.workspace.trigger('file-menu', menu, media.file, 'media-viewer'); + menu.showAtMouseEvent(e); + } + }; } // 顯示上一個媒體 @@ -826,10 +858,24 @@ export class FullScreenModal extends Modal { const img = container.createEl('img'); img.src = media.url; img.onclick = () => this.showMedia(idx); + img.oncontextmenu = (e) => { + if (media.file) { + const menu = new Menu(); + this.app.workspace.trigger('file-menu', menu, media.file, 'media-viewer'); + menu.showAtMouseEvent(e); + } + }; } else { if (media.url.match(/\.(mp4|mkv|mov|webm)/i)) { const video = container.createEl('video'); video.onclick = () => this.showMedia(idx); + video.oncontextmenu = (e) => { + if (media.file) { + const menu = new Menu(); + this.app.workspace.trigger('file-menu', menu, media.file, 'media-viewer'); + menu.showAtMouseEvent(e); + } + }; if (!Platform.isAndroidApp) { video.src = media.url; const videoIcon = container.createDiv('mv-video-indicator'); diff --git a/versions.json b/versions.json index 4c59f92..51ffed0 100644 --- a/versions.json +++ b/versions.json @@ -1,3 +1,3 @@ { - "2.0.6": "1.1.0" + "2.0.7": "1.1.0" } \ No newline at end of file