🐛 Fix: fix copy link bug

This commit is contained in:
萌萌哒赫萝 2023-04-17 19:39:51 +08:00
parent d55458197a
commit 72c9374a26
3 changed files with 17 additions and 6 deletions

View File

@ -5,7 +5,8 @@ import {
Notification,
IpcMainEvent,
BrowserWindow,
screen
screen,
IpcMainInvokeEvent
} from 'electron'
import windowManager from 'apis/app/window/windowManager'
import { IWindowList } from '#/types/enum'
@ -42,6 +43,7 @@ import { handleCopyUrl } from '~/main/utils/common'
import { buildMainPageMenu, buildMiniPageMenu, buildPluginPageMenu, buildPicBedListMenu } from './remotes/menu'
import path from 'path'
import { T } from '~/main/i18n'
import { generateShortUrl } from '~/universal/utils/common'
const STORE_PATH = app.getPath('userData')
@ -157,6 +159,11 @@ export default {
})
})
ipcMain.handle('getShortUrl', async (evt: IpcMainInvokeEvent, url: string) => {
const shortUrl = await generateShortUrl(url)
return shortUrl
})
ipcMain.on('openSettingWindow', () => {
windowManager.get(IWindowList.SETTING_WINDOW)!.show()
if (windowManager.has(IWindowList.MINI_WINDOW)) {

View File

@ -30,13 +30,15 @@ export default async (style: IPasteStyle, item: ImgInfo, customLink: string | un
if (useShortUrl) {
url = await generateShortUrl(url)
}
const copyedItem = JSON.parse(JSON.stringify(item))
copyedItem.url = url
const _customLink = customLink || '![$fileName]($url)'
const tpl = {
markdown: `![](${url})`,
HTML: `<img src="${url}"/>`,
URL: url,
UBB: `[IMG]${url}[/IMG]`,
Custom: formatCustomLink(_customLink, item)
Custom: formatCustomLink(_customLink, copyedItem)
}
return tpl[style]
}

View File

@ -70,7 +70,7 @@ import { IResult } from '@picgo/store/dist/types'
import { OPEN_WINDOW } from '#/events/constants'
import { IPasteStyle, IWindowList } from '#/types/enum'
import { getConfig, sendToMain } from '@/utils/dataSender'
import { handleUrlEncode, generateShortUrl } from '#/utils/common'
import { handleUrlEncode } from '#/utils/common'
const files = ref<IResult<ImgInfo>[]>([])
const notification = reactive({
@ -111,7 +111,6 @@ const formatCustomLink = (customLink: string, item: ImgInfo) => {
}
async function copyTheLink (item: ImgInfo) {
notification.body = item.imgUrl!
const pasteStyle = await getConfig<IPasteStyle>('settings.pasteStyle') || IPasteStyle.MARKDOWN
const customLink = await getConfig<string>('settings.customLink')
const txt = await pasteTemplate(pasteStyle, item, customLink)
@ -129,15 +128,18 @@ async function pasteTemplate (style: IPasteStyle, item: ImgInfo, customLink: str
}
const useShortUrl = await getConfig('settings.useShortUrl') || false
if (useShortUrl) {
url = await generateShortUrl(url)
url = await ipcRenderer.invoke('getShortUrl', url)
}
const copyedItem = JSON.parse(JSON.stringify(item))
copyedItem.url = url
notification.body = url
const _customLink = customLink || '![$fileName]($url)'
const tpl = {
markdown: `![](${url})`,
HTML: `<img src="${url}"/>`,
URL: url,
UBB: `[IMG]${url}[/IMG]`,
Custom: formatCustomLink(_customLink, item)
Custom: formatCustomLink(_customLink, copyedItem)
}
return tpl[style]
}