Feature: add autoCopy option for users to use or not

This commit is contained in:
Molunerfinn 2020-03-19 21:03:21 +08:00
parent cd70a1a5cc
commit 67e526f163
10 changed files with 51 additions and 17 deletions

View File

@ -15,6 +15,7 @@ import { IWindowList } from '~/main/apis/window/constants'
import picgo from '~/main/apis/picgo'
import pasteTemplate from '#/utils/pasteTemplate'
import pkg from 'root/package.json'
import { handleCopyUrl } from '~/main/utils/common'
let contextMenu: Menu | null
let menu: Menu | null
let tray: Tray | null
@ -148,8 +149,9 @@ export function createTray () {
.setWebContents(trayWindow.webContents)
.upload(files)
if (imgs !== false) {
let pasteText = ''
for (let i = 0; i < imgs.length; i++) {
clipboard.writeText(pasteTemplate(pasteStyle, imgs[i]))
pasteText += pasteTemplate(pasteStyle, imgs[i]) + '\r\n'
const notification = new Notification({
title: '上传成功',
body: imgs[i].imgUrl!,
@ -160,6 +162,7 @@ export function createTray () {
}, i * 100)
db.insert('uploaded', imgs[i])
}
handleCopyUrl(pasteText)
trayWindow.webContents.send('dragFiles', imgs)
}
})

View File

@ -19,6 +19,7 @@ import {
uploadChoosedFiles
} from '~/main/apis/uploader/api'
import picgoCoreIPC from './picgoCoreIPC'
import { handleCopyUrl } from '~/main/utils/common'
export default {
listen () {
@ -29,7 +30,7 @@ export default {
const img = await uploader.setWebContents(trayWindow.webContents).upload()
if (img !== false) {
const pasteStyle = db.get('settings.pasteStyle') || 'markdown'
clipboard.writeText(pasteTemplate(pasteStyle, img[0]))
handleCopyUrl(pasteTemplate(pasteStyle, img[0]))
const notification = new Notification({
title: '上传成功',
body: img[0].imgUrl!,

View File

@ -8,6 +8,7 @@ import {
import db from '#/datastore'
import uploader from '../uploader'
import pasteTemplate from '#/utils/pasteTemplate'
import { handleCopyUrl } from '~/main/utils/common'
import {
getWindowId,
getSettingWindowId
@ -79,7 +80,7 @@ class GuiApi implements IGuiApi {
}, i * 100)
db.insert('uploaded', imgs[i])
}
clipboard.writeText(pasteText)
handleCopyUrl(pasteText)
webContents.send('uploadFiles', imgs)
webContents.send('updateGallery')
return imgs

View File

@ -1,5 +1,4 @@
import {
clipboard,
Notification,
WebContents
} from 'electron'
@ -8,6 +7,7 @@ import { IWindowList } from '~/main/apis/window/constants'
import uploader from './'
import pasteTemplate from '#/utils/pasteTemplate'
import db from '#/datastore'
import { handleCopyUrl } from '~/main/utils/common'
export const uploadClipboardFiles = async (): Promise<string> => {
const win = windowManager.getAvailableWindow()
let img = await uploader.setWebContents(win!.webContents).upload()
@ -15,7 +15,7 @@ export const uploadClipboardFiles = async (): Promise<string> => {
if (img.length > 0) {
const trayWindow = windowManager.get(IWindowList.TRAY_WINDOW)!
const pasteStyle = db.get('settings.pasteStyle') || 'markdown'
clipboard.writeText(pasteTemplate(pasteStyle, img[0]))
handleCopyUrl(pasteTemplate(pasteStyle, img[0]))
const notification = new Notification({
title: '上传成功',
body: img[0].imgUrl!,
@ -62,7 +62,7 @@ export const uploadChoosedFiles = async (webContents: WebContents, files: IFileW
db.insert('uploaded', imgs[i])
result.push(imgs[i].imgUrl!)
}
clipboard.writeText(pasteText)
handleCopyUrl(pasteText)
windowManager.get(IWindowList.TRAY_WINDOW)!.webContents.send('uploadFiles', imgs)
if (windowManager.has(IWindowList.SETTING_WINDOW)) {
windowManager.get(IWindowList.SETTING_WINDOW)!.webContents.send('updateGallery')

View File

@ -12,8 +12,8 @@ export const TRAY_WINDOW_URL = isDevelopment
: `picgo://./index.html`
export const SETTING_WINDOW_URL = isDevelopment
? `${(process.env.WEBPACK_DEV_SERVER_URL as string)}#setting/upload`
: `picgo://./index.html#setting/upload`
? `${(process.env.WEBPACK_DEV_SERVER_URL as string)}#main-page/upload`
: `picgo://./index.html#main-page/upload`
export const MINI_WINDOW_URL = isDevelopment
? `${(process.env.WEBPACK_DEV_SERVER_URL as string)}#mini-page`

8
src/main/utils/common.ts Normal file
View File

@ -0,0 +1,8 @@
import db from '#/datastore'
import { clipboard } from 'electron'
export function handleCopyUrl (str: string): void {
if (db.get('settings.autoCopy') === true) {
clipboard.writeText(str)
}
}

View File

@ -1,5 +1,5 @@
<template>
<div id="setting-page">
<div id="main-page">
<div class="fake-title-bar" :class="{ 'darwin': os === 'darwin' }">
<div class="fake-title-bar__title">
PicGo - {{ version }}
@ -140,7 +140,7 @@ const customLinkRule = (rule: string, value: string, callback: (arg0?: Error) =>
}
}
@Component({
name: 'setting-page',
name: 'main-page',
mixins: [mixin],
components: {
InputBoxDialog
@ -282,7 +282,7 @@ $darwinBg = transparentify(#172426, #000, 0.7)
font-size 20px
text-align center
margin 10px auto
#setting-page
#main-page
.fake-title-bar
-webkit-app-region drag
height h = 22px

View File

@ -4,10 +4,10 @@
PicGo设置 - <i class="el-icon-document" @click="goConfigPage"></i>
</div>
<el-row class="setting-list">
<el-col :span="15" :offset="4">
<el-col :span="16" :offset="4">
<el-row>
<el-form
label-width="120px"
label-width="160px"
label-position="right"
size="small"
>
@ -107,6 +107,16 @@
@change="handleMiniWindowOntop"
></el-switch>
</el-form-item>
<el-form-item
label="上传后自动复制URL"
>
<el-switch
v-model="form.autoCopyUrl"
active-text="开"
inactive-text="关"
@change="handleAutoCopyUrl"
></el-switch>
</el-form-item>
<el-form-item
label="选择显示的图床"
>
@ -336,7 +346,8 @@ export default class extends Vue {
autoRename: db.get('settings.autoRename') || false,
uploadNotification: db.get('settings.uploadNotification') || false,
miniWindowOntop: db.get('settings.miniWindowOntop') || false,
logLevel
logLevel,
autoCopyUrl: db.get('settings.autoCopy') === undefined ? true : db.get('settings.autoCopy')
}
picBed: IPicBedType[] = []
logFileVisible = false
@ -513,6 +524,15 @@ export default class extends Vue {
db.set('settings.miniWindowOntop', val)
this.$message.info('需要重启生效')
}
handleAutoCopyUrl (val: boolean) {
db.set('settings.autoCopy', val)
const successNotification = new Notification('设置自动复制链接', {
body: '设置成功'
})
successNotification.onclick = () => {
return true
}
}
confirmLogLevelSetting () {
if (this.form.logLevel.length === 0) {
return this.$message.error('请选择日志记录等级')

View File

@ -22,9 +22,9 @@ export default new Router({
component: () => import(/* webpackChunkName: "MiniPage" */ '@/pages/MiniPage.vue')
},
{
path: '/setting',
name: 'setting-page',
component: () => import(/* webpackChunkName: "SettingPage" */ '@/layouts/SettingPage.vue'),
path: '/main-page',
name: 'main-page',
component: () => import(/* webpackChunkName: "SettingPage" */ '@/layouts/Main.vue'),
children: [
{
path: 'upload',

View File

@ -7,6 +7,7 @@ interface ISettingForm {
uploadNotification: boolean
miniWindowOntop: boolean
logLevel: string[]
autoCopyUrl: boolean
}
interface IShortKeyMap {