Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Commit

Permalink
fix: use showSaveDialog with promise instead of callback (#1711)
Browse files Browse the repository at this point in the history
  • Loading branch information
faustbrian authored Feb 26, 2020
1 parent 0633214 commit 3545736
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions src/renderer/mixins/electron.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import electron from 'electron'
import { readFile, writeFile } from 'fs'
import { readFile, writeFileSync } from 'fs'

export default {
methods: {
Expand All @@ -12,25 +12,20 @@ export default {
win.reload()
},

electron_writeFile (raw, defaultPath, options = {}) {
const filters = options.filters || [
{ name: 'JSON', extensions: ['json'] },
{ name: 'All Files', extensions: ['*'] }
]
async electron_writeFile (raw, defaultPath, options = {}) {
const { filePath } = await electron.remote.dialog.showSaveDialog({
defaultPath,
filters: options.filters || [
{ name: 'JSON', extensions: ['json'] },
{ name: 'All Files', extensions: ['*'] }
]
})

return new Promise((resolve, reject) => {
electron.remote.dialog.showSaveDialog({
defaultPath,
filters
}, fileName => {
if (!fileName) return
if (!filePath) return

writeFile(fileName, raw, 'utf8', err => {
if (err) reject(err)
resolve(fileName)
})
})
})
writeFileSync(filePath, raw, 'utf8')

return filePath
},

electron_readFile (options = {}) {
Expand Down

0 comments on commit 3545736

Please sign in to comment.