mirror of
https://github.com/Kuingsmile/PicList.git
synced 2025-02-02 11:08:13 -05:00
✨ Feature: support commandline -> upload images in clipboard
This commit is contained in:
parent
407b821aca
commit
74c7016d2c
@ -501,14 +501,18 @@ if (!gotTheLock) {
|
|||||||
} else {
|
} else {
|
||||||
app.on('second-instance', (event, commandLine, workingDirectory) => {
|
app.on('second-instance', (event, commandLine, workingDirectory) => {
|
||||||
let files = getUploadFiles(commandLine, workingDirectory)
|
let files = getUploadFiles(commandLine, workingDirectory)
|
||||||
if (files.length > 0) { // 如果有文件列表作为参数,说明是命令行启动
|
if (files === null || files.length > 0) { // 如果有文件列表作为参数,说明是命令行启动
|
||||||
let win
|
if (files === null) {
|
||||||
if (miniWindow && miniWindow.isVisible()) {
|
uploadClipboardFiles()
|
||||||
win = miniWindow
|
|
||||||
} else {
|
} 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 {
|
} else {
|
||||||
if (settingWindow) {
|
if (settingWindow) {
|
||||||
if (settingWindow.isMinimized()) {
|
if (settingWindow.isMinimized()) {
|
||||||
@ -542,14 +546,18 @@ app.on('ready', () => {
|
|||||||
})
|
})
|
||||||
if (process.env.NODE_ENV !== 'development') {
|
if (process.env.NODE_ENV !== 'development') {
|
||||||
let files = getUploadFiles()
|
let files = getUploadFiles()
|
||||||
if (files.length > 0) { // 如果有文件列表作为参数,说明是命令行启动
|
if (files === null || files.length > 0) { // 如果有文件列表作为参数,说明是命令行启动
|
||||||
let win
|
if (files === null) {
|
||||||
if (miniWindow && miniWindow.isVisible()) {
|
uploadClipboardFiles()
|
||||||
win = miniWindow
|
|
||||||
} else {
|
} 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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -2,26 +2,34 @@ import path from 'path'
|
|||||||
import fs from 'fs-extra'
|
import fs from 'fs-extra'
|
||||||
const getUploadFiles = (argv = process.argv, cwd = process.cwd()) => {
|
const getUploadFiles = (argv = process.argv, cwd = process.cwd()) => {
|
||||||
let files = argv.slice(1)
|
let files = argv.slice(1)
|
||||||
let result = []
|
if (files.length > 0 && files[0] === 'upload') {
|
||||||
if (files.length > 0) {
|
if (files.length === 1) {
|
||||||
result = files.map(item => {
|
return null // for uploading images in clipboard
|
||||||
if (path.isAbsolute(item)) {
|
} else if (files.length > 1) {
|
||||||
return {
|
files = argv.slice(1)
|
||||||
path: item
|
let result = []
|
||||||
}
|
if (files.length > 0) {
|
||||||
} else {
|
result = files.map(item => {
|
||||||
let tempPath = path.join(cwd, item)
|
if (path.isAbsolute(item)) {
|
||||||
if (fs.existsSync(tempPath)) {
|
return {
|
||||||
return {
|
path: item
|
||||||
path: tempPath
|
}
|
||||||
|
} else {
|
||||||
|
let tempPath = path.join(cwd, item)
|
||||||
|
if (fs.existsSync(tempPath)) {
|
||||||
|
return {
|
||||||
|
path: tempPath
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}).filter(item => item !== null)
|
||||||
return null
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}).filter(item => item !== null)
|
return result
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return result
|
return []
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
Loading…
Reference in New Issue
Block a user