Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jksmall0631/e20cde1782affb3f925bb4cedd04a842 to your computer and use it in GitHub Desktop.
Save jksmall0631/e20cde1782affb3f925bb4cedd04a842 to your computer and use it in GitHub Desktop.
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