diff --git a/src/main/events/ipcList.ts b/src/main/events/ipcList.ts index 36fc3e8..51f52d4 100644 --- a/src/main/events/ipcList.ts +++ b/src/main/events/ipcList.ts @@ -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)) { diff --git a/src/main/utils/pasteTemplate.ts b/src/main/utils/pasteTemplate.ts index 89677dd..2655252 100644 --- a/src/main/utils/pasteTemplate.ts +++ b/src/main/utils/pasteTemplate.ts @@ -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: ``, URL: url, UBB: `[IMG]${url}[/IMG]`, - Custom: formatCustomLink(_customLink, item) + Custom: formatCustomLink(_customLink, copyedItem) } return tpl[style] } diff --git a/src/renderer/pages/TrayPage.vue b/src/renderer/pages/TrayPage.vue index ed7061f..4a4c68b 100644 --- a/src/renderer/pages/TrayPage.vue +++ b/src/renderer/pages/TrayPage.vue @@ -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[]>([]) 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('settings.pasteStyle') || IPasteStyle.MARKDOWN const customLink = await getConfig('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: ``, URL: url, UBB: `[IMG]${url}[/IMG]`, - Custom: formatCustomLink(_customLink, item) + Custom: formatCustomLink(_customLink, copyedItem) } return tpl[style] }