Skip to content

Commit

Permalink
add notification on export/import tasks (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
bukinoshita committed Jan 4, 2018
1 parent 4e7b926 commit 9cde336
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 6 deletions.
27 changes: 27 additions & 0 deletions renderer/services/notify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Packages
const { remote } = require('electron')

module.exports = ({ title, body, url, onClick }) => {
const icon = 'static/icon.ico'
const specs = {
title,
body,
icon,
silent: true
}

const notification = new remote.Notification(specs)

if (url || onClick) {
notification.on('click', () => {
if (onClick) {
return onClick()
}

remote.shell.openExternal(url)
})
}

notification.show()
console.log(`[Notification] ${title}: ${body}`)
}
38 changes: 32 additions & 6 deletions renderer/services/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const { writeJSON, readJson } = require('fs-extra')

// Services
const { getUser, updateUser } = require('./api')
const notify = require('./notify')

export const exportUser = () => {
remote.dialog.showSaveDialog(
Expand All @@ -15,7 +16,19 @@ export const exportUser = () => {
if (fileName) {
const user = getUser()

writeJSON(fileName, user).catch(err => console.log(err))
writeJSON(fileName, user)
.then(() =>
notify({
title: 'User config exported!',
body: 'Your user config was exported successfully'
})
)
.catch(err =>
notify({
title: 'Error!',
body: 'Ops, something happened! Please, try again.'
})
)
}
}
)
Expand All @@ -26,11 +39,24 @@ export const importUser = () => {
undefined,
{ properties: ['openFile'] },
filePath => {
readJson(filePath[0]).then(({ user }) => {
if (user) {
return updateUser(user)
}
})
readJson(filePath[0])
.then(({ user }) => {
if (user) {
return updateUser(user)
}
})
.then(() =>
notify({
title: 'User config imported!',
body: 'Your user config was imported successfully'
})
)
.catch(err =>
notify({
title: 'Error!',
body: 'Ops, something happened! Please, try again.'
})
)
}
)
}
Expand Down
Binary file added renderer/static/icon.ico
Binary file not shown.

0 comments on commit 9cde336

Please sign in to comment.