Feature: support commandline -> upload images in clipboard

This commit is contained in:
Molunerfinn 2019-04-15 10:28:11 +08:00
parent 407b821aca
commit 74c7016d2c
2 changed files with 45 additions and 29 deletions

View File

@ -501,14 +501,18 @@ if (!gotTheLock) {
} else {
app.on('second-instance', (event, commandLine, workingDirectory) => {
let files = getUploadFiles(commandLine, workingDirectory)
if (files.length > 0) { // 如果有文件列表作为参数,说明是命令行启动
let win
if (miniWindow && miniWindow.isVisible()) {
win = miniWindow
if (files === null || files.length > 0) { // 如果有文件列表作为参数,说明是命令行启动
if (files === null) {
uploadClipboardFiles()
} else {
win = settingWindow || window || createSettingWindow()
let win
if (miniWindow && miniWindow.isVisible()) {
win = miniWindow
} else {
win = settingWindow || window || createSettingWindow()
}
uploadChoosedFiles(win.webContents, files)
}
uploadChoosedFiles(win.webContents, files)
} else {
if (settingWindow) {
if (settingWindow.isMinimized()) {
@ -542,14 +546,18 @@ app.on('ready', () => {
})
if (process.env.NODE_ENV !== 'development') {
let files = getUploadFiles()
if (files.length > 0) { // 如果有文件列表作为参数,说明是命令行启动
let win
if (miniWindow && miniWindow.isVisible()) {
win = miniWindow
if (files === null || files.length > 0) { // 如果有文件列表作为参数,说明是命令行启动
if (files === null) {
uploadClipboardFiles()
} else {
win = settingWindow || window || createSettingWindow()
let win
if (miniWindow && miniWindow.isVisible()) {
win = miniWindow
} else {
win = settingWindow || window || createSettingWindow()
}
uploadChoosedFiles(win.webContents, files)
}
uploadChoosedFiles(win.webContents, files)
}
}
})

View File

@ -2,26 +2,34 @@ import path from 'path'
import fs from 'fs-extra'
const getUploadFiles = (argv = process.argv, cwd = process.cwd()) => {
let files = argv.slice(1)
let result = []
if (files.length > 0) {
result = files.map(item => {
if (path.isAbsolute(item)) {
return {
path: item
}
} else {
let tempPath = path.join(cwd, item)
if (fs.existsSync(tempPath)) {
return {
path: tempPath
if (files.length > 0 && files[0] === 'upload') {
if (files.length === 1) {
return null // for uploading images in clipboard
} else if (files.length > 1) {
files = argv.slice(1)
let result = []
if (files.length > 0) {
result = files.map(item => {
if (path.isAbsolute(item)) {
return {
path: item
}
} else {
let tempPath = path.join(cwd, item)
if (fs.existsSync(tempPath)) {
return {
path: tempPath
}
} else {
return null
}
}
} else {
return null
}
}).filter(item => item !== null)
}
}).filter(item => item !== null)
return result
}
}
return result
return []
}
export {