2017-11-27 19:21:12 -05:00
|
|
|
'use strict'
|
|
|
|
|
2018-12-18 05:58:31 -05:00
|
|
|
import Uploader from './utils/uploader.js'
|
2019-05-22 12:13:12 -04:00
|
|
|
import {
|
|
|
|
app,
|
|
|
|
BrowserWindow,
|
|
|
|
Tray,
|
|
|
|
Menu,
|
|
|
|
Notification,
|
|
|
|
clipboard,
|
|
|
|
ipcMain,
|
|
|
|
globalShortcut,
|
|
|
|
dialog,
|
|
|
|
systemPreferences
|
|
|
|
} from 'electron'
|
2017-11-28 10:56:15 -05:00
|
|
|
import db from '../datastore'
|
2019-04-15 03:25:33 -04:00
|
|
|
import beforeOpen from './utils/beforeOpen'
|
2017-11-28 10:56:15 -05:00
|
|
|
import pasteTemplate from './utils/pasteTemplate'
|
2017-12-23 03:38:19 -05:00
|
|
|
import updateChecker from './utils/updateChecker'
|
2018-12-23 10:15:00 -05:00
|
|
|
import { getPicBeds } from './utils/getPicBeds'
|
2018-01-09 22:31:07 -05:00
|
|
|
import pkg from '../../package.json'
|
2018-09-18 06:48:55 -04:00
|
|
|
import picgoCoreIPC from './utils/picgoCoreIPC'
|
2019-01-12 06:19:26 -05:00
|
|
|
import fixPath from 'fix-path'
|
2019-04-14 03:41:48 -04:00
|
|
|
import { getUploadFiles } from './utils/handleArgv'
|
2019-09-10 02:38:08 -04:00
|
|
|
import bus from './utils/eventBus'
|
|
|
|
import {
|
|
|
|
updateShortKeyFromVersion212
|
|
|
|
} from './migrate/shortKeyUpdateHelper'
|
|
|
|
import {
|
2019-09-11 03:31:27 -04:00
|
|
|
shortKeyUpdater,
|
2019-09-10 02:38:08 -04:00
|
|
|
initShortKeyRegister
|
|
|
|
} from './utils/shortKeyRegister'
|
2019-04-15 03:25:33 -04:00
|
|
|
if (process.platform === 'darwin') {
|
|
|
|
beforeOpen()
|
|
|
|
}
|
2017-11-27 19:21:12 -05:00
|
|
|
/**
|
|
|
|
* Set `__static` path to static files in production
|
|
|
|
* https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-static-assets.html
|
|
|
|
*/
|
|
|
|
if (process.env.NODE_ENV !== 'development') {
|
|
|
|
global.__static = require('path').join(__dirname, '/static').replace(/\\/g, '\\\\')
|
|
|
|
}
|
2018-01-12 04:24:07 -05:00
|
|
|
if (process.env.DEBUG_ENV === 'debug') {
|
|
|
|
global.__static = require('path').join(__dirname, '../../static').replace(/\\/g, '\\\\')
|
|
|
|
}
|
2017-11-27 19:21:12 -05:00
|
|
|
|
|
|
|
let window
|
|
|
|
let settingWindow
|
2018-07-05 12:43:53 -04:00
|
|
|
let miniWindow
|
2017-11-27 19:21:12 -05:00
|
|
|
let tray
|
2017-12-15 04:37:38 -05:00
|
|
|
let menu
|
2018-01-30 02:20:19 -05:00
|
|
|
let contextMenu
|
2017-11-27 19:21:12 -05:00
|
|
|
const winURL = process.env.NODE_ENV === 'development'
|
|
|
|
? `http://localhost:9080`
|
|
|
|
: `file://${__dirname}/index.html`
|
|
|
|
const settingWinURL = process.env.NODE_ENV === 'development'
|
|
|
|
? `http://localhost:9080/#setting/upload`
|
|
|
|
: `file://${__dirname}/index.html#setting/upload`
|
2018-07-05 12:43:53 -04:00
|
|
|
const miniWinURL = process.env.NODE_ENV === 'development'
|
|
|
|
? `http://localhost:9080/#mini-page`
|
|
|
|
: `file://${__dirname}/index.html#mini-page`
|
2017-11-27 19:21:12 -05:00
|
|
|
|
2019-01-12 06:19:26 -05:00
|
|
|
// fix the $PATH in macOS
|
|
|
|
fixPath()
|
|
|
|
|
2018-12-25 03:11:10 -05:00
|
|
|
function createContextMenu () {
|
2018-12-23 10:15:00 -05:00
|
|
|
const picBeds = getPicBeds(app)
|
|
|
|
const submenu = picBeds.map(item => {
|
2018-06-05 08:29:16 -04:00
|
|
|
return {
|
|
|
|
label: item.name,
|
|
|
|
type: 'radio',
|
2019-09-11 07:30:08 -04:00
|
|
|
checked: db.get('picBed.current') === item.type,
|
2018-06-05 08:29:16 -04:00
|
|
|
click () {
|
2019-09-11 07:30:08 -04:00
|
|
|
db.set('picBed.current', item.type)
|
2018-07-10 10:37:29 -04:00
|
|
|
if (settingWindow) {
|
|
|
|
settingWindow.webContents.send('syncPicBed')
|
|
|
|
}
|
2018-06-05 08:29:16 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2018-01-30 02:20:19 -05:00
|
|
|
contextMenu = Menu.buildFromTemplate([
|
2018-01-09 22:31:07 -05:00
|
|
|
{
|
|
|
|
label: '关于',
|
|
|
|
click () {
|
|
|
|
dialog.showMessageBox({
|
|
|
|
title: 'PicGo',
|
|
|
|
message: 'PicGo',
|
|
|
|
detail: `Version: ${pkg.version}\nAuthor: Molunerfinn\nGithub: https://github.com/Molunerfinn/PicGo`
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
2017-11-27 19:21:12 -05:00
|
|
|
{
|
2017-11-28 10:56:15 -05:00
|
|
|
label: '打开详细窗口',
|
2017-11-27 19:21:12 -05:00
|
|
|
click () {
|
|
|
|
if (settingWindow === null) {
|
|
|
|
createSettingWindow()
|
2017-12-11 08:52:14 -05:00
|
|
|
settingWindow.show()
|
2017-11-27 19:21:12 -05:00
|
|
|
} else {
|
|
|
|
settingWindow.show()
|
|
|
|
settingWindow.focus()
|
|
|
|
}
|
2018-07-07 02:45:14 -04:00
|
|
|
if (miniWindow) {
|
|
|
|
miniWindow.hide()
|
|
|
|
}
|
2017-11-27 19:21:12 -05:00
|
|
|
}
|
2017-11-28 10:56:15 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: '选择默认图床',
|
|
|
|
type: 'submenu',
|
2018-06-05 08:29:16 -04:00
|
|
|
submenu
|
2017-12-11 08:52:14 -05:00
|
|
|
},
|
2018-01-10 04:12:24 -05:00
|
|
|
{
|
|
|
|
label: '打开更新助手',
|
|
|
|
type: 'checkbox',
|
2019-09-11 07:30:08 -04:00
|
|
|
checked: db.get('settings.showUpdateTip'),
|
2018-01-10 04:12:24 -05:00
|
|
|
click () {
|
2019-09-11 07:30:08 -04:00
|
|
|
const value = db.get('settings.showUpdateTip')
|
|
|
|
db.set('settings.showUpdateTip', !value)
|
2018-01-10 04:12:24 -05:00
|
|
|
}
|
|
|
|
},
|
2019-01-21 03:46:33 -05:00
|
|
|
{
|
|
|
|
label: '重启应用',
|
|
|
|
click () {
|
|
|
|
app.relaunch()
|
|
|
|
app.exit(0)
|
|
|
|
}
|
|
|
|
},
|
2017-12-11 08:52:14 -05:00
|
|
|
{
|
|
|
|
role: 'quit',
|
|
|
|
label: '退出'
|
2017-11-27 19:21:12 -05:00
|
|
|
}
|
|
|
|
])
|
2018-12-25 03:11:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function createTray () {
|
|
|
|
const menubarPic = process.platform === 'darwin' ? `${__static}/menubar.png` : `${__static}/menubar-nodarwin.png`
|
|
|
|
tray = new Tray(menubarPic)
|
2017-11-27 19:21:12 -05:00
|
|
|
tray.on('right-click', () => {
|
2018-06-26 05:03:46 -04:00
|
|
|
if (window) {
|
|
|
|
window.hide()
|
|
|
|
}
|
2018-12-25 03:11:10 -05:00
|
|
|
createContextMenu()
|
2017-11-27 19:21:12 -05:00
|
|
|
tray.popUpContextMenu(contextMenu)
|
|
|
|
})
|
2018-10-20 11:24:28 -04:00
|
|
|
tray.on('click', (event, bounds) => {
|
2018-01-10 03:51:09 -05:00
|
|
|
if (process.platform === 'darwin') {
|
|
|
|
let img = clipboard.readImage()
|
|
|
|
let obj = []
|
|
|
|
if (!img.isEmpty()) {
|
|
|
|
// 从剪贴板来的图片默认转为png
|
|
|
|
const imgUrl = 'data:image/png;base64,' + Buffer.from(img.toPNG(), 'binary').toString('base64')
|
|
|
|
obj.push({
|
|
|
|
width: img.getSize().width,
|
|
|
|
height: img.getSize().height,
|
|
|
|
imgUrl
|
|
|
|
})
|
|
|
|
}
|
2018-10-20 11:24:28 -04:00
|
|
|
toggleWindow(bounds)
|
2018-01-10 03:51:09 -05:00
|
|
|
setTimeout(() => {
|
|
|
|
window.webContents.send('clipboardFiles', obj)
|
|
|
|
}, 0)
|
|
|
|
} else {
|
2018-06-26 05:03:46 -04:00
|
|
|
if (window) {
|
|
|
|
window.hide()
|
|
|
|
}
|
2018-01-10 03:51:09 -05:00
|
|
|
if (settingWindow === null) {
|
|
|
|
createSettingWindow()
|
|
|
|
settingWindow.show()
|
|
|
|
} else {
|
|
|
|
settingWindow.show()
|
|
|
|
settingWindow.focus()
|
|
|
|
}
|
2018-09-13 04:54:18 -04:00
|
|
|
if (miniWindow) {
|
|
|
|
miniWindow.hide()
|
|
|
|
}
|
2017-11-27 19:21:12 -05:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
tray.on('drag-enter', () => {
|
2019-05-22 12:13:12 -04:00
|
|
|
if (systemPreferences.isDarkMode()) {
|
|
|
|
tray.setImage(`${__static}/upload-dark.png`)
|
|
|
|
} else {
|
|
|
|
tray.setImage(`${__static}/upload.png`)
|
|
|
|
}
|
2017-11-27 19:21:12 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
tray.on('drag-end', () => {
|
2017-12-11 08:52:14 -05:00
|
|
|
tray.setImage(`${__static}/menubar.png`)
|
2017-11-27 19:21:12 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
tray.on('drop-files', async (event, files) => {
|
2019-09-11 07:30:08 -04:00
|
|
|
const pasteStyle = db.get('settings.pasteStyle') || 'markdown'
|
2019-01-11 04:22:33 -05:00
|
|
|
const imgs = await new Uploader(files, window.webContents).upload()
|
2017-12-22 09:30:16 -05:00
|
|
|
if (imgs !== false) {
|
|
|
|
for (let i in imgs) {
|
2019-04-18 05:25:10 -04:00
|
|
|
clipboard.writeText(pasteTemplate(pasteStyle, imgs[i]))
|
2017-12-22 09:30:16 -05:00
|
|
|
const notification = new Notification({
|
|
|
|
title: '上传成功',
|
|
|
|
body: imgs[i].imgUrl,
|
|
|
|
icon: files[i]
|
|
|
|
})
|
|
|
|
setTimeout(() => {
|
|
|
|
notification.show()
|
|
|
|
}, i * 100)
|
2019-09-11 07:30:08 -04:00
|
|
|
db.insert('uploaded', imgs[i])
|
2017-12-22 09:30:16 -05:00
|
|
|
}
|
|
|
|
window.webContents.send('dragFiles', imgs)
|
2017-11-27 19:21:12 -05:00
|
|
|
}
|
|
|
|
})
|
2017-12-08 02:52:41 -05:00
|
|
|
// toggleWindow()
|
2017-11-27 19:21:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
const createWindow = () => {
|
2018-06-26 05:03:46 -04:00
|
|
|
if (process.platform !== 'darwin' && process.platform !== 'win32') {
|
|
|
|
return
|
|
|
|
}
|
2017-11-27 19:21:12 -05:00
|
|
|
window = new BrowserWindow({
|
|
|
|
height: 350,
|
|
|
|
width: 196, // 196
|
|
|
|
show: false,
|
|
|
|
frame: false,
|
|
|
|
fullscreenable: false,
|
|
|
|
resizable: false,
|
|
|
|
transparent: true,
|
|
|
|
vibrancy: 'ultra-dark',
|
|
|
|
webPreferences: {
|
2019-05-05 10:22:03 -04:00
|
|
|
nodeIntegration: true,
|
|
|
|
nodeIntegrationInWorker: true,
|
2017-11-27 19:21:12 -05:00
|
|
|
backgroundThrottling: false
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
window.loadURL(winURL)
|
|
|
|
|
|
|
|
window.on('closed', () => {
|
|
|
|
window = null
|
|
|
|
})
|
|
|
|
|
|
|
|
window.on('blur', () => {
|
|
|
|
window.hide()
|
|
|
|
})
|
2019-04-14 03:41:48 -04:00
|
|
|
return window
|
2017-11-27 19:21:12 -05:00
|
|
|
}
|
|
|
|
|
2018-07-05 12:43:53 -04:00
|
|
|
const createMiniWidow = () => {
|
2018-07-06 11:54:36 -04:00
|
|
|
if (miniWindow) {
|
|
|
|
return false
|
|
|
|
}
|
2018-07-10 21:39:23 -04:00
|
|
|
let obj = {
|
2018-07-05 12:43:53 -04:00
|
|
|
height: 64,
|
2018-07-06 11:54:36 -04:00
|
|
|
width: 64,
|
2019-04-17 02:45:08 -04:00
|
|
|
show: process.platform === 'linux',
|
2018-07-05 12:43:53 -04:00
|
|
|
frame: false,
|
|
|
|
fullscreenable: false,
|
2019-01-21 03:46:33 -05:00
|
|
|
skipTaskbar: true,
|
2018-07-05 12:43:53 -04:00
|
|
|
resizable: false,
|
2019-04-17 02:45:08 -04:00
|
|
|
transparent: process.platform !== 'linux',
|
2018-07-06 12:01:06 -04:00
|
|
|
icon: `${__static}/logo.png`,
|
2018-07-05 12:43:53 -04:00
|
|
|
webPreferences: {
|
2019-05-05 10:22:03 -04:00
|
|
|
backgroundThrottling: false,
|
|
|
|
nodeIntegration: true,
|
|
|
|
nodeIntegrationInWorker: true
|
2018-07-05 12:43:53 -04:00
|
|
|
}
|
2018-07-10 21:39:23 -04:00
|
|
|
}
|
|
|
|
|
2019-09-11 07:30:08 -04:00
|
|
|
if (db.get('settings.miniWindowOntop')) {
|
2018-09-07 05:32:11 -04:00
|
|
|
obj.alwaysOnTop = true
|
|
|
|
}
|
|
|
|
|
2018-07-10 21:39:23 -04:00
|
|
|
miniWindow = new BrowserWindow(obj)
|
2018-07-05 12:43:53 -04:00
|
|
|
|
|
|
|
miniWindow.loadURL(miniWinURL)
|
|
|
|
|
|
|
|
miniWindow.on('closed', () => {
|
|
|
|
miniWindow = null
|
|
|
|
})
|
2019-04-14 03:41:48 -04:00
|
|
|
return miniWindow
|
2018-07-05 12:43:53 -04:00
|
|
|
}
|
|
|
|
|
2017-11-27 19:21:12 -05:00
|
|
|
const createSettingWindow = () => {
|
2018-01-10 03:51:09 -05:00
|
|
|
const options = {
|
2017-11-27 19:21:12 -05:00
|
|
|
height: 450,
|
|
|
|
width: 800,
|
2017-12-08 02:52:41 -05:00
|
|
|
show: false,
|
2017-11-27 19:21:12 -05:00
|
|
|
frame: true,
|
|
|
|
center: true,
|
|
|
|
fullscreenable: false,
|
|
|
|
resizable: false,
|
2018-01-10 03:51:09 -05:00
|
|
|
title: 'PicGo',
|
2017-11-27 19:21:12 -05:00
|
|
|
vibrancy: 'ultra-dark',
|
|
|
|
transparent: true,
|
|
|
|
titleBarStyle: 'hidden',
|
|
|
|
webPreferences: {
|
2018-09-18 06:48:55 -04:00
|
|
|
backgroundThrottling: false,
|
2019-05-05 10:22:03 -04:00
|
|
|
nodeIntegration: true,
|
|
|
|
nodeIntegrationInWorker: true,
|
2018-09-18 06:48:55 -04:00
|
|
|
webSecurity: false
|
2017-11-27 19:21:12 -05:00
|
|
|
}
|
2018-01-10 03:51:09 -05:00
|
|
|
}
|
2018-06-25 07:27:41 -04:00
|
|
|
if (process.platform !== 'darwin') {
|
2018-09-13 04:54:18 -04:00
|
|
|
options.show = false
|
2018-01-10 03:51:09 -05:00
|
|
|
options.frame = false
|
|
|
|
options.backgroundColor = '#3f3c37'
|
2018-06-25 07:27:41 -04:00
|
|
|
options.transparent = false
|
2018-07-05 12:43:53 -04:00
|
|
|
options.icon = `${__static}/logo.png`
|
2018-01-10 03:51:09 -05:00
|
|
|
}
|
|
|
|
settingWindow = new BrowserWindow(options)
|
2017-11-27 19:21:12 -05:00
|
|
|
|
|
|
|
settingWindow.loadURL(settingWinURL)
|
|
|
|
|
|
|
|
settingWindow.on('closed', () => {
|
|
|
|
settingWindow = null
|
2018-07-10 22:04:42 -04:00
|
|
|
if (process.platform === 'linux') {
|
|
|
|
app.quit()
|
|
|
|
}
|
2017-11-27 19:21:12 -05:00
|
|
|
})
|
2018-06-26 05:03:46 -04:00
|
|
|
createMenu()
|
2018-07-05 12:43:53 -04:00
|
|
|
createMiniWidow()
|
2019-04-14 03:41:48 -04:00
|
|
|
return settingWindow
|
2017-11-27 19:21:12 -05:00
|
|
|
}
|
|
|
|
|
2017-12-15 04:37:38 -05:00
|
|
|
const createMenu = () => {
|
2018-01-09 22:31:07 -05:00
|
|
|
if (process.env.NODE_ENV !== 'development') {
|
|
|
|
const template = [{
|
|
|
|
label: 'Edit',
|
|
|
|
submenu: [
|
|
|
|
{ label: 'Undo', accelerator: 'CmdOrCtrl+Z', selector: 'undo:' },
|
|
|
|
{ label: 'Redo', accelerator: 'Shift+CmdOrCtrl+Z', selector: 'redo:' },
|
|
|
|
{ type: 'separator' },
|
|
|
|
{ label: 'Cut', accelerator: 'CmdOrCtrl+X', selector: 'cut:' },
|
|
|
|
{ label: 'Copy', accelerator: 'CmdOrCtrl+C', selector: 'copy:' },
|
|
|
|
{ label: 'Paste', accelerator: 'CmdOrCtrl+V', selector: 'paste:' },
|
|
|
|
{ label: 'Select All', accelerator: 'CmdOrCtrl+A', selector: 'selectAll:' },
|
|
|
|
{
|
|
|
|
label: 'Quit',
|
|
|
|
accelerator: 'CmdOrCtrl+Q',
|
|
|
|
click () {
|
|
|
|
app.quit()
|
|
|
|
}
|
2017-12-15 04:37:38 -05:00
|
|
|
}
|
2018-01-09 22:31:07 -05:00
|
|
|
]
|
|
|
|
}]
|
|
|
|
menu = Menu.buildFromTemplate(template)
|
|
|
|
Menu.setApplicationMenu(menu)
|
|
|
|
}
|
2017-12-15 04:37:38 -05:00
|
|
|
}
|
|
|
|
|
2018-10-20 11:24:28 -04:00
|
|
|
const toggleWindow = (bounds) => {
|
2017-11-27 19:21:12 -05:00
|
|
|
if (window.isVisible()) {
|
|
|
|
window.hide()
|
|
|
|
} else {
|
2018-10-20 11:24:28 -04:00
|
|
|
showWindow(bounds)
|
2017-11-27 19:21:12 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-20 11:24:28 -04:00
|
|
|
const showWindow = (bounds) => {
|
|
|
|
window.setPosition(bounds.x - 98 + 11, bounds.y, false)
|
2017-12-07 01:33:14 -05:00
|
|
|
window.webContents.send('updateFiles')
|
2017-11-27 19:21:12 -05:00
|
|
|
window.show()
|
|
|
|
window.focus()
|
|
|
|
}
|
|
|
|
|
2017-12-23 06:46:20 -05:00
|
|
|
const uploadClipboardFiles = async () => {
|
2018-07-07 03:06:36 -04:00
|
|
|
let win
|
2018-11-28 22:14:45 -05:00
|
|
|
if (miniWindow.isVisible()) {
|
2018-07-07 03:06:36 -04:00
|
|
|
win = miniWindow
|
|
|
|
} else {
|
2019-04-14 03:41:48 -04:00
|
|
|
win = settingWindow || window || createSettingWindow()
|
2018-07-07 03:06:36 -04:00
|
|
|
}
|
2019-01-12 03:09:24 -05:00
|
|
|
let img = await new Uploader(undefined, win.webContents).upload()
|
2017-12-23 06:46:20 -05:00
|
|
|
if (img !== false) {
|
2018-01-30 02:20:19 -05:00
|
|
|
if (img.length > 0) {
|
2019-09-11 07:30:08 -04:00
|
|
|
const pasteStyle = db.get('settings.pasteStyle') || 'markdown'
|
2019-04-18 05:25:10 -04:00
|
|
|
clipboard.writeText(pasteTemplate(pasteStyle, img[0]))
|
2018-01-30 02:20:19 -05:00
|
|
|
const notification = new Notification({
|
|
|
|
title: '上传成功',
|
|
|
|
body: img[0].imgUrl,
|
|
|
|
icon: img[0].imgUrl
|
|
|
|
})
|
|
|
|
notification.show()
|
2019-09-11 07:30:08 -04:00
|
|
|
db.insert('uploaded', img[0])
|
2018-01-30 02:20:19 -05:00
|
|
|
window.webContents.send('clipboardFiles', [])
|
|
|
|
window.webContents.send('uploadFiles', img)
|
2018-08-07 23:21:08 -04:00
|
|
|
if (settingWindow) {
|
|
|
|
settingWindow.webContents.send('updateGallery')
|
|
|
|
}
|
2018-01-30 02:20:19 -05:00
|
|
|
} else {
|
|
|
|
const notification = new Notification({
|
|
|
|
title: '上传不成功',
|
|
|
|
body: '你剪贴板最新的一条记录不是图片哦'
|
|
|
|
})
|
|
|
|
notification.show()
|
|
|
|
}
|
2017-12-23 06:46:20 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-14 03:41:48 -04:00
|
|
|
const uploadChoosedFiles = async (webContents, files) => {
|
|
|
|
const input = files.map(item => item.path)
|
|
|
|
const imgs = await new Uploader(input, webContents).upload()
|
|
|
|
if (imgs !== false) {
|
2019-09-11 07:30:08 -04:00
|
|
|
const pasteStyle = db.get('settings.pasteStyle') || 'markdown'
|
2019-04-14 03:41:48 -04:00
|
|
|
let pasteText = ''
|
|
|
|
for (let i in imgs) {
|
2019-04-18 05:25:10 -04:00
|
|
|
pasteText += pasteTemplate(pasteStyle, imgs[i]) + '\r\n'
|
2019-04-14 03:41:48 -04:00
|
|
|
const notification = new Notification({
|
|
|
|
title: '上传成功',
|
|
|
|
body: imgs[i].imgUrl,
|
|
|
|
icon: files[i].path
|
|
|
|
})
|
|
|
|
setTimeout(() => {
|
|
|
|
notification.show()
|
|
|
|
}, i * 100)
|
2019-09-11 07:30:08 -04:00
|
|
|
db.insert('uploaded', imgs[i])
|
2019-04-14 03:41:48 -04:00
|
|
|
}
|
|
|
|
clipboard.writeText(pasteText)
|
|
|
|
window.webContents.send('uploadFiles', imgs)
|
|
|
|
if (settingWindow) {
|
|
|
|
settingWindow.webContents.send('updateGallery')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:48:55 -04:00
|
|
|
picgoCoreIPC(app, ipcMain)
|
|
|
|
|
2018-12-27 22:10:28 -05:00
|
|
|
// from macOS tray
|
2017-11-27 19:21:12 -05:00
|
|
|
ipcMain.on('uploadClipboardFiles', async (evt, file) => {
|
2019-01-25 06:16:52 -05:00
|
|
|
const img = await new Uploader(undefined, window.webContents).upload()
|
2017-12-22 09:30:16 -05:00
|
|
|
if (img !== false) {
|
2019-09-11 07:30:08 -04:00
|
|
|
const pasteStyle = db.get('settings.pasteStyle') || 'markdown'
|
2019-04-18 05:25:10 -04:00
|
|
|
clipboard.writeText(pasteTemplate(pasteStyle, img[0]))
|
2017-12-22 09:30:16 -05:00
|
|
|
const notification = new Notification({
|
|
|
|
title: '上传成功',
|
|
|
|
body: img[0].imgUrl,
|
2017-12-23 06:46:20 -05:00
|
|
|
// icon: file[0]
|
|
|
|
icon: img[0].imgUrl
|
2017-12-22 09:30:16 -05:00
|
|
|
})
|
|
|
|
notification.show()
|
2019-09-11 07:30:08 -04:00
|
|
|
db.insert('uploaded', img[0])
|
2017-12-22 09:30:16 -05:00
|
|
|
window.webContents.send('clipboardFiles', [])
|
2018-08-07 23:21:08 -04:00
|
|
|
if (settingWindow) {
|
|
|
|
settingWindow.webContents.send('updateGallery')
|
|
|
|
}
|
2017-12-22 09:30:16 -05:00
|
|
|
}
|
2019-01-25 06:16:52 -05:00
|
|
|
window.webContents.send('uploadFiles')
|
2017-11-28 10:56:15 -05:00
|
|
|
})
|
|
|
|
|
2018-01-30 02:20:19 -05:00
|
|
|
ipcMain.on('uploadClipboardFilesFromUploadPage', () => {
|
|
|
|
uploadClipboardFiles()
|
|
|
|
})
|
|
|
|
|
2017-11-28 10:56:15 -05:00
|
|
|
ipcMain.on('uploadChoosedFiles', async (evt, files) => {
|
2019-04-15 22:45:09 -04:00
|
|
|
return uploadChoosedFiles(evt.sender, files)
|
2017-11-27 19:21:12 -05:00
|
|
|
})
|
|
|
|
|
2019-09-11 03:31:27 -04:00
|
|
|
ipcMain.on('updateShortKey', (evt, item) => {
|
|
|
|
shortKeyUpdater(globalShortcut, item)
|
2018-01-30 02:20:19 -05:00
|
|
|
const notification = new Notification({
|
|
|
|
title: '操作成功',
|
|
|
|
body: '你的快捷键已经修改成功'
|
|
|
|
})
|
|
|
|
notification.show()
|
|
|
|
})
|
|
|
|
|
2018-03-09 01:35:41 -05:00
|
|
|
ipcMain.on('updateCustomLink', (evt, oldLink) => {
|
|
|
|
const notification = new Notification({
|
|
|
|
title: '操作成功',
|
|
|
|
body: '你的自定义链接格式已经修改成功'
|
|
|
|
})
|
|
|
|
notification.show()
|
|
|
|
})
|
|
|
|
|
2018-05-02 07:34:24 -04:00
|
|
|
ipcMain.on('autoStart', (evt, val) => {
|
|
|
|
app.setLoginItemSettings({
|
|
|
|
openAtLogin: val
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-07-06 11:54:36 -04:00
|
|
|
ipcMain.on('openSettingWindow', (evt) => {
|
|
|
|
if (!settingWindow) {
|
|
|
|
createSettingWindow()
|
|
|
|
} else {
|
|
|
|
settingWindow.show()
|
|
|
|
}
|
|
|
|
miniWindow.hide()
|
|
|
|
})
|
|
|
|
|
|
|
|
ipcMain.on('openMiniWindow', (evt) => {
|
|
|
|
if (!miniWindow) {
|
|
|
|
createMiniWidow()
|
|
|
|
}
|
|
|
|
miniWindow.show()
|
2018-07-07 02:45:14 -04:00
|
|
|
miniWindow.focus()
|
2018-07-06 11:54:36 -04:00
|
|
|
settingWindow.hide()
|
|
|
|
})
|
|
|
|
|
2018-07-10 10:37:29 -04:00
|
|
|
// from mini window
|
|
|
|
ipcMain.on('syncPicBed', (evt) => {
|
|
|
|
if (settingWindow) {
|
|
|
|
settingWindow.webContents.send('syncPicBed')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-12-23 10:15:00 -05:00
|
|
|
ipcMain.on('getPicBeds', (evt) => {
|
|
|
|
const picBeds = getPicBeds(app)
|
|
|
|
evt.sender.send('getPicBeds', picBeds)
|
2018-12-25 03:11:10 -05:00
|
|
|
evt.returnValue = picBeds
|
2018-12-23 10:15:00 -05:00
|
|
|
})
|
|
|
|
|
2019-09-11 03:31:27 -04:00
|
|
|
ipcMain.on('updateShortKey', (evt, val) => {
|
|
|
|
// console.log(val)
|
|
|
|
})
|
|
|
|
|
|
|
|
// const shortKeyHash = {
|
|
|
|
// upload: uploadClipboardFiles
|
|
|
|
// }
|
2018-01-30 02:20:19 -05:00
|
|
|
|
2018-12-25 04:28:12 -05:00
|
|
|
const gotTheLock = app.requestSingleInstanceLock()
|
|
|
|
|
|
|
|
if (!gotTheLock) {
|
|
|
|
app.quit()
|
|
|
|
} else {
|
2019-04-14 03:41:48 -04:00
|
|
|
app.on('second-instance', (event, commandLine, workingDirectory) => {
|
|
|
|
let files = getUploadFiles(commandLine, workingDirectory)
|
2019-04-14 22:28:11 -04:00
|
|
|
if (files === null || files.length > 0) { // 如果有文件列表作为参数,说明是命令行启动
|
|
|
|
if (files === null) {
|
|
|
|
uploadClipboardFiles()
|
2019-04-14 03:41:48 -04:00
|
|
|
} else {
|
2019-04-14 22:28:11 -04:00
|
|
|
let win
|
|
|
|
if (miniWindow && miniWindow.isVisible()) {
|
|
|
|
win = miniWindow
|
|
|
|
} else {
|
|
|
|
win = settingWindow || window || createSettingWindow()
|
|
|
|
}
|
|
|
|
uploadChoosedFiles(win.webContents, files)
|
2019-04-14 03:41:48 -04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (settingWindow) {
|
|
|
|
if (settingWindow.isMinimized()) {
|
|
|
|
settingWindow.restore()
|
|
|
|
}
|
|
|
|
settingWindow.focus()
|
|
|
|
}
|
2018-01-09 22:31:07 -05:00
|
|
|
}
|
2019-04-14 03:41:48 -04:00
|
|
|
})
|
2018-01-09 22:31:07 -05:00
|
|
|
}
|
|
|
|
|
2018-01-10 03:51:09 -05:00
|
|
|
if (process.platform === 'win32') {
|
|
|
|
app.setAppUserModelId(pkg.build.appId)
|
|
|
|
}
|
|
|
|
|
2018-06-26 05:03:46 -04:00
|
|
|
if (process.env.XDG_CURRENT_DESKTOP && process.env.XDG_CURRENT_DESKTOP.includes('Unity')) {
|
|
|
|
process.env.XDG_CURRENT_DESKTOP = 'Unity'
|
|
|
|
}
|
|
|
|
|
2017-11-27 19:21:12 -05:00
|
|
|
app.on('ready', () => {
|
|
|
|
createWindow()
|
2018-06-26 05:03:46 -04:00
|
|
|
createSettingWindow()
|
|
|
|
if (process.platform === 'darwin' || process.platform === 'win32') {
|
|
|
|
createTray()
|
|
|
|
}
|
2019-09-11 07:30:08 -04:00
|
|
|
db.set('needReload', false)
|
2017-12-23 03:38:19 -05:00
|
|
|
updateChecker()
|
2019-09-10 02:38:08 -04:00
|
|
|
initEventCenter()
|
|
|
|
// 不需要阻塞
|
|
|
|
process.nextTick(() => {
|
2019-09-11 07:30:08 -04:00
|
|
|
updateShortKeyFromVersion212(db, db.get('settings.shortKey'))
|
|
|
|
initShortKeyRegister(globalShortcut, db.get('settings.shortKey'))
|
2017-12-23 06:46:20 -05:00
|
|
|
})
|
2019-09-10 02:38:08 -04:00
|
|
|
|
2019-04-14 10:07:33 -04:00
|
|
|
if (process.env.NODE_ENV !== 'development') {
|
|
|
|
let files = getUploadFiles()
|
2019-04-14 22:28:11 -04:00
|
|
|
if (files === null || files.length > 0) { // 如果有文件列表作为参数,说明是命令行启动
|
|
|
|
if (files === null) {
|
|
|
|
uploadClipboardFiles()
|
2019-04-14 10:07:33 -04:00
|
|
|
} else {
|
2019-04-14 22:28:11 -04:00
|
|
|
let win
|
|
|
|
if (miniWindow && miniWindow.isVisible()) {
|
|
|
|
win = miniWindow
|
|
|
|
} else {
|
|
|
|
win = settingWindow || window || createSettingWindow()
|
|
|
|
}
|
|
|
|
uploadChoosedFiles(win.webContents, files)
|
2019-04-14 10:07:33 -04:00
|
|
|
}
|
2019-04-14 03:41:48 -04:00
|
|
|
}
|
|
|
|
}
|
2017-11-27 19:21:12 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
app.on('window-all-closed', () => {
|
|
|
|
if (process.platform !== 'darwin') {
|
|
|
|
app.quit()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
app.on('activate', () => {
|
2018-06-26 05:03:46 -04:00
|
|
|
if (window === null) {
|
2017-11-27 19:21:12 -05:00
|
|
|
createWindow()
|
|
|
|
}
|
2018-06-26 05:03:46 -04:00
|
|
|
if (settingWindow === null) {
|
|
|
|
createSettingWindow()
|
|
|
|
}
|
2017-11-27 19:21:12 -05:00
|
|
|
})
|
|
|
|
|
2017-12-23 06:46:20 -05:00
|
|
|
app.on('will-quit', () => {
|
|
|
|
globalShortcut.unregisterAll()
|
2019-09-10 02:38:08 -04:00
|
|
|
bus.removeAllListeners()
|
2017-12-23 06:46:20 -05:00
|
|
|
})
|
|
|
|
|
2018-05-02 05:17:55 -04:00
|
|
|
app.setLoginItemSettings({
|
2019-09-11 07:30:08 -04:00
|
|
|
openAtLogin: db.get('settings.autoStart') || false
|
2018-05-02 05:17:55 -04:00
|
|
|
})
|
|
|
|
|
2019-09-10 02:38:08 -04:00
|
|
|
function initEventCenter () {
|
|
|
|
const eventList = {
|
|
|
|
'picgo:upload': uploadClipboardFiles
|
|
|
|
}
|
|
|
|
for (let i in eventList) {
|
|
|
|
bus.on(i, eventList[i])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-27 19:21:12 -05:00
|
|
|
/**
|
|
|
|
* Auto Updater
|
|
|
|
*
|
|
|
|
* Uncomment the following code below and install `electron-updater` to
|
|
|
|
* support auto updating. Code Signing with a valid certificate is required.
|
|
|
|
* https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-electron-builder.html#auto-updating
|
|
|
|
*/
|
|
|
|
|
|
|
|
// import { autoUpdater } from 'electron-updater'
|
|
|
|
|
|
|
|
// autoUpdater.on('update-downloaded', () => {
|
|
|
|
// autoUpdater.quitAndInstall()
|
|
|
|
// })
|
|
|
|
|
|
|
|
// app.on('ready', () => {
|
|
|
|
// if (process.env.NODE_ENV === 'production') {
|
|
|
|
// autoUpdater.checkForUpdates()
|
|
|
|
// }
|
|
|
|
// })
|