Skip to content

Commit

Permalink
improve error handling when files passed as arguments at launch canno…
Browse files Browse the repository at this point in the history
…t be opened
  • Loading branch information
stuffmatic committed Apr 14, 2020
1 parent 6f6cbb6 commit 8d00075
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,16 +286,31 @@ function createWindow() {
const openCommand = process.argv[argCount - 2]
const filePath = process.argv[argCount - 1]
if (openCommand == 'open' && filePath) {
if (ProjectFile.isProjectFile(filePath)) {
window.webContents.send(
OpenProjectMessage.type,
new OpenProjectMessage(filePath, false)
)
} else {
window.webContents.send(
OpenImageMessage.type,
new OpenImageMessage(filePath)
)
try {
// Make sure the file can be opened before proceeding
const fd = openSync(filePath, 'r')
closeSync(fd)

if (ProjectFile.isProjectFile(filePath)) {
window.webContents.send(
OpenProjectMessage.type,
new OpenProjectMessage(filePath, false)
)
} else {
window.webContents.send(
OpenImageMessage.type,
new OpenImageMessage(filePath)
)
}
} catch (error) {
console.log(error)
console.log('process.argv:')
console.log(process.argv)

const errorMessage = 'Failed to open \'' + filePath + '\'. ' + error
dialog.showMessageBoxSync(window, {
message: errorMessage
})
}
}
}
Expand Down

0 comments on commit 8d00075

Please sign in to comment.