From 630a8c579857b9eda279e6d39835fdd585f804e6 Mon Sep 17 00:00:00 2001 From: Justin Georgi Date: Fri, 4 Oct 2024 09:28:37 -0700 Subject: [PATCH] Add clipboard image selection method Signed-off-by: Justin Georgi --- src/components/svg-icon.vue | 4 +++- src/pages/detect.vue | 26 +++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/components/svg-icon.vue b/src/components/svg-icon.vue index e3b27ff..f429e8a 100644 --- a/src/components/svg-icon.vue +++ b/src/components/svg-icon.vue @@ -19,6 +19,7 @@ + @@ -48,7 +49,8 @@ 'photo_sample', 'reset_slide', 'zoom_to', - 'reset_zoom' + 'reset_zoom', + 'clipboard' ] return iconList.includes(value) } diff --git a/src/pages/detect.vue b/src/pages/detect.vue index 419d4e9..9d6c690 100644 --- a/src/pages/detect.vue +++ b/src/pages/detect.vue @@ -116,6 +116,9 @@ + + + @@ -170,6 +173,7 @@ serverSettings: {}, otherSettings: {}, isCordova: !!window.cordova, + secureProtocol: location.protocol == 'https:', uploadUid: null, uploadDirty: false, modelLocation: '', @@ -312,7 +316,7 @@ if (!this.getInfoUrl) return '' let structure = this.showResults.find( r => r.resultIndex == this.selectedChip) return structure ? this.getInfoUrl + structure.label.replaceAll(' ','_') : '' - } + }, }, methods: { chipGradient (confVal) { @@ -433,6 +437,22 @@ }).open() return } + if (mode == 'clipboard') { + navigator.clipboard.read().then(clip => { + if (!clip[0].types.includes("image/png")) { + throw new Error("Clipboard does not contain valid image data."); + } + return clip[0].getType("image/png"); + }).then(blob => { + let clipImage = URL.createObjectURL(blob); + console.log(clipImage) + this.getImage(clipImage) + }).catch(e => { + console.log(e) + f7.dialog.alert(`Error pasting image: ${e.message}`) + }) + return + } this.$refs.image_chooser.click() }, onFail (message) { @@ -532,6 +552,10 @@ this.detecting = true resolve('data:image/jpg;base64,' + searchImage) } + if (this.imageLoadMode == 'clipboard') { + this.detecting = true + resolve(searchImage) + } const reader = new FileReader() reader.addEventListener("load", () => { this.detecting = true