From cfe567b9fb8212112df80c51c0203dcbbe193b82 Mon Sep 17 00:00:00 2001 From: ZiuChen <457353192@qq.com> Date: Thu, 8 Sep 2022 23:49:11 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=A4=9A=E9=80=89?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=20=E6=94=AF=E6=8C=81=E5=90=88=E5=B9=B6?= =?UTF-8?q?=E6=96=87=E6=9C=AC/=E5=9B=BE=E7=89=87/=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/preload.js | 32 ++++++++++-- src/cpns/ClipItemList.vue | 59 +++++++++++++++------- src/style/cpns/clip-item-list.less | 3 ++ src/style/cpns/clip-switch.less | 25 ++++++++-- src/views/Main.vue | 79 ++++++++++++++++++++++++++++-- 5 files changed, 170 insertions(+), 28 deletions(-) diff --git a/public/preload.js b/public/preload.js index 40c9fc3..c7e3491 100644 --- a/public/preload.js +++ b/public/preload.js @@ -15,7 +15,8 @@ const dbName = '_utools_clipboard_manager_storage' const isMacOs = utools.isMacOs() const isWindows = utools.isWindows() -const DBPath = `${isMacOs ? userDataPath : homePath}${isWindows ? '\\' : '/'}${dbName}` +const sep = isWindows ? '\\' : '/' +const DBPath = `${isMacOs ? userDataPath : homePath}${sep}${dbName}` let globalImageOversize = false @@ -45,7 +46,7 @@ class DB { ) this.updateDataBaseLocal() } catch (err) { - utools.showNotification('读取剪切板出错' + err) + utools.showNotification('读取剪切板出错: ' + err) return } return @@ -66,7 +67,7 @@ class DB { // 更新文件数据 fs.writeFileSync(this.path, JSON.stringify(dataBase || this.dataBase), (err) => { if (err) { - utools.showNotification('写入剪切板出错' + err) + utools.showNotification('写入剪切板出错: ' + err) return } }) @@ -186,6 +187,30 @@ const paste = () => { else utools.simulateKeyboardTap('v', 'ctrl') } +const createFile = (item) => { + const tempPath = utools.getPath('temp') + const folderPath = tempPath + sep + 'utools-clipboard-manager' + if (!fs.existsSync(folderPath)) { + try { + fs.mkdirSync(folderPath) + } catch (err) { + utools.showNotification('创建临时文件夹出错: ' + err) + } + } + const { type } = item + if (type === 'image') { + const base64Data = item.data.replace(/^data:image\/\w+;base64,/, '') // remove the prefix + const buffer = Buffer.from(base64Data, 'base64') // to Buffer + const filePath = folderPath + sep + new Date().valueOf() + '.png' + fs.writeFileSync(filePath, buffer) + return filePath + } else if (type === 'text') { + const filePath = folderPath + sep + new Date().valueOf() + '.txt' + fs.writeFileSync(filePath, item.data) + return filePath + } +} + const db = new DB(DBPath) db.init() @@ -231,6 +256,7 @@ window.db = db window.copy = copy window.paste = paste window.remove = remove +window.createFile = createFile window.openFile = utools.shellOpenPath window.openFileFolder = utools.shellShowItemInFolder window.getIcon = utools.getFileIcon diff --git a/src/cpns/ClipItemList.vue b/src/cpns/ClipItemList.vue index a5ee289..37fc496 100644 --- a/src/cpns/ClipItemList.vue +++ b/src/cpns/ClipItemList.vue @@ -7,7 +7,7 @@ @click.left="handleItemClick($event, item)" @click.right="handleItemClick($event, item)" @mouseover="handleMouseOver(index)" - :class="{ active: index === activeIndex }" + :class="{ active: index === activeIndex, select: selectItemList.indexOf(item) !== -1 }" >
@@ -29,7 +29,7 @@
-
+