From 4387719907be0d353dfb8b2664a2d4d4edca1b53 Mon Sep 17 00:00:00 2001 From: Natsumi Date: Mon, 8 May 2023 14:45:43 +1200 Subject: [PATCH] feat: Copy/open image, open last image --- AppApi.cs | 41 +++++++++++++++++++++ html/src/app.js | 53 +++++++++++++++++++++------ html/src/index.pug | 9 ++++- html/src/localization/strings/en.json | 4 ++ 4 files changed, 95 insertions(+), 12 deletions(-) diff --git a/AppApi.cs b/AppApi.cs index ed1b1e06..2a6d16e9 100644 --- a/AppApi.cs +++ b/AppApi.cs @@ -7,6 +7,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Drawing; using System.Globalization; using System.IO; using System.Linq; @@ -796,6 +797,46 @@ namespace VRCX ExecuteAppFunction("displayScreenshotMetadata", metadata.ToString(Formatting.Indented)); } + public void GetLastScreenshot() + { + // Get the last screenshot taken by VRChat + var path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "VRChat"); + if (!Directory.Exists(path)) + return; + + var lastDirectory = Directory.GetDirectories(path).OrderByDescending(Directory.GetCreationTime).FirstOrDefault(); + if (lastDirectory == null) + return; + + var lastScreenshot = Directory.GetFiles(lastDirectory, "*.png").OrderByDescending(File.GetCreationTime).FirstOrDefault(); + if (lastScreenshot == null) + return; + + GetScreenshotMetadata(lastScreenshot); + } + + public void CopyImageToClipboard(string path) + { + // check if the file exists and is any image file type + if (File.Exists(path) && (path.EndsWith(".png") || path.EndsWith(".jpg") || path.EndsWith(".jpeg") || path.EndsWith(".gif") || path.EndsWith(".bmp") || path.EndsWith(".webp"))) + { + MainForm.Instance.BeginInvoke(new MethodInvoker(() => + { + var image = Image.FromFile(path); + Clipboard.SetImage(image); + })); + } + } + + public void OpenImageFolder(string path) + { + if (!File.Exists(path)) + return; + + // open folder with file highlighted + Process.Start("explorer.exe", $"/select,\"{path}\""); + } + public void FlashWindow() { MainForm.Instance.BeginInvoke(new MethodInvoker(() => { WinformThemer.Flash(MainForm.Instance); })); diff --git a/html/src/app.js b/html/src/app.js index 8763780b..81ca96f3 100644 --- a/html/src/app.js +++ b/html/src/app.js @@ -89,8 +89,11 @@ speechSynthesis.getVoices(); $app.refreshCustomCss(); } - let carouselNavigation = { 'ArrowLeft': 0, 'ArrowRight': 2 }[e.key] - if (carouselNavigation !== undefined && $app.screenshotMetadataDialog?.visible) { + let carouselNavigation = {ArrowLeft: 0, ArrowRight: 2}[e.key]; + if ( + typeof carouselNavigation !== 'undefined' && + $app.screenshotMetadataDialog?.visible + ) { $app.screenshotMetadataCarouselChange(carouselNavigation); } }); @@ -20636,16 +20639,16 @@ speechSynthesis.getVoices(); D.metadata.dateTime = Date.parse(json.creationDate); } - this.showScreenshotMetadataDialog(); + this.openScreenshotMetadataDialog(); }; - + $app.data.screenshotMetadataDialog = { visible: false, metadata: {}, isUploading: false }; - $app.methods.showScreenshotMetadataDialog = function () { + $app.methods.openScreenshotMetadataDialog = function () { this.$nextTick(() => adjustDialogZ(this.$refs.screenshotMetadataDialog.$el) ); @@ -20653,6 +20656,14 @@ speechSynthesis.getVoices(); D.visible = true; }; + $app.methods.showScreenshotMetadataDialog = function () { + var D = this.screenshotMetadataDialog; + if (!D.metadata.filePath) { + AppApi.GetLastScreenshot(); + } + this.openScreenshotMetadataDialog(); + }; + $app.methods.screenshotMetadataCarouselChange = function (index) { var D = this.screenshotMetadataDialog; if (index === 0) { @@ -20712,16 +20723,36 @@ speechSynthesis.getVoices(); * This function is called by .NET(CefCustomDragHandler#CefCustomDragHandler) when a file is dragged over a drop zone in the app window. * @param {string} filePath - The full path to the file being dragged into the window */ - $app.methods.dragEnterCef = function(filePath) { - this.currentlyDroppingFile = filePath + $app.methods.dragEnterCef = function (filePath) { + this.currentlyDroppingFile = filePath; }; - $app.methods.handleDrop = function(event) { - if (this.currentlyDroppingFile == null) return - console.log("Dropped file into window: ", this.currentlyDroppingFile) + $app.methods.handleDrop = function (event) { + if (this.currentlyDroppingFile === null) { + return; + } + console.log('Dropped file into window: ', this.currentlyDroppingFile); AppApi.GetScreenshotMetadata(this.currentlyDroppingFile); - event.preventDefault() + event.preventDefault(); + }; + + $app.methods.copyImageToClipboard = function (path) { + AppApi.CopyImageToClipboard(path).then(() => { + this.$message({ + message: 'Image copied to clipboard', + type: 'success' + }); + }); + }; + + $app.methods.openImageFolder = function (path) { + AppApi.OpenImageFolder(path).then(() => { + this.$message({ + message: 'Opened image folder', + type: 'success' + }); + }); }; // YouTube API diff --git a/html/src/index.pug b/html/src/index.pug index 3155f0f9..7eabc6d5 100644 --- a/html/src/index.pug +++ b/html/src/index.pug @@ -3846,9 +3846,16 @@ html //- dialog: screenshot metadata el-dialog.x-dialog(:before-close="beforeDialogClose" @mousedown.native="dialogMouseDown" @mouseup.native="dialogMouseUp" ref="screenshotMetadataDialog" :visible.sync="screenshotMetadataDialog.visible" :title="$t('dialog.screenshot_metadata.header')" width="1050px") div(v-if="screenshotMetadataDialog.visible" @dragover.prevent @dragenter.prevent @drop="handleDrop" style="-webkit-app-region: drag") + span(style="margin-left:5px;color:#909399;font-family:monospace") {{ $t('dialog.screenshot_metadata.drag') }} + br el-button(size="small" icon="el-icon-folder-opened" @click="AppApi.OpenScreenshotFileDialog()") {{ $t('dialog.screenshot_metadata.browse') }} + el-button(size="small" icon="el-icon-picture-outline" @click="AppApi.GetLastScreenshot()") {{ $t('dialog.screenshot_metadata.last_screenshot') }} + el-button(size="small" icon="el-icon-copy-document" @click="copyImageToClipboard(screenshotMetadataDialog.metadata.filePath)") {{ $t('dialog.screenshot_metadata.copy_image') }} + el-button(size="small" icon="el-icon-folder" @click="openImageFolder(screenshotMetadataDialog.metadata.filePath)") {{ $t('dialog.screenshot_metadata.open_folder') }} el-button(v-if="API.currentUser.$isVRCPlus && screenshotMetadataDialog.metadata.filePath" size="small" icon="el-icon-upload2" @click="uploadScreenshotToGallery") {{ $t('dialog.screenshot_metadata.upload') }} - span(v-text="screenshotMetadataDialog.metadata.fileName" style="margin-left:5px") + br + br + span(v-text="screenshotMetadataDialog.metadata.fileName") br span(v-if="screenshotMetadataDialog.metadata.dateTime") {{ screenshotMetadataDialog.metadata.dateTime | formatDate('long') }} span(v-if="screenshotMetadataDialog.metadata.fileResolution" v-text="screenshotMetadataDialog.metadata.fileResolution" style="margin-left:5px") diff --git a/html/src/localization/strings/en.json b/html/src/localization/strings/en.json index 3615d625..e831b04d 100644 --- a/html/src/localization/strings/en.json +++ b/html/src/localization/strings/en.json @@ -1095,7 +1095,11 @@ }, "screenshot_metadata": { "header": "Screenshot Metadata", + "drag": "Drag and drop a screenshot here", "browse": "Browse", + "last_screenshot": "Last Screenshot", + "copy_image": "Copy Image", + "open_folder": "Open Folder", "upload": "Upload" } },