PicList/src/background.ts

721 lines
18 KiB
TypeScript
Raw Normal View History

2017-11-27 19:21:12 -05:00
'use strict'
import {
app,
BrowserWindow,
Tray,
Menu,
Notification,
clipboard,
ipcMain,
globalShortcut,
dialog,
2019-12-19 06:17:21 -05:00
systemPreferences,
WebContents,
IpcMainEvent,
protocol
} from 'electron'
2019-12-19 06:17:21 -05:00
import {
createProtocol,
installVueDevtools
} from 'vue-cli-plugin-electron-builder/lib'
import db from '#/datastore'
import picgo from '~/main/utils/picgo'
import uploader from '~/main/utils/uploader'
2019-12-19 06:17:21 -05:00
import beforeOpen from '~/main/utils/beforeOpen'
import pasteTemplate from '#/utils/pasteTemplate'
import updateChecker from '~/main/utils/updateChecker'
import { getPicBeds } from '~/main/utils/getPicBeds'
import pkg from 'root/package.json'
import picgoCoreIPC from '~/main/utils/picgoCoreIPC'
2019-01-12 06:19:26 -05:00
import fixPath from 'fix-path'
2019-12-19 06:17:21 -05:00
import { getUploadFiles } from '~/main/utils/handleArgv'
import bus from '~/main/utils/eventBus'
2019-09-10 02:38:08 -04:00
import {
updateShortKeyFromVersion212
2019-12-19 06:17:21 -05:00
} from '~/main/migrate/shortKeyUpdateHelper'
import shortKeyHandler from '~/main/utils/shortKeyHandler'
import logger from '~/main/utils/logger'
2019-12-19 06:17:21 -05:00
const isDevelopment = process.env.NODE_ENV !== 'production'
protocol.registerSchemesAsPrivileged([{ scheme: 'picgo', privileges: { secure: true, standard: true } }])
2019-12-19 06:17:21 -05:00
if (process.platform === 'darwin') {
beforeOpen()
}
2017-11-27 19:21:12 -05:00
2019-12-19 06:17:21 -05:00
let window: BrowserWindow | null
let settingWindow: BrowserWindow | null
let miniWindow: BrowserWindow | null
let tray: Tray | null
let menu: Menu | null
let contextMenu: Menu | null
const winURL = isDevelopment
? (process.env.WEBPACK_DEV_SERVER_URL as string)
: `picgo://./index.html`
const settingWinURL = isDevelopment
? `${(process.env.WEBPACK_DEV_SERVER_URL as string)}#setting/upload`
: `picgo://./index.html#setting/upload`
const miniWinURL = isDevelopment
? `${(process.env.WEBPACK_DEV_SERVER_URL as string)}#mini-page`
: `picgo://./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()
function createContextMenu () {
const picBeds = getPicBeds()
2018-12-23 10:15:00 -05:00
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 () {
picgo.saveConfig({
'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([
{
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()
2019-12-19 06:17:21 -05:00
settingWindow!.show()
2017-11-27 19:21:12 -05:00
} else {
settingWindow.show()
settingWindow.focus()
}
if (miniWindow) {
miniWindow.hide()
}
2017-11-27 19:21:12 -05:00
}
2017-11-28 10:56:15 -05:00
},
{
label: '选择默认图床',
type: 'submenu',
2019-12-19 06:17:21 -05:00
// @ts-ignore
2018-06-05 08:29:16 -04:00
submenu
2017-12-11 08:52:14 -05:00
},
2019-12-19 06:17:21 -05:00
// @ts-ignore
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
}
},
{
label: '重启应用',
click () {
app.relaunch()
app.exit(0)
}
},
2019-12-19 06:17:21 -05:00
// @ts-ignore
2017-12-11 08:52:14 -05:00
{
role: 'quit',
label: '退出'
2017-11-27 19:21:12 -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', () => {
if (window) {
window.hide()
}
createContextMenu()
2019-12-19 06:17:21 -05:00
tray!.popUpContextMenu(contextMenu!)
2017-11-27 19:21:12 -05:00
})
tray.on('click', (event, bounds) => {
2018-01-10 03:51:09 -05:00
if (process.platform === 'darwin') {
let img = clipboard.readImage()
2019-12-19 06:17:21 -05:00
let obj: ImgInfo[] = []
2018-01-10 03:51:09 -05:00
if (!img.isEmpty()) {
// 从剪贴板来的图片默认转为png
2019-12-19 06:17:21 -05:00
// @ts-ignore
2018-01-10 03:51:09 -05:00
const imgUrl = 'data:image/png;base64,' + Buffer.from(img.toPNG(), 'binary').toString('base64')
obj.push({
width: img.getSize().width,
height: img.getSize().height,
imgUrl
})
}
toggleWindow(bounds)
2018-01-10 03:51:09 -05:00
setTimeout(() => {
2019-12-19 06:17:21 -05:00
window!.webContents.send('clipboardFiles', obj)
2018-01-10 03:51:09 -05:00
}, 0)
} else {
if (window) {
window.hide()
}
2018-01-10 03:51:09 -05:00
if (settingWindow === null) {
createSettingWindow()
2019-12-19 06:17:21 -05:00
settingWindow!.show()
2018-01-10 03:51:09 -05:00
} else {
settingWindow.show()
settingWindow.focus()
}
if (miniWindow) {
miniWindow.hide()
}
2017-11-27 19:21:12 -05:00
}
})
tray.on('drag-enter', () => {
if (systemPreferences.isDarkMode()) {
2019-12-19 06:17:21 -05:00
tray!.setImage(`${__static}/upload-dark.png`)
} else {
2019-12-19 06:17:21 -05:00
tray!.setImage(`${__static}/upload.png`)
}
2017-11-27 19:21:12 -05:00
})
tray.on('drag-end', () => {
2019-12-19 06:17:21 -05:00
tray!.setImage(`${__static}/menubar.png`)
2017-11-27 19:21:12 -05:00
})
2019-12-19 06:17:21 -05:00
tray.on('drop-files', async (event: Event, files: string[]) => {
2019-09-11 07:30:08 -04:00
const pasteStyle = db.get('settings.pasteStyle') || 'markdown'
const imgs = await uploader.setWebContents(window!.webContents).upload(files)
2017-12-22 09:30:16 -05:00
if (imgs !== false) {
2019-12-19 06:17:21 -05:00
for (let i = 0; i < imgs.length; i++) {
clipboard.writeText(pasteTemplate(pasteStyle, imgs[i]))
2017-12-22 09:30:16 -05:00
const notification = new Notification({
title: '上传成功',
2019-12-19 06:17:21 -05:00
body: imgs[i].imgUrl!,
2017-12-22 09:30:16 -05:00
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
}
2019-12-19 06:17:21 -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 = () => {
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: {
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', () => {
2019-12-19 06:17:21 -05:00
window!.hide()
2017-11-27 19:21:12 -05: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
}
let obj: IBrowserWindowOptions = {
2018-07-05 12:43:53 -04:00
height: 64,
2018-07-06 11:54:36 -04:00
width: 64,
show: process.platform === 'linux',
2018-07-05 12:43:53 -04:00
frame: false,
fullscreenable: false,
skipTaskbar: true,
2018-07-05 12:43:53 -04:00
resizable: false,
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: {
backgroundThrottling: false,
nodeIntegration: true,
nodeIntegrationInWorker: true
2018-07-05 12:43:53 -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
}
miniWindow = new BrowserWindow(obj)
2018-07-05 12:43:53 -04:00
miniWindow.loadURL(miniWinURL)
miniWindow.on('closed', () => {
miniWindow = null
})
return miniWindow
2018-07-05 12:43:53 -04:00
}
2017-11-27 19:21:12 -05:00
const createSettingWindow = () => {
const options: IBrowserWindowOptions = {
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: {
backgroundThrottling: false,
nodeIntegration: true,
nodeIntegrationInWorker: true,
webSecurity: false
2017-11-27 19:21:12 -05:00
}
2018-01-10 03:51:09 -05:00
}
if (process.platform !== 'darwin') {
options.show = false
2018-01-10 03:51:09 -05:00
options.frame = false
options.backgroundColor = '#3f3c37'
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
2019-12-19 06:17:21 -05:00
settingWindow!.loadURL(settingWinURL)
2017-11-27 19:21:12 -05:00
2019-12-19 06:17:21 -05:00
settingWindow!.on('closed', () => {
bus.emit('toggleShortKeyModifiedMode', false)
2017-11-27 19:21:12 -05:00
settingWindow = null
2018-07-10 22:04:42 -04:00
if (process.platform === 'linux') {
process.nextTick(() => {
app.quit()
})
2018-07-10 22:04:42 -04:00
}
2017-11-27 19:21:12 -05:00
})
createMenu()
2018-07-05 12:43:53 -04:00
createMiniWidow()
return settingWindow
2017-11-27 19:21:12 -05:00
}
2017-12-15 04:37:38 -05:00
const createMenu = () => {
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
}
]
}]
2019-12-19 06:17:21 -05:00
// @ts-ignore
menu = Menu.buildFromTemplate(template)
Menu.setApplicationMenu(menu)
}
2017-12-15 04:37:38 -05:00
}
const toggleWindow = (bounds: IBounds) => {
2019-12-19 06:17:21 -05:00
if (window!.isVisible()) {
window!.hide()
2017-11-27 19:21:12 -05:00
} else {
showWindow(bounds)
2017-11-27 19:21:12 -05:00
}
}
const showWindow = (bounds: IBounds) => {
2019-12-19 06:17:21 -05:00
window!.setPosition(bounds.x - 98 + 11, bounds.y, false)
window!.webContents.send('updateFiles')
window!.show()
window!.focus()
2017-11-27 19:21:12 -05:00
}
const uploadClipboardFiles = async () => {
let win
2019-12-19 06:17:21 -05:00
if (miniWindow!.isVisible()) {
win = miniWindow
} else {
win = settingWindow || window || createSettingWindow()
}
let img = await uploader.setWebContents(win!.webContents).upload()
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'
clipboard.writeText(pasteTemplate(pasteStyle, img[0]))
2018-01-30 02:20:19 -05:00
const notification = new Notification({
title: '上传成功',
2019-12-19 06:17:21 -05:00
body: img[0].imgUrl!,
2018-01-30 02:20:19 -05:00
icon: img[0].imgUrl
})
notification.show()
2019-09-11 07:30:08 -04:00
db.insert('uploaded', img[0])
2019-12-19 06:17:21 -05:00
window!.webContents.send('clipboardFiles', [])
window!.webContents.send('uploadFiles', img)
if (settingWindow) {
settingWindow.webContents.send('updateGallery')
}
2018-01-30 02:20:19 -05:00
} else {
const notification = new Notification({
title: '上传不成功',
body: '你剪贴板最新的一条记录不是图片哦'
})
notification.show()
}
}
}
const uploadChoosedFiles = async (webContents: WebContents, files: IFileWithPath[]) => {
const input = files.map(item => item.path)
const imgs = await uploader.setWebContents(webContents).upload(input)
if (imgs !== false) {
2019-09-11 07:30:08 -04:00
const pasteStyle = db.get('settings.pasteStyle') || 'markdown'
let pasteText = ''
2019-12-19 06:17:21 -05:00
for (let i = 0; i < imgs.length; i++) {
pasteText += pasteTemplate(pasteStyle, imgs[i]) + '\r\n'
const notification = new Notification({
title: '上传成功',
2019-12-19 06:17:21 -05:00
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])
}
clipboard.writeText(pasteText)
2019-12-19 06:17:21 -05:00
window!.webContents.send('uploadFiles', imgs)
if (settingWindow) {
settingWindow.webContents.send('updateGallery')
}
}
}
picgoCoreIPC()
2018-12-27 22:10:28 -05:00
// from macOS tray
2019-12-19 06:17:21 -05:00
ipcMain.on('uploadClipboardFiles', async () => {
const img = await uploader.setWebContents(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'
clipboard.writeText(pasteTemplate(pasteStyle, img[0]))
2017-12-22 09:30:16 -05:00
const notification = new Notification({
title: '上传成功',
2019-12-19 06:17:21 -05:00
body: img[0].imgUrl!,
// 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])
2019-12-19 06:17:21 -05:00
window!.webContents.send('clipboardFiles', [])
if (settingWindow) {
settingWindow.webContents.send('updateGallery')
}
2017-12-22 09:30:16 -05:00
}
2019-12-19 06:17:21 -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()
})
ipcMain.on('uploadChoosedFiles', async (evt: IpcMainEvent, files: IFileWithPath[]) => {
return uploadChoosedFiles(evt.sender, files)
2017-11-27 19:21:12 -05:00
})
ipcMain.on('updateShortKey', (evt: IpcMainEvent, item: IShortKeyConfig, oldKey: string, from: string) => {
const result = shortKeyHandler.updateShortKey(item, oldKey, from)
evt.sender.send('updateShortKeyResponse', result)
if (result) {
const notification = new Notification({
title: '操作成功',
body: '你的快捷键已经修改成功'
})
notification.show()
} else {
const notification = new Notification({
title: '操作失败',
body: '快捷键冲突,请重新设置'
})
notification.show()
}
})
ipcMain.on('bindOrUnbindShortKey', (evt: IpcMainEvent, item: IShortKeyConfig, from: string) => {
const result = shortKeyHandler.bindOrUnbindShortKey(item, from)
if (result) {
const notification = new Notification({
title: '操作成功',
body: '你的快捷键已经修改成功'
})
notification.show()
} else {
const notification = new Notification({
title: '操作失败',
body: '快捷键冲突,请重新设置'
})
notification.show()
}
2018-01-30 02:20:19 -05:00
})
2019-12-19 06:17:21 -05:00
ipcMain.on('updateCustomLink', () => {
const notification = new Notification({
title: '操作成功',
body: '你的自定义链接格式已经修改成功'
})
notification.show()
})
2019-12-19 06:17:21 -05:00
ipcMain.on('autoStart', (evt: IpcMainEvent, val: boolean) => {
2018-05-02 07:34:24 -04:00
app.setLoginItemSettings({
openAtLogin: val
})
})
2019-12-19 06:17:21 -05:00
ipcMain.on('openSettingWindow', () => {
2018-07-06 11:54:36 -04:00
if (!settingWindow) {
createSettingWindow()
} else {
settingWindow.show()
}
2019-12-19 06:17:21 -05:00
if (miniWindow) {
miniWindow.hide()
}
2018-07-06 11:54:36 -04:00
})
2019-12-19 06:17:21 -05:00
ipcMain.on('openMiniWindow', () => {
2018-07-06 11:54:36 -04:00
if (!miniWindow) {
createMiniWidow()
}
2019-12-19 06:17:21 -05:00
miniWindow!.show()
miniWindow!.focus()
settingWindow!.hide()
2018-07-06 11:54:36 -04:00
})
2018-07-10 10:37:29 -04:00
// from mini window
2019-12-19 06:17:21 -05:00
ipcMain.on('syncPicBed', () => {
2018-07-10 10:37:29 -04:00
if (settingWindow) {
settingWindow.webContents.send('syncPicBed')
}
})
2019-12-19 06:17:21 -05:00
ipcMain.on('getPicBeds', (evt: IpcMainEvent) => {
const picBeds = getPicBeds()
2018-12-23 10:15:00 -05:00
evt.sender.send('getPicBeds', picBeds)
evt.returnValue = picBeds
2018-12-23 10:15:00 -05:00
})
2019-12-19 06:17:21 -05:00
ipcMain.on('toggleShortKeyModifiedMode', (evt: IpcMainEvent, val: boolean) => {
bus.emit('toggleShortKeyModifiedMode', val)
})
// const shortKeyHash = {
// upload: uploadClipboardFiles
// }
2018-01-30 02:20:19 -05:00
const gotTheLock = app.requestSingleInstanceLock()
if (!gotTheLock) {
app.quit()
} else {
app.on('second-instance', (event, commandLine, workingDirectory) => {
let files = getUploadFiles(commandLine, workingDirectory)
if (files === null || files.length > 0) { // 如果有文件列表作为参数,说明是命令行启动
if (files === null) {
uploadClipboardFiles()
} else {
let win
if (miniWindow && miniWindow.isVisible()) {
win = miniWindow
} else {
win = settingWindow || window || createSettingWindow()
}
uploadChoosedFiles(win.webContents, files)
}
} else {
if (settingWindow) {
if (settingWindow.isMinimized()) {
settingWindow.restore()
}
settingWindow.focus()
}
}
})
}
2018-01-10 03:51:09 -05:00
if (process.platform === 'win32') {
2019-12-19 06:17:21 -05:00
app.setAppUserModelId('com.molunerfinn.picgo')
2018-01-10 03:51:09 -05:00
}
if (process.env.XDG_CURRENT_DESKTOP && process.env.XDG_CURRENT_DESKTOP.includes('Unity')) {
process.env.XDG_CURRENT_DESKTOP = 'Unity'
}
2019-12-19 06:17:21 -05:00
app.on('ready', async () => {
createProtocol('picgo')
2019-12-19 06:17:21 -05:00
if (isDevelopment && !process.env.IS_TEST) {
// Install Vue Devtools
try {
await installVueDevtools()
} catch (e) {
console.error('Vue Devtools failed to install:', e.toString())
}
}
2017-11-27 19:21:12 -05:00
createWindow()
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'))
shortKeyHandler.init()
})
2019-09-10 02:38:08 -04:00
if (process.env.NODE_ENV !== 'development') {
let files = getUploadFiles()
if (files === null) {
logger.info('get clipboardFile, null')
} else {
logger.info(`get clipboardFile, ${files.toString()}`)
}
if (files === null || files.length > 0) { // 如果有文件列表作为参数,说明是命令行启动
if (files === null) {
uploadClipboardFiles()
} else {
let win
if (miniWindow && miniWindow.isVisible()) {
win = miniWindow
} else {
win = settingWindow || window || createSettingWindow()
}
uploadChoosedFiles(win.webContents, files)
}
}
}
2017-11-27 19:21:12 -05:00
})
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', () => {
2019-12-19 06:17:21 -05:00
createProtocol('picgo')
if (window === null) {
2017-11-27 19:21:12 -05:00
createWindow()
}
if (settingWindow === null) {
createSettingWindow()
}
2017-11-27 19:21:12 -05:00
})
app.on('will-quit', () => {
globalShortcut.unregisterAll()
2019-09-10 02:38:08 -04:00
bus.removeAllListeners()
})
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 () {
2019-12-19 06:17:21 -05:00
const eventList: any = {
'picgo:upload': uploadClipboardFiles,
'createSettingWindow': shortKeyRequestSettingWindow,
hideMiniWindow
2019-09-10 02:38:08 -04:00
}
for (let i in eventList) {
bus.on(i, eventList[i])
}
}
function shortKeyRequestSettingWindow (command: string) {
if (!settingWindow) createSettingWindow()
bus.emit('createSettingWindowDone', command, settingWindow!.id)
}
function hideMiniWindow () {
if (miniWindow && miniWindow.isVisible()) {
miniWindow.hide()
}
}
2019-12-19 06:17:21 -05:00
// Exit cleanly on request from parent process in development mode.
if (isDevelopment) {
if (process.platform === 'win32') {
process.on('message', data => {
if (data === 'graceful-exit') {
app.quit()
}
})
} else {
process.on('SIGTERM', () => {
app.quit()
})
}
}
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()
// }
// })