Skip to content

Commit

Permalink
✨ Feature: add clipbord listening menu for mini page
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuingsmile committed Apr 12, 2023
1 parent b20c6d7 commit 04d6705
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
29 changes: 28 additions & 1 deletion src/main/events/remotes/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@ import picgoCoreIPC from '~/main/events/picgoCoreIPC'
import { PicGo as PicGoCore } from 'piclist'
import { T } from '~/main/i18n'
import { changeCurrentUploader } from '~/main/utils/handleUploaderConfig'

import db from '~/main/apis/core/datastore'
import clipboardListener from 'clipboard-event'
import clipboardPoll from '~/main/utils/clipboardPoll'
interface GuiMenuItem {
label: string
handle: (arg0: PicGoCore, arg1: GuiApi) => Promise<void>
}

const buildMiniPageMenu = () => {
const isListeningClipboard = db.get('settings.isListeningClipboard') || false
const ClipboardWatcher = process.platform === 'win32' ? clipboardListener : clipboardPoll
const submenu = buildPicBedListMenu()
const template = [
{
Expand Down Expand Up @@ -49,6 +53,29 @@ const buildMiniPageMenu = () => {
BrowserWindow.getFocusedWindow()!.hide()
}
},
{
label: T('START_WATCH_CLIPBOARD'),
click () {
db.set('settings.isListeningClipboard', true)
ClipboardWatcher.startListening()
ClipboardWatcher.on('change', () => {
picgo.log.info('clipboard changed')
uploadClipboardFiles()
})
buildMiniPageMenu()
},
enabled: !isListeningClipboard
},
{
label: T('STOP_WATCH_CLIPBOARD'),
click () {
db.set('settings.isListeningClipboard', false)
ClipboardWatcher.stopListening()
ClipboardWatcher.removeAllListeners()
buildMiniPageMenu()
},
enabled: isListeningClipboard
},
{
label: T('RELOAD_APP'),
click () {
Expand Down
20 changes: 19 additions & 1 deletion src/renderer/pages/TrayPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ 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 { formatCustomLink } from '~/main/utils/pasteTemplate'
import { handleUrlEncode } from '#/utils/common'
const files = ref<IResult<ImgInfo>[]>([])
Expand All @@ -92,6 +91,25 @@ async function getData () {
files.value = (await $$db.get<ImgInfo>({ orderBy: 'desc', limit: 5 })).data
}
const formatCustomLink = (customLink: string, item: ImgInfo) => {
const fileName = item.fileName!.replace(new RegExp(`\\${item.extname}$`), '')
const url = item.url || item.imgUrl
const extName = item.extname
const formatObj = {
url,
fileName,
extName
}
const keys = Object.keys(formatObj) as ['url', 'fileName', 'extName']
keys.forEach(item => {
if (customLink.indexOf(`$${item}`) !== -1) {
const reg = new RegExp(`\\$${item}`, 'g')
customLink = customLink.replace(reg, formatObj[item])
}
})
return customLink
}
async function copyTheLink (item: ImgInfo) {
notification.body = item.imgUrl!
const pasteStyle = await getConfig<IPasteStyle>('settings.pasteStyle') || IPasteStyle.MARKDOWN
Expand Down

0 comments on commit 04d6705

Please sign in to comment.