Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
save-photo
ipcMain.on('save-selfie', (event, args) => {
const { fileName, img } = args
saveSelfie(fileName, img)
.then(path => wallpaper.set(path, { scale: 'fill' }))
.then(_ => {
notifier.notify({
'title': 'Wallpaper Updated',
'message': 'Updated Your Desktop Wallpaper to Your Selfie',
'sound': false,
})
event.sender.send('save-selfie-reply', 'selfie saved!')
})
.catch(err => event.sender.send('save-selfie-error', err))
})
const saveSelfie = (fileName, img) => {
return new Promise((resolve, reject) => {
const picsDir = app.getPath('pictures')
const path = join(picsDir, 'SplashTop-Selfies', fileName)
const dir = dirname(path)
fs.ensureDir(dir, err => {
if (err) { reject(err) }
const base64data = img.replace(/^data:image\/png;base64,/, '')
fs.writeFile(path, base64data, 'base64', resolve(path))
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment