mirror of
https://github.com/Molunerfinn/PicGo.git
synced 2026-09-20 03:16:37 +00:00
🐛 Fix: tray window clipboard image not show bug (#1362)
This commit is contained in:
@@ -30,6 +30,7 @@
|
||||
"@picgo/i18n": "^1.0.0",
|
||||
"@picgo/store": "^2.1.0",
|
||||
"axios": "^0.19.0",
|
||||
"clip-filepaths": "^0.3.0",
|
||||
"compare-versions": "^4.1.3",
|
||||
"core-js": "^3.27.1",
|
||||
"element-plus": "^2.3.7",
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import fs from 'fs-extra'
|
||||
import {
|
||||
app,
|
||||
Menu,
|
||||
@@ -14,7 +13,7 @@ import windowManager from 'apis/app/window/windowManager'
|
||||
import { IWindowList } from '#/types/enum'
|
||||
import pasteTemplate from '~/main/utils/pasteTemplate'
|
||||
import pkg from 'root/package.json'
|
||||
import { ensureFilePath, handleCopyUrl } from '~/main/utils/common'
|
||||
import { ensureFilePath, getClipboardFilePathList, handleCopyUrl } from '~/main/utils/common'
|
||||
import { privacyManager } from '~/main/utils/privacyManager'
|
||||
import { T } from '~/main/i18n'
|
||||
import { isMacOSVersionGreaterThanOrEqualTo } from '~/main/utils/getMacOSVersion'
|
||||
@@ -165,33 +164,19 @@ export function createTray () {
|
||||
if (process.platform === 'darwin') {
|
||||
toggleWindow(bounds)
|
||||
setTimeout(async () => {
|
||||
const img = clipboard.readImage()
|
||||
const obj: ImgInfo[] = []
|
||||
if (!img.isEmpty()) {
|
||||
// 从剪贴板来的图片默认转为png
|
||||
// https://github.com/electron/electron/issues/9035
|
||||
const imgPath = clipboard.read('public.file-url')
|
||||
if (imgPath) {
|
||||
const imgPathList = getClipboardFilePathList()
|
||||
if (imgPathList.length > 0) {
|
||||
for (const imgPath of imgPathList) {
|
||||
const decodePath = ensureFilePath(imgPath)
|
||||
if (decodePath === imgPath) {
|
||||
obj.push({
|
||||
imgUrl: imgPath
|
||||
})
|
||||
} else {
|
||||
if (decodePath !== '') {
|
||||
// 带有中文的路径,无法直接被img.src所使用,会被转义
|
||||
const base64 = await fs.readFile(
|
||||
decodePath.replace('file://', ''),
|
||||
{ encoding: 'base64' }
|
||||
)
|
||||
obj.push({
|
||||
imgUrl: `data:image/png;base64,${base64}`
|
||||
})
|
||||
}
|
||||
}
|
||||
} else {
|
||||
obj.push({
|
||||
imgUrl: decodePath
|
||||
})
|
||||
}
|
||||
} else {
|
||||
const img = clipboard.readImage()
|
||||
if (!img.isEmpty()) {
|
||||
const imgUrl = img.toDataURL()
|
||||
// console.log(imgUrl)
|
||||
obj.push({
|
||||
width: img.getSize().width,
|
||||
height: img.getSize().height,
|
||||
@@ -231,7 +216,7 @@ export function createTray () {
|
||||
|
||||
// drop-files only be supported in macOS
|
||||
// so the tray window must be available
|
||||
tray.on('drop-files', async (event: Event, files: string[]) => {
|
||||
tray.on('drop-files', async (event, files: string[]) => {
|
||||
const pasteStyle = db.get('settings.pasteStyle') || 'markdown'
|
||||
const trayWindow = windowManager.get(IWindowList.TRAY_WINDOW)!
|
||||
const imgs = await uploader
|
||||
@@ -269,10 +254,10 @@ export function createTray () {
|
||||
export function handleDockIcon () {
|
||||
if (isMacOS) {
|
||||
if (db.get('settings.showDockIcon') !== false) {
|
||||
app.dock.show()
|
||||
app.dock.setMenu(createContextMenu())
|
||||
app.dock?.show()
|
||||
app.dock?.setMenu(createContextMenu())
|
||||
} else {
|
||||
app.dock.hide()
|
||||
app.dock?.hide()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import windowManager from 'apis/app/window/windowManager'
|
||||
import { IWindowList } from '#/types/enum'
|
||||
import util from 'util'
|
||||
import { IPicGo } from 'picgo'
|
||||
import { showNotification, calcDurationRange, getClipboardFilePath } from '~/main/utils/common'
|
||||
import { showNotification, calcDurationRange, getClipboardFilePathList } from '~/main/utils/common'
|
||||
import { GET_RENAME_FILE_NAME, RENAME_FILE_NAME, TALKING_DATA_EVENT } from '~/universal/events/constants'
|
||||
import logger from '@core/picgo/logger'
|
||||
import { T } from '~/main/i18n'
|
||||
@@ -120,8 +120,8 @@ class Uploader {
|
||||
async uploadWithBuildInClipboard (): Promise<ImgInfo[]|false> {
|
||||
let filePath = ''
|
||||
try {
|
||||
const imgPath = getClipboardFilePath()
|
||||
if (!imgPath) {
|
||||
const imgPath = getClipboardFilePathList()
|
||||
if (!imgPath.length) {
|
||||
const nativeImage = clipboard.readImage()
|
||||
if (nativeImage.isEmpty()) {
|
||||
return false
|
||||
@@ -133,7 +133,7 @@ class Uploader {
|
||||
await writeFile(filePath, buffer)
|
||||
return await this.upload([filePath])
|
||||
} else {
|
||||
return await this.upload([imgPath])
|
||||
return await this.upload(imgPath)
|
||||
}
|
||||
} catch (e: any) {
|
||||
logger.error(e)
|
||||
|
||||
@@ -23,6 +23,10 @@ class WindowManager implements IWindowManager {
|
||||
this.windowIdMap.set(window.id, name)
|
||||
}
|
||||
windowConfig.callback(window, this)
|
||||
// https://github.com/electron/electron/issues/1594
|
||||
window.on('page-title-updated', (evt) => {
|
||||
evt.preventDefault()
|
||||
})
|
||||
window.on('close', () => {
|
||||
this.deleteById(id)
|
||||
})
|
||||
|
||||
@@ -20,7 +20,7 @@ systemRouter
|
||||
})
|
||||
.add(IRPCActionType.SHOW_DOCK_ICON, async (args) => {
|
||||
const [visible] = args as IShowDockIconArgs
|
||||
app.dock[visible ? 'show' : 'hide']()
|
||||
app.dock?.[visible ? 'show' : 'hide']()
|
||||
const win = windowManager.get(IWindowList.SETTING_WINDOW)
|
||||
if (!visible) {
|
||||
win?.show()
|
||||
|
||||
@@ -2,6 +2,7 @@ import fs from 'fs-extra'
|
||||
import db from '~/main/apis/core/datastore'
|
||||
import { clipboard, Notification, dialog } from 'electron'
|
||||
import { handleUrlEncode } from '~/universal/utils/common'
|
||||
import { readClipboardFilePaths } from 'clip-filepaths'
|
||||
|
||||
export const handleCopyUrl = (str: string): void => {
|
||||
if (db.get('settings.autoCopyUrl') !== false) {
|
||||
@@ -97,26 +98,9 @@ export const ensureFilePath = (filePath: string, prefix = 'file://'): string =>
|
||||
* for builtin clipboard to get image path from clipboard
|
||||
* @returns
|
||||
*/
|
||||
export const getClipboardFilePath = (): string => {
|
||||
// TODO: linux support
|
||||
const img = clipboard.readImage()
|
||||
if (img.isEmpty()) {
|
||||
if (process.platform === 'win32') {
|
||||
const imgPath = clipboard.readBuffer('FileNameW')?.toString('ucs2')?.replace(RegExp(String.fromCharCode(0), 'g'), '')
|
||||
if (imgPath) {
|
||||
return imgPath
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (process.platform === 'darwin') {
|
||||
let imgPath = clipboard.read('public.file-url') // will get file://xxx/xxx
|
||||
imgPath = ensureFilePath(imgPath)
|
||||
if (imgPath) {
|
||||
return imgPath.replace('file://', '')
|
||||
}
|
||||
}
|
||||
}
|
||||
return ''
|
||||
export const getClipboardFilePathList = (): string[] => {
|
||||
const { filePaths } = readClipboardFilePaths()
|
||||
return filePaths
|
||||
}
|
||||
|
||||
export const handleUrlEncodeWithSetting = (url: string) => {
|
||||
|
||||
+1
-1
@@ -65,4 +65,4 @@
|
||||
"vueCompilerOptions": {
|
||||
"target": 3,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3607,6 +3607,60 @@ cli-width@^2.0.0:
|
||||
resolved "https://registry.npmjs.org/cli-width/-/cli-width-2.2.1.tgz#b0433d0b4e9c847ef18868a4ef16fd5fc8271c48"
|
||||
integrity sha512-GRMWDxpOB6Dgk2E5Uo+3eEBvtOOlimMmpbFiKuLFnQzYDavtLFY3K5ona41jgN/WdRZtG7utuVSVTL4HbZHGkw==
|
||||
|
||||
clip-filepaths-darwin-arm64@0.3.0:
|
||||
version "0.3.0"
|
||||
resolved "https://registry.yarnpkg.com/clip-filepaths-darwin-arm64/-/clip-filepaths-darwin-arm64-0.3.0.tgz#e0553a7a0e47776a7ac9553e5af313c574e48f82"
|
||||
integrity sha512-MNsead3rwMUg/i2+Qn4XUK/O2wPmR+viMwAB2ogd10YdKgAjNqRnVYYMSw3ZAbHy+mIg2xK/sQXsTefwXXMHng==
|
||||
|
||||
clip-filepaths-darwin-x64@0.3.0:
|
||||
version "0.3.0"
|
||||
resolved "https://registry.yarnpkg.com/clip-filepaths-darwin-x64/-/clip-filepaths-darwin-x64-0.3.0.tgz#9a2207d7a8754da5a0234d023002b5fb9d9a1343"
|
||||
integrity sha512-Ged3iEL8V32XGRUi8zhel3xu3dWkq2ILmWRBurA6vMX+dm6izQvwB+hDNVfozEXSbpsUiXaD8Lx1K2FNQePykA==
|
||||
|
||||
clip-filepaths-linux-arm64-gnu@0.3.0:
|
||||
version "0.3.0"
|
||||
resolved "https://registry.yarnpkg.com/clip-filepaths-linux-arm64-gnu/-/clip-filepaths-linux-arm64-gnu-0.3.0.tgz#7ec0e36ac74bad9dc918d7fc50678e9aa8212a69"
|
||||
integrity sha512-ytyiSkiOSe/erIiNILZf8BW+1lpE0KKDA0n2OjWHvq8/VXxxmseNRqiORb+xZUV0tfn2Nz/0QknqcaAjBmpa2w==
|
||||
|
||||
clip-filepaths-linux-arm64-musl@0.3.0:
|
||||
version "0.3.0"
|
||||
resolved "https://registry.yarnpkg.com/clip-filepaths-linux-arm64-musl/-/clip-filepaths-linux-arm64-musl-0.3.0.tgz#9553463e7655354b0ef575006ffc23975d18ce65"
|
||||
integrity sha512-0JiZ4bBNhv8Hv6fh88E6M4bPzdFR3MDUiu/Y/jvC012DZRUUTRh6Mk+zcrol8A0zjFMha/VofO7wtXI4yVIJMw==
|
||||
|
||||
clip-filepaths-linux-x64-gnu@0.3.0:
|
||||
version "0.3.0"
|
||||
resolved "https://registry.yarnpkg.com/clip-filepaths-linux-x64-gnu/-/clip-filepaths-linux-x64-gnu-0.3.0.tgz#4f7c2cddd16ac085027316f8dde0046cdda5f5af"
|
||||
integrity sha512-Cq+go0MfeNh+KSiWla0uYFZ2nOSsCI2MF7qcvyd2r7DGDpd02nNeAYXO6kGr4WYgy1z7JRCYyjwrbsPi/KFcrw==
|
||||
|
||||
clip-filepaths-linux-x64-musl@0.3.0:
|
||||
version "0.3.0"
|
||||
resolved "https://registry.yarnpkg.com/clip-filepaths-linux-x64-musl/-/clip-filepaths-linux-x64-musl-0.3.0.tgz#862aa3193952943915294c87e64e4d7a6f91b850"
|
||||
integrity sha512-yZP8/FXT7ca4KKxnTFapJINf8uMUWRqLmW3NBcs2DUJ/Z5merc7vJu3aaGnzMO9+IFwWk6Wl4UFSHD3l5OX2Qg==
|
||||
|
||||
clip-filepaths-win32-arm64-msvc@0.3.0:
|
||||
version "0.3.0"
|
||||
resolved "https://registry.yarnpkg.com/clip-filepaths-win32-arm64-msvc/-/clip-filepaths-win32-arm64-msvc-0.3.0.tgz#69932570854c220900325fda4ad4898b5d8d8d9e"
|
||||
integrity sha512-IuzhKedlG8jvfuK2Np6pcjeAherzGTldPiNcodslaSyPJT5tBwSvQp4a9jN/B4vp9QTlPDpDMFeUcjgOmZ41RQ==
|
||||
|
||||
clip-filepaths-win32-x64-msvc@0.3.0:
|
||||
version "0.3.0"
|
||||
resolved "https://registry.yarnpkg.com/clip-filepaths-win32-x64-msvc/-/clip-filepaths-win32-x64-msvc-0.3.0.tgz#0ad61c748c21ca832fa8a95f49075405b728d19c"
|
||||
integrity sha512-FERY7lIHMXBD2JMTC9LT96G5wMKF0Vky5reM6ZtNvBDvbe6GwSMC843LjKupoiP/DptosG7d0o3ecaFRyeySdg==
|
||||
|
||||
clip-filepaths@^0.3.0:
|
||||
version "0.3.0"
|
||||
resolved "https://registry.yarnpkg.com/clip-filepaths/-/clip-filepaths-0.3.0.tgz#43bf2816345808af72c5a7ec8c9f5bc13c763588"
|
||||
integrity sha512-RTvOf16co5+Xqpn9ioDKDHYG2Ie7qhL0CSHstrC2u1hCHpb5QxUOnti4rO8hF+uwqonr/KriO6PfXf1zLSGBqA==
|
||||
optionalDependencies:
|
||||
clip-filepaths-darwin-arm64 "0.3.0"
|
||||
clip-filepaths-darwin-x64 "0.3.0"
|
||||
clip-filepaths-linux-arm64-gnu "0.3.0"
|
||||
clip-filepaths-linux-arm64-musl "0.3.0"
|
||||
clip-filepaths-linux-x64-gnu "0.3.0"
|
||||
clip-filepaths-linux-x64-musl "0.3.0"
|
||||
clip-filepaths-win32-arm64-msvc "0.3.0"
|
||||
clip-filepaths-win32-x64-msvc "0.3.0"
|
||||
|
||||
cliui@^7.0.2:
|
||||
version "7.0.4"
|
||||
resolved "https://registry.npmjs.org/cliui/-/cliui-7.0.4.tgz#a0265ee655476fc807aea9df3df8df7783808b4f"
|
||||
|
||||
Reference in New Issue
Block a user