2019-05-22 12:13:12 -04:00
|
|
|
import {
|
|
|
|
app,
|
|
|
|
globalShortcut,
|
2019-12-19 06:17:21 -05:00
|
|
|
protocol
|
2019-05-22 12:13:12 -04:00
|
|
|
} from 'electron'
|
2019-12-19 06:17:21 -05:00
|
|
|
import {
|
|
|
|
createProtocol,
|
|
|
|
installVueDevtools
|
|
|
|
} from 'vue-cli-plugin-electron-builder/lib'
|
|
|
|
import db from '#/datastore'
|
2020-04-10 11:28:46 -04:00
|
|
|
import { IWindowList } from 'apis/app/window/constants'
|
|
|
|
import windowManager from 'apis/app/window/windowManager'
|
2020-01-10 09:34:08 -05:00
|
|
|
import {
|
|
|
|
uploadChoosedFiles,
|
|
|
|
uploadClipboardFiles
|
2020-04-10 11:28:46 -04:00
|
|
|
} from 'apis/app/uploader/apis'
|
2019-12-19 06:17:21 -05:00
|
|
|
import beforeOpen from '~/main/utils/beforeOpen'
|
|
|
|
import updateChecker from '~/main/utils/updateChecker'
|
2020-04-10 11:28:46 -04:00
|
|
|
import ipcList from '~/main/events/ipcList'
|
|
|
|
import busEventList from '~/main/events/busEventList'
|
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'
|
2020-04-10 11:28:46 -04:00
|
|
|
import bus from '@core/bus'
|
2019-09-10 02:38:08 -04:00
|
|
|
import {
|
|
|
|
updateShortKeyFromVersion212
|
2020-01-08 06:26:25 -05:00
|
|
|
} from '~/main/migrate'
|
2020-04-10 11:28:46 -04:00
|
|
|
import shortKeyHandler from 'apis/app/shortKey/shortKeyHandler'
|
2019-12-31 10:50:19 -05:00
|
|
|
import server from '~/main/server/index'
|
2020-01-10 09:34:08 -05:00
|
|
|
import {
|
|
|
|
createTray
|
2020-04-10 11:28:46 -04:00
|
|
|
} from 'apis/app/system'
|
2019-12-20 05:46:39 -05:00
|
|
|
|
2019-12-19 06:17:21 -05:00
|
|
|
const isDevelopment = process.env.NODE_ENV !== 'production'
|
2019-12-20 05:46:39 -05:00
|
|
|
protocol.registerSchemesAsPrivileged([{ scheme: 'picgo', privileges: { secure: true, standard: true } }])
|
2019-12-19 06:17:21 -05:00
|
|
|
|
2019-12-28 02:19:27 -05:00
|
|
|
beforeOpen()
|
2017-11-27 19:21:12 -05:00
|
|
|
|
2019-01-12 06:19:26 -05:00
|
|
|
// fix the $PATH in macOS
|
|
|
|
fixPath()
|
|
|
|
|
2020-01-10 09:34:08 -05:00
|
|
|
ipcList.listen()
|
|
|
|
busEventList.listen()
|
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 {
|
2020-01-07 07:49:27 -05:00
|
|
|
const win = windowManager.getAvailableWindow()
|
2019-04-14 22:28:11 -04:00
|
|
|
uploadChoosedFiles(win.webContents, files)
|
2019-04-14 03:41:48 -04:00
|
|
|
}
|
|
|
|
} else {
|
2020-01-07 07:49:27 -05:00
|
|
|
if (windowManager.has(IWindowList.SETTING_WINDOW)) {
|
|
|
|
const settingWindow = windowManager.get(IWindowList.SETTING_WINDOW)!
|
2019-04-14 03:41:48 -04:00
|
|
|
if (settingWindow.isMinimized()) {
|
|
|
|
settingWindow.restore()
|
|
|
|
}
|
|
|
|
settingWindow.focus()
|
|
|
|
}
|
2018-01-09 22:31:07 -05:00
|
|
|
}
|
2019-04-14 03:41:48 -04:00
|
|
|
})
|
2020-04-10 23:05:58 -04:00
|
|
|
if (process.platform === 'win32') {
|
|
|
|
app.setAppUserModelId('com.molunerfinn.picgo')
|
|
|
|
}
|
2018-01-10 03:51:09 -05:00
|
|
|
|
2020-04-10 23:05:58 -04:00
|
|
|
if (process.env.XDG_CURRENT_DESKTOP && process.env.XDG_CURRENT_DESKTOP.includes('Unity')) {
|
|
|
|
process.env.XDG_CURRENT_DESKTOP = 'Unity'
|
|
|
|
}
|
2018-06-26 05:03:46 -04:00
|
|
|
|
2020-04-10 23:05:58 -04:00
|
|
|
app.on('ready', async () => {
|
|
|
|
createProtocol('picgo')
|
|
|
|
if (isDevelopment && !process.env.IS_TEST) {
|
2019-12-19 06:17:21 -05:00
|
|
|
// Install Vue Devtools
|
2020-04-10 23:05:58 -04:00
|
|
|
try {
|
|
|
|
await installVueDevtools()
|
|
|
|
} catch (e) {
|
|
|
|
console.error('Vue Devtools failed to install:', e.toString())
|
|
|
|
}
|
2019-12-19 06:17:21 -05:00
|
|
|
}
|
2020-04-10 23:05:58 -04:00
|
|
|
windowManager.create(IWindowList.TRAY_WINDOW)
|
|
|
|
windowManager.create(IWindowList.SETTING_WINDOW)
|
|
|
|
if (process.platform === 'darwin' || process.platform === 'win32') {
|
|
|
|
createTray()
|
|
|
|
}
|
|
|
|
db.set('needReload', false)
|
|
|
|
updateChecker()
|
|
|
|
// 不需要阻塞
|
|
|
|
process.nextTick(() => {
|
|
|
|
updateShortKeyFromVersion212(db, db.get('settings.shortKey'))
|
|
|
|
shortKeyHandler.init()
|
|
|
|
})
|
|
|
|
server.startup()
|
|
|
|
if (process.env.NODE_ENV !== 'development') {
|
|
|
|
let files = getUploadFiles()
|
|
|
|
if (files === null || files.length > 0) { // 如果有文件列表作为参数,说明是命令行启动
|
|
|
|
if (files === null) {
|
|
|
|
uploadClipboardFiles()
|
|
|
|
} else {
|
|
|
|
const win = windowManager.getAvailableWindow()
|
|
|
|
uploadChoosedFiles(win.webContents, files)
|
|
|
|
}
|
2019-04-14 10:07:33 -04:00
|
|
|
}
|
2019-04-14 03:41:48 -04:00
|
|
|
}
|
2020-04-10 23:05:58 -04:00
|
|
|
})
|
2017-11-27 19:21:12 -05:00
|
|
|
|
2020-04-10 23:05:58 -04:00
|
|
|
app.on('window-all-closed', () => {
|
|
|
|
if (process.platform !== 'darwin') {
|
|
|
|
app.quit()
|
|
|
|
}
|
|
|
|
})
|
2017-11-27 19:21:12 -05:00
|
|
|
|
2020-04-10 23:05:58 -04:00
|
|
|
app.on('activate', () => {
|
|
|
|
createProtocol('picgo')
|
|
|
|
if (!windowManager.has(IWindowList.TRAY_WINDOW)) {
|
|
|
|
windowManager.create(IWindowList.TRAY_WINDOW)
|
|
|
|
}
|
|
|
|
if (!windowManager.has(IWindowList.SETTING_WINDOW)) {
|
|
|
|
windowManager.create(IWindowList.SETTING_WINDOW)
|
|
|
|
}
|
|
|
|
})
|
2017-11-27 19:21:12 -05:00
|
|
|
|
2020-04-10 23:05:58 -04:00
|
|
|
app.on('will-quit', () => {
|
|
|
|
globalShortcut.unregisterAll()
|
|
|
|
bus.removeAllListeners()
|
|
|
|
server.shutdown()
|
|
|
|
})
|
2017-12-23 06:46:20 -05:00
|
|
|
|
2020-04-10 23:05:58 -04:00
|
|
|
app.setLoginItemSettings({
|
|
|
|
openAtLogin: db.get('settings.autoStart') || false
|
|
|
|
})
|
|
|
|
}
|
2018-05-02 05:17:55 -04:00
|
|
|
|
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()
|
2019-12-31 10:50:19 -05:00
|
|
|
server.shutdown()
|
2019-12-19 06:17:21 -05:00
|
|
|
}
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
process.on('SIGTERM', () => {
|
|
|
|
app.quit()
|
2019-12-31 10:50:19 -05:00
|
|
|
server.shutdown()
|
2019-12-19 06:17:21 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
// }
|
|
|
|
// })
|