save-photo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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