Compare commits

..
4 Commits
Author SHA1 Message Date
PiEgg 9274b3f8be 📦 Chore(fuck): electron-builder publish option 2020-01-01 19:38:31 +08:00
PiEgg 7809b626d3 🐛 Fix: cI build error in linux 2020-01-01 19:29:37 +08:00
PiEgg a7995c037c 📦 Chore: fix CI script 2020-01-01 19:01:47 +08:00
PiEgg 85f4c67e0b 🎉 Release: v2.2.0 2020-01-01 18:18:51 +08:00
26 changed files with 305 additions and 503 deletions
-43
View File
@@ -1,46 +1,3 @@
## :tada: 2.2.1 (2020-01-09)
### :sparkles: Features
* add alias for plugin config name ([5a06483](https://github.com/Molunerfinn/PicGo/commit/5a06483))
* add aliyun oss options ([a33f1ad](https://github.com/Molunerfinn/PicGo/commit/a33f1ad)), closes [#347](https://github.com/Molunerfinn/PicGo/issues/347)
* **server:** add http server for uploading images by a http request ([c56d4ef](https://github.com/Molunerfinn/PicGo/commit/c56d4ef))
* add server config settings ([6b57cf7](https://github.com/Molunerfinn/PicGo/commit/6b57cf7))
* only shows visible pic-beds ([9d4d605](https://github.com/Molunerfinn/PicGo/commit/9d4d605)), closes [#310](https://github.com/Molunerfinn/PicGo/issues/310)
### :bug: Bug Fixes
* decrease title-bar z-index when config-form dialog shows ([f2750e1](https://github.com/Molunerfinn/PicGo/commit/f2750e1))
* **website:** website pictures error ([a5b6526](https://github.com/Molunerfinn/PicGo/commit/a5b6526))
* add new tray icon for macOS dark-mode ([c5adf3b](https://github.com/Molunerfinn/PicGo/commit/c5adf3b)), closes [#267](https://github.com/Molunerfinn/PicGo/issues/267)
* beforeOpen handler in windows ([cd30a6c](https://github.com/Molunerfinn/PicGo/commit/cd30a6c))
* busApi event register first && emit later ([e1a0cbb](https://github.com/Molunerfinn/PicGo/commit/e1a0cbb))
* enum type error ([4e3fa28](https://github.com/Molunerfinn/PicGo/commit/4e3fa28))
* handle empty request-body ([81e6acb](https://github.com/Molunerfinn/PicGo/commit/81e6acb))
* launch error in new structrue ([bc8e641](https://github.com/Molunerfinn/PicGo/commit/bc8e641))
* miniWindow minimize bug ([5f2b7c7](https://github.com/Molunerfinn/PicGo/commit/5f2b7c7))
* plugin config-form && default plugin logo ([514fc40](https://github.com/Molunerfinn/PicGo/commit/514fc40))
* release script ([b4f10c6](https://github.com/Molunerfinn/PicGo/commit/b4f10c6))
* removeById handler error ([c4f0a30](https://github.com/Molunerfinn/PicGo/commit/c4f0a30)), closes [#382](https://github.com/Molunerfinn/PicGo/issues/382)
* rename page not work ([29a55ed](https://github.com/Molunerfinn/PicGo/commit/29a55ed))
* save debug mode && PICGO_ENV into config file ([c6ead5b](https://github.com/Molunerfinn/PicGo/commit/c6ead5b))
* server may never start ([73870a5](https://github.com/Molunerfinn/PicGo/commit/73870a5))
* settingPage && miniPage style in windows ([3fd9572](https://github.com/Molunerfinn/PicGo/commit/3fd9572))
### :pencil: Documentation
* add note for windows electron mirror ([46a49ed](https://github.com/Molunerfinn/PicGo/commit/46a49ed))
* remove weibo picbed ([e81b8f4](https://github.com/Molunerfinn/PicGo/commit/e81b8f4))
* update installation by scoop ([91b397d](https://github.com/Molunerfinn/PicGo/commit/91b397d)), closes [#295](https://github.com/Molunerfinn/PicGo/issues/295)
* update readme ([1b3522e](https://github.com/Molunerfinn/PicGo/commit/1b3522e))
* update README ([f491209](https://github.com/Molunerfinn/PicGo/commit/f491209))
* update site ([fe9e19a](https://github.com/Molunerfinn/PicGo/commit/fe9e19a))
# :tada: 2.2.0 (2020-01-01) # :tada: 2.2.0 (2020-01-01)
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "picgo", "name": "picgo",
"version": "2.2.1", "version": "2.2.0",
"private": true, "private": true,
"scripts": { "scripts": {
"serve": "vue-cli-service serve", "serve": "vue-cli-service serve",
+211 -80
View File
@@ -20,12 +20,12 @@ import {
installVueDevtools installVueDevtools
} from 'vue-cli-plugin-electron-builder/lib' } from 'vue-cli-plugin-electron-builder/lib'
import db from '#/datastore' import db from '#/datastore'
import picgo from '~/main/apis/picgo' import picgo from '~/main/utils/picgo'
import uploader from '~/main/apis/uploader' import uploader from '~/main/utils/uploader'
import beforeOpen from '~/main/utils/beforeOpen' import beforeOpen from '~/main/utils/beforeOpen'
import pasteTemplate from '#/utils/pasteTemplate' import pasteTemplate from '#/utils/pasteTemplate'
import updateChecker from '~/main/utils/updateChecker' import updateChecker from '~/main/utils/updateChecker'
import getPicBeds from '~/main/utils/getPicBeds' import { getPicBeds } from '~/main/utils/getPicBeds'
import pkg from 'root/package.json' import pkg from 'root/package.json'
import picgoCoreIPC from '~/main/utils/picgoCoreIPC' import picgoCoreIPC from '~/main/utils/picgoCoreIPC'
import fixPath from 'fix-path' import fixPath from 'fix-path'
@@ -33,8 +33,8 @@ import { getUploadFiles } from '~/main/utils/handleArgv'
import bus from '~/main/utils/eventBus' import bus from '~/main/utils/eventBus'
import { import {
updateShortKeyFromVersion212 updateShortKeyFromVersion212
} from '~/main/migrate' } from '~/main/migrate/shortKeyUpdateHelper'
import shortKeyHandler from '~/main/apis/shortKey/shortKeyHandler' import shortKeyHandler from '~/main/utils/shortKeyHandler'
import logger from '~/main/utils/logger' import logger from '~/main/utils/logger'
import { import {
UPLOAD_WITH_FILES, UPLOAD_WITH_FILES,
@@ -44,18 +44,18 @@ import {
GET_WINDOW_ID, GET_WINDOW_ID,
GET_WINDOW_ID_REPONSE, GET_WINDOW_ID_REPONSE,
GET_SETTING_WINDOW_ID, GET_SETTING_WINDOW_ID,
GET_SETTING_WINDOW_ID_RESPONSE, GET_SETTING_WINDOW_ID_RESPONSE
CREATE_APP_MENU } from '~/main/utils/busApi/constants'
} from '~/main/apis/bus/constants'
import server from '~/main/server/index' import server from '~/main/server/index'
import { IWindowList } from '~/main/apis/window/constants'
import windowManager from '~/main/apis/window/windowManager'
const isDevelopment = process.env.NODE_ENV !== 'production' const isDevelopment = process.env.NODE_ENV !== 'production'
protocol.registerSchemesAsPrivileged([{ scheme: 'picgo', privileges: { secure: true, standard: true } }]) protocol.registerSchemesAsPrivileged([{ scheme: 'picgo', privileges: { secure: true, standard: true } }])
beforeOpen() beforeOpen()
let window: BrowserWindow | null
let settingWindow: BrowserWindow | null
let miniWindow: BrowserWindow | null
let tray: Tray | null let tray: Tray | null
let menu: Menu | null let menu: Menu | null
let contextMenu: Menu | null let contextMenu: Menu | null
@@ -83,8 +83,8 @@ function createContextMenu () {
picgo.saveConfig({ picgo.saveConfig({
'picBed.current': item.type 'picBed.current': item.type
}) })
if (windowManager.has(IWindowList.SETTING_WINDOW)) { if (settingWindow) {
windowManager.get(IWindowList.SETTING_WINDOW)!.webContents.send('syncPicBed') settingWindow.webContents.send('syncPicBed')
} }
} }
} }
@@ -103,11 +103,15 @@ function createContextMenu () {
{ {
label: '打开详细窗口', label: '打开详细窗口',
click () { click () {
const settingWindow = windowManager.get(IWindowList.SETTING_WINDOW) if (settingWindow === null) {
settingWindow!.show() createSettingWindow()
settingWindow!.focus() settingWindow!.show()
if (windowManager.has(IWindowList.MINI_WINDOW)) { } else {
windowManager.get(IWindowList.MINI_WINDOW)!.hide() settingWindow.show()
settingWindow.focus()
}
if (miniWindow) {
miniWindow.hide()
} }
} }
}, },
@@ -146,8 +150,8 @@ function createTray () {
const menubarPic = process.platform === 'darwin' ? `${__static}/menubar.png` : `${__static}/menubar-nodarwin.png` const menubarPic = process.platform === 'darwin' ? `${__static}/menubar.png` : `${__static}/menubar-nodarwin.png`
tray = new Tray(menubarPic) tray = new Tray(menubarPic)
tray.on('right-click', () => { tray.on('right-click', () => {
if (windowManager.has(IWindowList.TRAY_WINDOW)) { if (window) {
windowManager.get(IWindowList.TRAY_WINDOW)!.hide() window.hide()
} }
createContextMenu() createContextMenu()
tray!.popUpContextMenu(contextMenu!) tray!.popUpContextMenu(contextMenu!)
@@ -168,17 +172,21 @@ function createTray () {
imgUrl imgUrl
}) })
} }
windowManager.get(IWindowList.TRAY_WINDOW)!.webContents.send('clipboardFiles', obj) window!.webContents.send('clipboardFiles', obj)
}, 0) }, 0)
} else { } else {
if (windowManager.has(IWindowList.TRAY_WINDOW)) { if (window) {
windowManager.get(IWindowList.TRAY_WINDOW)!.hide() window.hide()
} }
const settingWindow = windowManager.get(IWindowList.SETTING_WINDOW) if (settingWindow === null) {
settingWindow!.show() createSettingWindow()
settingWindow!.focus() settingWindow!.show()
if (windowManager.has(IWindowList.MINI_WINDOW)) { } else {
windowManager.get(IWindowList.MINI_WINDOW)!.hide() settingWindow.show()
settingWindow.focus()
}
if (miniWindow) {
miniWindow.hide()
} }
} }
}) })
@@ -197,10 +205,7 @@ function createTray () {
tray.on('drop-files', async (event: Event, files: string[]) => { tray.on('drop-files', async (event: Event, files: string[]) => {
const pasteStyle = db.get('settings.pasteStyle') || 'markdown' const pasteStyle = db.get('settings.pasteStyle') || 'markdown'
const trayWindow = windowManager.get(IWindowList.TRAY_WINDOW)! const imgs = await uploader.setWebContents(window!.webContents).upload(files)
const imgs = await uploader
.setWebContents(trayWindow.webContents)
.upload(files)
if (imgs !== false) { if (imgs !== false) {
for (let i = 0; i < imgs.length; i++) { for (let i = 0; i < imgs.length; i++) {
clipboard.writeText(pasteTemplate(pasteStyle, imgs[i])) clipboard.writeText(pasteTemplate(pasteStyle, imgs[i]))
@@ -214,12 +219,124 @@ function createTray () {
}, i * 100) }, i * 100)
db.insert('uploaded', imgs[i]) db.insert('uploaded', imgs[i])
} }
trayWindow.webContents.send('dragFiles', imgs) window!.webContents.send('dragFiles', imgs)
} }
}) })
// toggleWindow() // toggleWindow()
} }
const createWindow = () => {
if (process.platform !== 'darwin' && process.platform !== 'win32') {
return
}
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,
backgroundThrottling: false
}
})
window.loadURL(winURL)
window.on('closed', () => {
window = null
})
window.on('blur', () => {
window!.hide()
})
return window
}
const createMiniWindow = () => {
if (miniWindow || process.platform === 'darwin') {
return false
}
let obj: IBrowserWindowOptions = {
height: 64,
width: 64,
show: process.platform === 'linux',
frame: false,
fullscreenable: false,
skipTaskbar: true,
resizable: false,
transparent: process.platform !== 'linux',
icon: `${__static}/logo.png`,
webPreferences: {
backgroundThrottling: false,
nodeIntegration: true,
nodeIntegrationInWorker: true
}
}
if (db.get('settings.miniWindowOntop')) {
obj.alwaysOnTop = true
}
miniWindow = new BrowserWindow(obj)
miniWindow.loadURL(miniWinURL)
miniWindow.on('closed', () => {
miniWindow = null
})
return miniWindow
}
const createSettingWindow = () => {
const options: IBrowserWindowOptions = {
height: 450,
width: 800,
show: false,
frame: true,
center: true,
fullscreenable: false,
resizable: false,
title: 'PicGo',
vibrancy: 'ultra-dark',
transparent: true,
titleBarStyle: 'hidden',
webPreferences: {
backgroundThrottling: false,
nodeIntegration: true,
nodeIntegrationInWorker: true,
webSecurity: false
}
}
if (process.platform !== 'darwin') {
options.show = false
options.frame = false
options.backgroundColor = '#3f3c37'
options.transparent = false
options.icon = `${__static}/logo.png`
}
settingWindow = new BrowserWindow(options)
settingWindow!.loadURL(settingWinURL)
settingWindow!.on('closed', () => {
bus.emit('toggleShortKeyModifiedMode', false)
settingWindow = null
if (process.platform === 'linux') {
process.nextTick(() => {
app.quit()
})
}
})
createMenu()
createMiniWindow()
return settingWindow
}
const createMenu = () => { const createMenu = () => {
if (process.env.NODE_ENV !== 'development') { if (process.env.NODE_ENV !== 'development') {
const template = [{ const template = [{
@@ -248,23 +365,25 @@ const createMenu = () => {
} }
const toggleWindow = (bounds: IBounds) => { const toggleWindow = (bounds: IBounds) => {
const trayWindow = windowManager.get(IWindowList.TRAY_WINDOW)! if (window!.isVisible()) {
if (trayWindow.isVisible()) { window!.hide()
trayWindow.hide()
} else { } else {
trayWindow.setPosition(bounds.x - 98 + 11, bounds.y, false) showWindow(bounds)
trayWindow.webContents.send('updateFiles')
trayWindow.show()
trayWindow.focus()
} }
} }
const showWindow = (bounds: IBounds) => {
window!.setPosition(bounds.x - 98 + 11, bounds.y, false)
window!.webContents.send('updateFiles')
window!.show()
window!.focus()
}
const uploadClipboardFiles = async (): Promise<string> => { const uploadClipboardFiles = async (): Promise<string> => {
const win = windowManager.getAvailableWindow() const win = getAvailableWindow()
let img = await uploader.setWebContents(win!.webContents).upload() let img = await uploader.setWebContents(win!.webContents).upload()
if (img !== false) { if (img !== false) {
if (img.length > 0) { if (img.length > 0) {
const trayWindow = windowManager.get(IWindowList.TRAY_WINDOW)!
const pasteStyle = db.get('settings.pasteStyle') || 'markdown' const pasteStyle = db.get('settings.pasteStyle') || 'markdown'
clipboard.writeText(pasteTemplate(pasteStyle, img[0])) clipboard.writeText(pasteTemplate(pasteStyle, img[0]))
const notification = new Notification({ const notification = new Notification({
@@ -274,10 +393,10 @@ const uploadClipboardFiles = async (): Promise<string> => {
}) })
notification.show() notification.show()
db.insert('uploaded', img[0]) db.insert('uploaded', img[0])
trayWindow.webContents.send('clipboardFiles', []) window!.webContents.send('clipboardFiles', [])
trayWindow.webContents.send('uploadFiles', img) window!.webContents.send('uploadFiles', img)
if (windowManager.has(IWindowList.SETTING_WINDOW)) { if (settingWindow) {
windowManager.get(IWindowList.SETTING_WINDOW)!.webContents.send('updateGallery') settingWindow.webContents.send('updateGallery')
} }
return img[0].imgUrl as string return img[0].imgUrl as string
} else { } else {
@@ -314,9 +433,9 @@ const uploadChoosedFiles = async (webContents: WebContents, files: IFileWithPath
result.push(imgs[i].imgUrl!) result.push(imgs[i].imgUrl!)
} }
clipboard.writeText(pasteText) clipboard.writeText(pasteText)
windowManager.get(IWindowList.TRAY_WINDOW)!.webContents.send('uploadFiles', imgs) window!.webContents.send('uploadFiles', imgs)
if (windowManager.has(IWindowList.SETTING_WINDOW)) { if (settingWindow) {
windowManager.get(IWindowList.SETTING_WINDOW)!.webContents.send('updateGallery') settingWindow.webContents.send('updateGallery')
} }
return result return result
} else { } else {
@@ -328,8 +447,7 @@ picgoCoreIPC()
// from macOS tray // from macOS tray
ipcMain.on('uploadClipboardFiles', async () => { ipcMain.on('uploadClipboardFiles', async () => {
const trayWindow = windowManager.get(IWindowList.TRAY_WINDOW)! const img = await uploader.setWebContents(window!.webContents).upload()
const img = await uploader.setWebContents(trayWindow.webContents).upload()
if (img !== false) { if (img !== false) {
const pasteStyle = db.get('settings.pasteStyle') || 'markdown' const pasteStyle = db.get('settings.pasteStyle') || 'markdown'
clipboard.writeText(pasteTemplate(pasteStyle, img[0])) clipboard.writeText(pasteTemplate(pasteStyle, img[0]))
@@ -341,12 +459,12 @@ ipcMain.on('uploadClipboardFiles', async () => {
}) })
notification.show() notification.show()
db.insert('uploaded', img[0]) db.insert('uploaded', img[0])
trayWindow.webContents.send('clipboardFiles', []) window!.webContents.send('clipboardFiles', [])
if (windowManager.has(IWindowList.SETTING_WINDOW)) { if (settingWindow) {
windowManager.get(IWindowList.SETTING_WINDOW)!.webContents.send('updateGallery') settingWindow.webContents.send('updateGallery')
} }
} }
trayWindow.webContents.send('uploadFiles') window!.webContents.send('uploadFiles')
}) })
ipcMain.on('uploadClipboardFilesFromUploadPage', () => { ipcMain.on('uploadClipboardFilesFromUploadPage', () => {
@@ -407,24 +525,29 @@ ipcMain.on('autoStart', (evt: IpcMainEvent, val: boolean) => {
}) })
ipcMain.on('openSettingWindow', () => { ipcMain.on('openSettingWindow', () => {
windowManager.get(IWindowList.SETTING_WINDOW)!.show() if (!settingWindow) {
if (windowManager.has(IWindowList.MINI_WINDOW)) { createSettingWindow()
windowManager.get(IWindowList.MINI_WINDOW)!.hide() } else {
settingWindow.show()
}
if (miniWindow) {
miniWindow.hide()
} }
}) })
ipcMain.on('openMiniWindow', () => { ipcMain.on('openMiniWindow', () => {
const miniWindow = windowManager.get(IWindowList.MINI_WINDOW)! if (!miniWindow) {
const settingWindow = windowManager.get(IWindowList.SETTING_WINDOW)! createMiniWindow()
miniWindow.show() }
miniWindow.focus() miniWindow!.show()
settingWindow.hide() miniWindow!.focus()
settingWindow!.hide()
}) })
// from mini window // from mini window
ipcMain.on('syncPicBed', () => { ipcMain.on('syncPicBed', () => {
if (windowManager.has(IWindowList.SETTING_WINDOW)) { if (settingWindow) {
windowManager.get(IWindowList.SETTING_WINDOW)!.webContents.send('syncPicBed') settingWindow.webContents.send('syncPicBed')
} }
}) })
@@ -453,12 +576,11 @@ if (!gotTheLock) {
if (files === null) { if (files === null) {
uploadClipboardFiles() uploadClipboardFiles()
} else { } else {
const win = windowManager.getAvailableWindow() const win = getAvailableWindow()
uploadChoosedFiles(win.webContents, files) uploadChoosedFiles(win.webContents, files)
} }
} else { } else {
if (windowManager.has(IWindowList.SETTING_WINDOW)) { if (settingWindow) {
const settingWindow = windowManager.get(IWindowList.SETTING_WINDOW)!
if (settingWindow.isMinimized()) { if (settingWindow.isMinimized()) {
settingWindow.restore() settingWindow.restore()
} }
@@ -486,8 +608,8 @@ app.on('ready', async () => {
console.error('Vue Devtools failed to install:', e.toString()) console.error('Vue Devtools failed to install:', e.toString())
} }
} }
windowManager.create(IWindowList.TRAY_WINDOW) createWindow()
windowManager.create(IWindowList.SETTING_WINDOW) createSettingWindow()
if (process.platform === 'darwin' || process.platform === 'win32') { if (process.platform === 'darwin' || process.platform === 'win32') {
createTray() createTray()
} }
@@ -506,7 +628,7 @@ app.on('ready', async () => {
if (files === null) { if (files === null) {
uploadClipboardFiles() uploadClipboardFiles()
} else { } else {
const win = windowManager.getAvailableWindow() const win = getAvailableWindow()
uploadChoosedFiles(win.webContents, files) uploadChoosedFiles(win.webContents, files)
} }
} }
@@ -521,11 +643,11 @@ app.on('window-all-closed', () => {
app.on('activate', () => { app.on('activate', () => {
createProtocol('picgo') createProtocol('picgo')
if (!windowManager.has(IWindowList.TRAY_WINDOW)) { if (window === null) {
windowManager.create(IWindowList.TRAY_WINDOW) createWindow()
} }
if (!windowManager.has(IWindowList.SETTING_WINDOW)) { if (settingWindow === null) {
windowManager.create(IWindowList.SETTING_WINDOW) createSettingWindow()
} }
}) })
@@ -545,33 +667,42 @@ function initEventCenter () {
[UPLOAD_WITH_CLIPBOARD_FILES]: busCallUploadClipboardFiles, [UPLOAD_WITH_CLIPBOARD_FILES]: busCallUploadClipboardFiles,
[UPLOAD_WITH_FILES]: busCallUploadFiles, [UPLOAD_WITH_FILES]: busCallUploadFiles,
[GET_WINDOW_ID]: busCallGetWindowId, [GET_WINDOW_ID]: busCallGetWindowId,
[GET_SETTING_WINDOW_ID]: busCallGetSettingWindowId, [GET_SETTING_WINDOW_ID]: busCallGetSettingWindowId
[CREATE_APP_MENU]: createMenu
} }
for (let i in eventList) { for (let i in eventList) {
bus.on(i, eventList[i]) bus.on(i, eventList[i])
} }
} }
function getAvailableWindow () {
let win
if (miniWindow && miniWindow.isVisible()) {
win = miniWindow
} else {
win = settingWindow || window || createSettingWindow()
}
return win
}
async function busCallUploadClipboardFiles () { async function busCallUploadClipboardFiles () {
const imgUrl = await uploadClipboardFiles() const imgUrl = await uploadClipboardFiles()
bus.emit(UPLOAD_WITH_CLIPBOARD_FILES_RESPONSE, imgUrl) bus.emit(UPLOAD_WITH_CLIPBOARD_FILES_RESPONSE, imgUrl)
} }
async function busCallUploadFiles (pathList: IFileWithPath[]) { async function busCallUploadFiles (pathList: IFileWithPath[]) {
const win = windowManager.getAvailableWindow() const win = getAvailableWindow()
const urls = await uploadChoosedFiles(win.webContents, pathList) const urls = await uploadChoosedFiles(win.webContents, pathList)
bus.emit(UPLOAD_WITH_FILES_RESPONSE, urls) bus.emit(UPLOAD_WITH_FILES_RESPONSE, urls)
} }
function busCallGetWindowId () { function busCallGetWindowId () {
const win = windowManager.getAvailableWindow() const win = getAvailableWindow()
bus.emit(GET_WINDOW_ID_REPONSE, win.id) bus.emit(GET_WINDOW_ID_REPONSE, win.id)
} }
function busCallGetSettingWindowId () { function busCallGetSettingWindowId () {
const settingWindow = windowManager.get(IWindowList.SETTING_WINDOW)! if (!settingWindow) createSettingWindow()
bus.emit(GET_SETTING_WINDOW_ID_RESPONSE, settingWindow.id) bus.emit(GET_SETTING_WINDOW_ID_RESPONSE, settingWindow!.id)
} }
// Exit cleanly on request from parent process in development mode. // Exit cleanly on request from parent process in development mode.
-27
View File
@@ -1,27 +0,0 @@
export enum IWindowList {
SETTING_WINDOW = 'SETTING_WINDOW',
TRAY_WINDOW = 'TRAY_WINDOW',
MINI_WINDOW = 'MINI_WINDOW',
RENAME_WINDOW = 'RENAME_WINDOW'
}
const isDevelopment = process.env.NODE_ENV !== 'production'
export const TRAY_WINDOW_URL = isDevelopment
? (process.env.WEBPACK_DEV_SERVER_URL as string)
: `picgo://./index.html`
export const SETTING_WINDOW_URL = isDevelopment
? `${(process.env.WEBPACK_DEV_SERVER_URL as string)}#setting/upload`
: `picgo://./index.html#setting/upload`
export const MINI_WINDOW_URL = isDevelopment
? `${(process.env.WEBPACK_DEV_SERVER_URL as string)}#mini-page`
: `picgo://./index.html#mini-page`
export const RENAME_WINDOW_URL = process.env.NODE_ENV === 'development'
? `${(process.env.WEBPACK_DEV_SERVER_URL as string)}#rename-page`
: `picgo://./index.html#rename-page`
export const DELETE_WINDOW_EVENT = 'DELETE_WINDOW_EVENT'
export const CREATE_WINDOW_EVENT = 'CREATE_WINDOW_EVENT'
-181
View File
@@ -1,181 +0,0 @@
import {
IWindowList,
DELETE_WINDOW_EVENT,
CREATE_WINDOW_EVENT,
SETTING_WINDOW_URL,
TRAY_WINDOW_URL,
MINI_WINDOW_URL,
RENAME_WINDOW_URL
} from './constants'
import { IWindowListItem } from '#/types/electron'
import bus from '~/main/utils/eventBus'
import db from '#/datastore'
import { getWindowId } from '~/main/apis/bus'
import { BrowserWindow, app } from 'electron'
import { CREATE_APP_MENU } from '~/main/apis/bus/constants'
const windowList = new Map<IWindowList, IWindowListItem>()
windowList.set(IWindowList.TRAY_WINDOW, {
isValid: process.platform !== 'linux',
multiple: false,
options () {
return {
height: 350,
width: 196, // 196
show: false,
frame: false,
fullscreenable: false,
resizable: false,
transparent: true,
vibrancy: 'ultra-dark',
webPreferences: {
nodeIntegration: true,
nodeIntegrationInWorker: true,
backgroundThrottling: false
}
}
},
callback (window) {
const id = window!.id
window!.loadURL(TRAY_WINDOW_URL)
window!.on('closed', () => {
bus.emit(DELETE_WINDOW_EVENT, id)
})
window!.on('blur', () => {
window!.hide()
})
}
})
windowList.set(IWindowList.SETTING_WINDOW, {
isValid: true,
multiple: false,
options () {
const options: IBrowserWindowOptions = {
height: 450,
width: 800,
show: false,
frame: true,
center: true,
fullscreenable: false,
resizable: false,
title: 'PicGo',
vibrancy: 'ultra-dark',
transparent: true,
titleBarStyle: 'hidden',
webPreferences: {
backgroundThrottling: false,
nodeIntegration: true,
nodeIntegrationInWorker: true,
webSecurity: false
}
}
if (process.platform !== 'darwin') {
options.show = false
options.frame = false
options.backgroundColor = '#3f3c37'
options.transparent = false
options.icon = `${__static}/logo.png`
}
return options
},
callback (window) {
const id = window!.id
window!.loadURL(SETTING_WINDOW_URL)
window!.on('closed', () => {
bus.emit('toggleShortKeyModifiedMode', false)
bus.emit(DELETE_WINDOW_EVENT, id)
if (process.platform === 'linux') {
process.nextTick(() => {
app.quit()
})
}
})
bus.emit(CREATE_APP_MENU)
bus.emit(CREATE_WINDOW_EVENT, IWindowList.MINI_WINDOW)
}
})
windowList.set(IWindowList.MINI_WINDOW, {
isValid: process.platform !== 'darwin',
multiple: false,
options () {
let obj: IBrowserWindowOptions = {
height: 64,
width: 64,
show: process.platform === 'linux',
frame: false,
fullscreenable: false,
skipTaskbar: true,
resizable: false,
transparent: process.platform !== 'linux',
icon: `${__static}/logo.png`,
webPreferences: {
backgroundThrottling: false,
nodeIntegration: true,
nodeIntegrationInWorker: true
}
}
if (db.get('settings.miniWindowOntop')) {
obj.alwaysOnTop = true
}
return obj
},
callback (window) {
const id = window!.id
window!.loadURL(MINI_WINDOW_URL)
window!.on('closed', () => {
bus.emit(DELETE_WINDOW_EVENT, id)
})
}
})
windowList.set(IWindowList.RENAME_WINDOW, {
isValid: true,
multiple: true,
options () {
let options: IBrowserWindowOptions = {
height: 175,
width: 300,
show: true,
fullscreenable: false,
resizable: false,
vibrancy: 'ultra-dark',
webPreferences: {
nodeIntegration: true,
nodeIntegrationInWorker: true,
backgroundThrottling: false
}
}
if (process.platform !== 'darwin') {
options.show = true
options.backgroundColor = '#3f3c37'
options.autoHideMenuBar = true
options.transparent = false
}
return options
},
async callback (window) {
window!.loadURL(RENAME_WINDOW_URL)
const currentWindowId = await getWindowId()
const currentWindow = BrowserWindow.fromId(currentWindowId)
if (currentWindow && currentWindow.isVisible()) {
// bounds: { x: 821, y: 75, width: 800, height: 450 }
const bounds = currentWindow.getBounds()
const positionX = bounds.x + bounds.width / 2 - 150
let positionY
// if is the settingWindow
if (bounds.height > 400) {
positionY = bounds.y + bounds.height / 2 - 88
} else { // if is the miniWindow
positionY = bounds.y + bounds.height / 2
}
window!.setPosition(positionX, positionY, false)
}
}
})
export default windowList
-77
View File
@@ -1,77 +0,0 @@
import {
BrowserWindow
} from 'electron'
import { IWindowManager, IWindowListItem } from '#/types/electron'
import windowList from './windowList'
import {
IWindowList,
DELETE_WINDOW_EVENT,
CREATE_WINDOW_EVENT
} from './constants'
import bus from '~/main/utils/eventBus'
class WindowManager implements IWindowManager {
private windowMap: Map<IWindowList | string, BrowserWindow> = new Map()
private windowIdMap: Map<number, IWindowList | string> = new Map()
constructor () {
bus.on(DELETE_WINDOW_EVENT, this.deleteById)
bus.on(CREATE_WINDOW_EVENT, this.create)
}
create = (name: IWindowList) => {
const windowConfig: IWindowListItem = windowList.get(name)!
if (windowConfig.isValid) {
if (!windowConfig.multiple) {
if (this.windowMap.has(name)) return this.windowMap.get(name)!
}
const window = new BrowserWindow(windowConfig.options())
if (windowConfig.multiple) {
this.windowMap.set(`${name}_${window.id}`, window)
this.windowIdMap.set(window.id, `${name}_${window.id}`)
} else {
this.windowMap.set(name, window)
this.windowIdMap.set(window.id, name)
}
windowConfig.callback(window)
return window
} else {
return null
}
}
get (name: IWindowList) {
if (this.windowMap.has(name)) {
return this.windowMap.get(name)!
} else {
const window = this.create(name)
return window
}
}
has (name: IWindowList) {
return this.windowMap.has(name)
}
delete = (name: IWindowList) => {
const window = this.windowMap.get(name)
if (window) {
this.windowIdMap.delete(window.id)
this.windowMap.delete(name)
}
}
deleteById = (id: number) => {
const name = this.windowIdMap.get(id)
if (name) {
this.windowMap.delete(name)
this.windowIdMap.delete(id)
}
}
getAvailableWindow () {
const miniWindow = this.windowMap.get(IWindowList.MINI_WINDOW)
if (miniWindow && miniWindow.isVisible()) {
return miniWindow
} else {
const settingWindow = this.windowMap.get(IWindowList.SETTING_WINDOW)
const trayWindow = this.windowMap.get(IWindowList.TRAY_WINDOW)
return settingWindow || trayWindow || this.create(IWindowList.SETTING_WINDOW)!
}
}
}
export default new WindowManager()
+6 -23
View File
@@ -3,37 +3,20 @@ import routers from './routerManager'
import { import {
handleResponse handleResponse
} from './utils' } from './utils'
import picgo from '~/main/apis/picgo' import picgo from '~/main/utils/picgo'
import logger from '~/main/utils/logger' import logger from '~/main/utils/logger'
class Server { class Server {
private httpServer: http.Server private httpServer: http.Server
private config: IServerConfig private config: IServerConfig
constructor () { constructor () {
let config = picgo.getConfig('settings.server') this.config = picgo.getConfig('settings.server') || {
const result = this.checkIfConfigIsValid(config) port: 36677,
if (result) { host: '127.0.0.1',
this.config = config enable: true
} else {
config = {
port: 36677,
host: '127.0.0.1',
enable: true
}
this.config = config
picgo.saveConfig({
'settings.server': config
})
} }
this.httpServer = http.createServer(this.handleRequest) this.httpServer = http.createServer(this.handleRequest)
} }
private checkIfConfigIsValid (config: IObj | undefined) {
if (config && config.port && config.host && (config.enable !== undefined)) {
return true
} else {
return false
}
}
private handleRequest = (request: http.IncomingMessage, response: http.ServerResponse) => { private handleRequest = (request: http.IncomingMessage, response: http.ServerResponse) => {
if (request.method === 'POST') { if (request.method === 'POST') {
if (!routers.getHandler(request.url!)) { if (!routers.getHandler(request.url!)) {
@@ -82,7 +65,7 @@ class Server {
logger.warn(`[PicGo Server] ${port} is busy, trying with port ${port + 1}`) logger.warn(`[PicGo Server] ${port} is busy, trying with port ${port + 1}`)
this.config.port += 1 this.config.port += 1
picgo.saveConfig({ picgo.saveConfig({
'settings.server': this.config 'settings.server.port': this.config.port
}) })
this.listen(this.config.port) this.listen(this.config.port)
} }
+1 -1
View File
@@ -2,7 +2,7 @@ import router from './router'
import { import {
uploadWithClipboardFiles, uploadWithClipboardFiles,
uploadWithFiles uploadWithFiles
} from '~/main/apis/bus/index' } from '~/main/utils/busApi/index'
import { import {
handleResponse handleResponse
} from './utils' } from './utils'
@@ -6,4 +6,3 @@ export const UPLOAD_WITH_FILES = 'UPLOAD_WITH_FILES'
export const UPLOAD_WITH_FILES_RESPONSE = 'UPLOAD_WITH_FILES_RESPONSE' export const UPLOAD_WITH_FILES_RESPONSE = 'UPLOAD_WITH_FILES_RESPONSE'
export const UPLOAD_WITH_CLIPBOARD_FILES = 'UPLOAD_WITH_CLIPBOARD_FILES' export const UPLOAD_WITH_CLIPBOARD_FILES = 'UPLOAD_WITH_CLIPBOARD_FILES'
export const UPLOAD_WITH_CLIPBOARD_FILES_RESPONSE = 'UPLOAD_WITH_CLIPBOARD_FILES_RESPONSE' export const UPLOAD_WITH_CLIPBOARD_FILES_RESPONSE = 'UPLOAD_WITH_CLIPBOARD_FILES_RESPONSE'
export const CREATE_APP_MENU = 'CREATE_APP_MENU'
@@ -1,4 +1,4 @@
import bus from '../../utils/eventBus' import bus from '../eventBus'
import { import {
UPLOAD_WITH_FILES, UPLOAD_WITH_FILES,
UPLOAD_WITH_FILES_RESPONSE, UPLOAD_WITH_FILES_RESPONSE,
+4 -2
View File
@@ -1,4 +1,4 @@
import picgo from '../apis/picgo' import picgo from './picgo'
const getPicBeds = () => { const getPicBeds = () => {
const picBedTypes = picgo.helper.uploader.getIdList() const picBedTypes = picgo.helper.uploader.getIdList()
@@ -14,4 +14,6 @@ const getPicBeds = () => {
return picBeds return picBeds
} }
export default getPicBeds export {
getPicBeds
}
@@ -8,12 +8,12 @@ import {
webContents webContents
} from 'electron' } from 'electron'
import db from '#/datastore' import db from '#/datastore'
import uploader from '../uploader' import uploader from './uploader'
import pasteTemplate from '#/utils/pasteTemplate' import pasteTemplate from '#/utils/pasteTemplate'
import { import {
getWindowId, getWindowId,
getSettingWindowId getSettingWindowId
} from '~/main/apis/bus' } from '~/main/utils/busApi'
class GuiApi implements IGuiApi { class GuiApi implements IGuiApi {
private windowId: number = -1 private windowId: number = -1
View File
+3 -3
View File
@@ -1,5 +1,5 @@
import path from 'path' import path from 'path'
import GuiApi from '../apis/gui' import GuiApi from './guiApi'
import { import {
dialog, dialog,
shell, shell,
@@ -11,8 +11,8 @@ import {
} from 'electron' } from 'electron'
import PicGoCore from '~/universal/types/picgo' import PicGoCore from '~/universal/types/picgo'
import { IPicGoHelperType } from '#/types/enum' import { IPicGoHelperType } from '#/types/enum'
import shortKeyHandler from '../apis/shortKey/shortKeyHandler' import shortKeyHandler from './shortKeyHandler'
import picgo from '~/main/apis/picgo' import picgo from '~/main/utils/picgo'
// eslint-disable-next-line // eslint-disable-next-line
const requireFunc = typeof __webpack_require__ === 'function' ? __non_webpack_require__ : require const requireFunc = typeof __webpack_require__ === 'function' ? __non_webpack_require__ : require
@@ -1,4 +1,4 @@
import bus from '../../utils/eventBus' import bus from './eventBus'
import PicGoCore from '~/universal/types/picgo' import PicGoCore from '~/universal/types/picgo'
import path from 'path' import path from 'path'
import { import {
@@ -6,11 +6,11 @@ import {
globalShortcut, globalShortcut,
BrowserWindow BrowserWindow
} from 'electron' } from 'electron'
import logger from '../../utils/logger' import logger from './logger'
import GuiApi from '../gui' import GuiApi from './guiApi'
import db from '#/datastore' import db from '#/datastore'
import shortKeyService from './shortKeyService' import shortKeyService from './shortkeyService'
import picgo from '../picgo' import picgo from './picgo'
class ShortKeyHandler { class ShortKeyHandler {
private isInModifiedMode: boolean = false private isInModifiedMode: boolean = false
@@ -1,4 +1,4 @@
import logger from '../../utils/logger' import logger from './logger'
class ShortKeyService { class ShortKeyService {
private commandList: Map<string, IShortKeyHandler> = new Map() private commandList: Map<string, IShortKeyHandler> = new Map()
registerCommand (command: string, handler: IShortKeyHandler) { registerCommand (command: string, handler: IShortKeyHandler) {
@@ -6,10 +6,53 @@ import {
WebContents WebContents
} from 'electron' } from 'electron'
import dayjs from 'dayjs' import dayjs from 'dayjs'
import picgo from '~/main/apis/picgo' import picgo from '~/main/utils/picgo'
import db from '#/datastore' import db from '#/datastore'
import windowManager from '~/main/apis/window/windowManager'
import { IWindowList } from '~/main/apis/window/constants' const renameURL = process.env.NODE_ENV === 'development'
? `${(process.env.WEBPACK_DEV_SERVER_URL as string)}#rename-page`
: `picgo://./index.html#rename-page`
const createRenameWindow = (currentWindow: BrowserWindow) => {
let options: IBrowserWindowOptions = {
height: 175,
width: 300,
show: true,
fullscreenable: false,
resizable: false,
vibrancy: 'ultra-dark',
webPreferences: {
nodeIntegration: true,
nodeIntegrationInWorker: true,
backgroundThrottling: false
}
}
if (process.platform !== 'darwin') {
options.show = true
options.backgroundColor = '#3f3c37'
options.autoHideMenuBar = true
options.transparent = false
}
const window = new BrowserWindow(options)
window.loadURL(renameURL)
// check if this window is visible
if (currentWindow && currentWindow.isVisible()) {
// bounds: { x: 821, y: 75, width: 800, height: 450 }
const bounds = currentWindow.getBounds()
const positionX = bounds.x + bounds.width / 2 - 150
let positionY
// if is the settingWindow
if (bounds.height > 400) {
positionY = bounds.y + bounds.height / 2 - 88
} else { // if is the miniWindow
positionY = bounds.y + bounds.height / 2
}
window.setPosition(positionX, positionY, false)
}
return window
}
const waitForShow = (webcontent: WebContents) => { const waitForShow = (webcontent: WebContents) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@@ -21,7 +64,6 @@ const waitForShow = (webcontent: WebContents) => {
const waitForRename = (window: BrowserWindow, id: number): Promise<string|null> => { const waitForRename = (window: BrowserWindow, id: number): Promise<string|null> => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const windowId = window.id
ipcMain.once(`rename${id}`, (evt: Event, newName: string) => { ipcMain.once(`rename${id}`, (evt: Event, newName: string) => {
resolve(newName) resolve(newName)
window.close() window.close()
@@ -29,13 +71,13 @@ const waitForRename = (window: BrowserWindow, id: number): Promise<string|null>
window.on('close', () => { window.on('close', () => {
resolve(null) resolve(null)
ipcMain.removeAllListeners(`rename${id}`) ipcMain.removeAllListeners(`rename${id}`)
windowManager.deleteById(windowId)
}) })
}) })
} }
class Uploader { class Uploader {
private webContents: WebContents | null = null private webContents: WebContents | null = null
private currentWindow: BrowserWindow | null = null
constructor () { constructor () {
this.init() this.init()
} }
@@ -47,7 +89,7 @@ class Uploader {
}) })
picgo.on('uploadProgress', progress => { picgo.on('uploadProgress', progress => {
this.webContents?.send('uploadProgress', progress) this.webContents!.send('uploadProgress', progress)
}) })
picgo.on('beforeTransform', ctx => { picgo.on('beforeTransform', ctx => {
if (db.get('settings.uploadNotification')) { if (db.get('settings.uploadNotification')) {
@@ -71,7 +113,7 @@ class Uploader {
fileName = item.fileName fileName = item.fileName
} }
if (rename) { if (rename) {
const window = windowManager.create(IWindowList.RENAME_WINDOW)! const window = createRenameWindow(this.currentWindow!)
await waitForShow(window.webContents) await waitForShow(window.webContents)
window.webContents.send('rename', fileName, window.webContents.id) window.webContents.send('rename', fileName, window.webContents.id)
name = await waitForRename(window, window.webContents.id) name = await waitForRename(window, window.webContents.id)
@@ -88,6 +130,8 @@ class Uploader {
} }
upload (img?: IUploadOption): Promise<ImgInfo[]|false> { upload (img?: IUploadOption): Promise<ImgInfo[]|false> {
this.currentWindow = BrowserWindow.fromWebContents(this.webContents!)
picgo.upload(img) picgo.upload(img)
return new Promise((resolve) => { return new Promise((resolve) => {
+10 -7
View File
@@ -237,8 +237,9 @@ export default class extends Vue {
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning' type: 'warning'
}).then(() => { }).then(() => {
const file = this.$db.getById('uploaded', id) const file = this.$db.get('uploaded').getById(id)
this.$db.removeById('uploaded', id) // @ts-ignore
this.$db.read().get('uploaded').removeById(id).write()
ipcRenderer.send('removeFiles', [file]) ipcRenderer.send('removeFiles', [file])
const obj = { const obj = {
title: '操作结果', title: '操作结果',
@@ -249,8 +250,7 @@ export default class extends Vue {
return true return true
} }
this.getGallery() this.getGallery()
}).catch((e) => { }).catch(() => {
console.log(e)
return true return true
}) })
} }
@@ -302,9 +302,11 @@ export default class extends Vue {
let files: ImgInfo[] = [] let files: ImgInfo[] = []
Object.keys(this.choosedList).forEach(key => { Object.keys(this.choosedList).forEach(key => {
if (this.choosedList[key]) { if (this.choosedList[key]) {
const file = this.$db.getById('uploaded', key) // @ts-ignore
const file = this.$db.read().get('uploaded').getById(key).value()
files.push(file) files.push(file)
this.$db.removeById('uploaded', key) // @ts-ignore
this.$db.read().get('uploaded').removeById(key).write()
} }
}) })
this.choosedList = {} this.choosedList = {}
@@ -330,7 +332,8 @@ export default class extends Vue {
// choosedList -> { [id]: true or false }; true means choosed. false means not choosed. // choosedList -> { [id]: true or false }; true means choosed. false means not choosed.
Object.keys(this.choosedList).forEach(key => { Object.keys(this.choosedList).forEach(key => {
if (this.choosedList[key]) { if (this.choosedList[key]) {
const item = this.$db.getById('uploaded', key) // @ts-ignore
const item = this.$db.read().get('uploaded').getById(key).value()
copyString += pasteStyle(style, item) + '\n' copyString += pasteStyle(style, item) + '\n'
this.choosedList[key] = false this.choosedList[key] = false
} }
+2 -4
View File
@@ -170,10 +170,8 @@ export default class extends Vue {
} }
}, },
{ {
label: '隐藏窗口', label: '最小化窗口',
click () { role: 'minimize'
remote.BrowserWindow.getFocusedWindow()!.hide()
}
}, },
{ {
label: '重启应用', label: '重启应用',
-8
View File
@@ -61,14 +61,6 @@ class DB {
unset (key: string, value: any): boolean { unset (key: string, value: any): boolean {
return this.read().get(key).unset(value).value() return this.read().get(key).unset(value).value()
} }
getById (key: string, id: string) {
// @ts-ignore
return this.read().get(key).getById(id).value()
}
removeById (key: string, id: string) {
// @ts-ignore
return this.read().get(key).removeById(id).write()
}
} }
export default new DB() export default new DB()
-20
View File
@@ -1,20 +0,0 @@
import {
BrowserWindow
} from 'electron'
import {
IWindowList
} from '~/main/apis/window/constants'
declare interface IWindowListItem {
isValid: boolean
multiple: boolean
options: () => IBrowserWindowOptions,
callback: (window: BrowserWindow | null) => void
}
declare interface IWindowManager {
create: (name: IWindowList) => BrowserWindow | null
get: (name: IWindowList) => BrowserWindow | null
delete: (name: IWindowList) => void
getAvailableWindow: () => BrowserWindow
}
+6 -5
View File
@@ -7,7 +7,7 @@ interface IObjT<T> {
[propName: string]: T [propName: string]: T
} }
declare interface ErrnoException extends Error { interface ErrnoException extends Error {
errno?: number | string; errno?: number | string;
code?: string; code?: string;
path?: string; path?: string;
@@ -15,10 +15,6 @@ declare interface ErrnoException extends Error {
stack?: string; stack?: string;
} }
declare var __static: string
declare type ILogType = 'success' | 'info' | 'warn' | 'error'
// Server // Server
type routeHandler = (ctx: IServerCTX) => Promise<void> type routeHandler = (ctx: IServerCTX) => Promise<void>
@@ -118,6 +114,11 @@ interface IBounds {
y: number y: number
} }
declare type ILogType = 'success' | 'info' | 'warn' | 'error'
// global value
declare var __static: string
// PicGo Types // PicGo Types
type ICtx = import('picgo') type ICtx = import('picgo')
interface IPicGoPlugin { interface IPicGoPlugin {
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"compilerOptions": { "compilerOptions": {
"target": "es2020", "target": "esnext",
"module": "esnext", "module": "esnext",
"strict": true, "strict": true,
"jsx": "preserve", "jsx": "preserve",
-3
View File
@@ -64,9 +64,6 @@ module.exports = {
}, },
linux: { linux: {
icon: 'build/icons/' icon: 'build/icons/'
},
snap: {
publish: ['github']
} }
} }
} }