Skip to content

Commit

Permalink
✨ Feature: support commandline -> upload images in clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Molunerfinn committed Apr 15, 2019
1 parent 407b821 commit 74c7016
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 29 deletions.
32 changes: 20 additions & 12 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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)
}
}
})
Expand Down
42 changes: 25 additions & 17 deletions src/main/utils/handleArgv.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 74c7016

Please sign in to comment.