mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-07-08 08:21:26 +08:00
Added: globalshotcut for clipboard upload
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
import uploader from './utils/uploader.js'
|
import uploader from './utils/uploader.js'
|
||||||
import { app, BrowserWindow, Tray, Menu, Notification, clipboard, ipcMain } from 'electron'
|
import { app, BrowserWindow, Tray, Menu, Notification, clipboard, ipcMain, globalShortcut } from 'electron'
|
||||||
import db from '../datastore'
|
import db from '../datastore'
|
||||||
import pasteTemplate from './utils/pasteTemplate'
|
import pasteTemplate from './utils/pasteTemplate'
|
||||||
import updateChecker from './utils/updateChecker'
|
import updateChecker from './utils/updateChecker'
|
||||||
@@ -252,6 +252,35 @@ const showWindow = () => {
|
|||||||
window.focus()
|
window.focus()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const uploadClipboardFiles = async () => {
|
||||||
|
let img = clipboard.readImage()
|
||||||
|
let uploadImg = null
|
||||||
|
if (!img.isEmpty()) {
|
||||||
|
// 从剪贴板来的图片默认转为png
|
||||||
|
const imgUrl = 'data:image/png;base64,' + Buffer.from(img.toPNG(), 'binary').toString('base64')
|
||||||
|
uploadImg = {
|
||||||
|
width: img.getSize().width,
|
||||||
|
height: img.getSize().height,
|
||||||
|
imgUrl
|
||||||
|
}
|
||||||
|
}
|
||||||
|
img = await uploader(uploadImg, 'imgFromClipboard', window.webContents)
|
||||||
|
if (img !== false) {
|
||||||
|
const pasteStyle = db.read().get('picBed.pasteStyle').value() || 'markdown'
|
||||||
|
clipboard.writeText(pasteTemplate(pasteStyle, img[0].imgUrl))
|
||||||
|
const notification = new Notification({
|
||||||
|
title: '上传成功',
|
||||||
|
body: img[0].imgUrl,
|
||||||
|
icon: img[0].imgUrl
|
||||||
|
})
|
||||||
|
notification.show()
|
||||||
|
window.webContents.send('clipboardFiles', [])
|
||||||
|
window.webContents.send('uploadFiles', img)
|
||||||
|
} else {
|
||||||
|
uploadFailed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ipcMain.on('uploadClipboardFiles', async (evt, file) => {
|
ipcMain.on('uploadClipboardFiles', async (evt, file) => {
|
||||||
const img = await uploader(file, 'imgFromClipboard', window.webContents)
|
const img = await uploader(file, 'imgFromClipboard', window.webContents)
|
||||||
if (img !== false) {
|
if (img !== false) {
|
||||||
@@ -260,7 +289,8 @@ ipcMain.on('uploadClipboardFiles', async (evt, file) => {
|
|||||||
const notification = new Notification({
|
const notification = new Notification({
|
||||||
title: '上传成功',
|
title: '上传成功',
|
||||||
body: img[0].imgUrl,
|
body: img[0].imgUrl,
|
||||||
icon: file[0]
|
// icon: file[0]
|
||||||
|
icon: img[0].imgUrl
|
||||||
})
|
})
|
||||||
notification.show()
|
notification.show()
|
||||||
window.webContents.send('clipboardFiles', [])
|
window.webContents.send('clipboardFiles', [])
|
||||||
@@ -298,6 +328,11 @@ app.on('ready', () => {
|
|||||||
createTray()
|
createTray()
|
||||||
createMenu()
|
createMenu()
|
||||||
updateChecker()
|
updateChecker()
|
||||||
|
|
||||||
|
globalShortcut.register('CommandOrControl+Shift+P', () => {
|
||||||
|
console.log(1)
|
||||||
|
uploadClipboardFiles()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
app.on('window-all-closed', () => {
|
app.on('window-all-closed', () => {
|
||||||
@@ -314,6 +349,10 @@ app.on('activate', () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
app.on('will-quit', () => {
|
||||||
|
globalShortcut.unregisterAll()
|
||||||
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Auto Updater
|
* Auto Updater
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -21,13 +21,15 @@ const imgFromPath = async (imgPath) => {
|
|||||||
|
|
||||||
const imgFromClipboard = (file) => {
|
const imgFromClipboard = (file) => {
|
||||||
let result = []
|
let result = []
|
||||||
const today = new Date().toLocaleString().replace(/[ ]+/g, '-')
|
if (file !== null) {
|
||||||
result.push({
|
const today = new Date().toLocaleString().replace(/[ ]+/g, '-').replace(/\/+/g, '-')
|
||||||
base64Image: file.imgUrl.replace(/^data\S+,/, ''),
|
result.push({
|
||||||
fileName: `${today}.png`,
|
base64Image: file.imgUrl.replace(/^data\S+,/, ''),
|
||||||
width: file.width,
|
fileName: `${today}.png`,
|
||||||
height: file.height
|
width: file.width,
|
||||||
})
|
height: file.height
|
||||||
|
})
|
||||||
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div id="setting-page">
|
<div id="setting-page">
|
||||||
<div class="fake-title-bar">
|
<div class="fake-title-bar">
|
||||||
PicGo
|
PicGo - {{ version }}
|
||||||
</div>
|
</div>
|
||||||
<el-row style="padding-top: 22px;">
|
<el-row style="padding-top: 22px;">
|
||||||
<el-col :span="5">
|
<el-col :span="5">
|
||||||
@@ -43,10 +43,12 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
|
import pkg from '../../../package.json'
|
||||||
export default {
|
export default {
|
||||||
name: 'setting-page',
|
name: 'setting-page',
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
|
version: pkg.version,
|
||||||
defaultActive: 'upload'
|
defaultActive: 'upload'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user