mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-04-15 12:53:51 +02:00
feat: Copy/open image, open last image
This commit is contained in:
41
AppApi.cs
41
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); }));
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user