Skip to content

Commit

Permalink
✨ Feature: add autoCopy option for users to use or not
Browse files Browse the repository at this point in the history
  • Loading branch information
Molunerfinn committed Mar 19, 2020
1 parent cd70a1a commit 67e526f
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 17 deletions.
5 changes: 4 additions & 1 deletion src/main/apis/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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!,
Expand All @@ -160,6 +162,7 @@ export function createTray () {
}, i * 100)
db.insert('uploaded', imgs[i])
}
handleCopyUrl(pasteText)
trayWindow.webContents.send('dragFiles', imgs)
}
})
Expand Down
3 changes: 2 additions & 1 deletion src/main/apis/eventCenter/ipcList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
uploadChoosedFiles
} from '~/main/apis/uploader/api'
import picgoCoreIPC from './picgoCoreIPC'
import { handleCopyUrl } from '~/main/utils/common'

export default {
listen () {
Expand All @@ -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!,
Expand Down
3 changes: 2 additions & 1 deletion src/main/apis/gui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/main/apis/uploader/api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
clipboard,
Notification,
WebContents
} from 'electron'
Expand All @@ -8,14 +7,15 @@ 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()
if (img !== false) {
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!,
Expand Down Expand Up @@ -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')
Expand Down
4 changes: 2 additions & 2 deletions src/main/apis/window/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
8 changes: 8 additions & 0 deletions src/main/utils/common.ts
Original file line number Diff line number Diff line change
@@ -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)
}
}
Original file line number Diff line number Diff line change
@@ -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 }}
Expand Down Expand Up @@ -140,7 +140,7 @@ const customLinkRule = (rule: string, value: string, callback: (arg0?: Error) =>
}
}
@Component({
name: 'setting-page',
name: 'main-page',
mixins: [mixin],
components: {
InputBoxDialog
Expand Down Expand Up @@ -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
Expand Down
26 changes: 23 additions & 3 deletions src/renderer/pages/PicGoSetting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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"
>
Expand Down Expand Up @@ -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="选择显示的图床"
>
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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('请选择日志记录等级')
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions src/universal/types/view.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ interface ISettingForm {
uploadNotification: boolean
miniWindowOntop: boolean
logLevel: string[]
autoCopyUrl: boolean
}

interface IShortKeyMap {
Expand Down

0 comments on commit 67e526f

Please sign in to comment.