electron-app-sexy
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
const { dialog } = require('electron'); | |
const { autoUpdater } = require('electron-updater'); | |
autoUpdater.autoDownload = true; | |
autoUpdater.on('error', (error) => { | |
dialog.showErrorBox('Error: ', error == null ? "unknown" : (error.stack || error).toString()); | |
}); | |
autoUpdater.on('update-available', () => { | |
dialog.showMessageBox({ | |
type: 'info', | |
title: 'Found Updates', | |
message: 'Found updates, do you want update now?', | |
buttons: ['Sure', 'No'] | |
}, (buttonIndex) => { | |
if (buttonIndex === 0) { | |
autoUpdater.downloadUpdate(); | |
} | |
}); | |
}); | |
autoUpdater.on('update-not-available', () => { | |
dialog.showMessageBox({ | |
title: 'No Updates', | |
message: 'Current version is up-to-date.' | |
}); | |
}); | |
autoUpdater.on('update-downloaded', () => { | |
dialog.showMessageBox({ | |
title: 'Install Updates', | |
message: 'Updates downloaded, application will be quit for update...' | |
}, () => { | |
setImmediate(() => autoUpdater.quitAndInstall()); | |
}); | |
}); | |
function checkForUpdates (menuItem, focusedWindow, event) { | |
autoUpdater.checkForUpdates(); | |
} | |
module.exports.checkForUpdates = checkForUpdates; |
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
module.exports = { | |
init: () => { | |
const dragAndDrop = document.getElementById('drag-and-drop'); | |
dragAndDrop.ondragover = () => { | |
return false; | |
}; | |
dragAndDrop.ondragleave = () => { | |
return false; | |
}; | |
dragAndDrop.ondragend = () => { | |
return false; | |
}; | |
dragAndDrop.ondrop = (e) => { | |
e.preventDefault(); | |
const paths = []; | |
for (let file of e.dataTransfer.files) { | |
paths.push(file.path); | |
} | |
// create html from file paths | |
const fileItems = paths.reduce((html, file) => { | |
html += `<li class="file-item">${file}</li>`; | |
return html; | |
}, ''); | |
// put File paths items into fileList element | |
const fileList = document.getElementById('fileList'); | |
fileList.innerHTML = fileItems; | |
return false; | |
}; | |
}, | |
}; |
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
const { crashReporter } = require('electron') | |
crashReporter.start({ submitURL: 'https://your-domain.com/url-to-submit' }) |
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
module.exports = { | |
notify: (message) => { | |
const notification = { | |
title: 'Electron App', | |
body: message, | |
icon: 'assets/icons/check-ok.ico' | |
}; | |
new window.Notification(notification.title, notification); | |
} | |
}; |
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
import { Menu, Tray, nativeImage } from 'electron'; | |
let tray = null; | |
const trayIcon = nativeImage.createFromPath('assets/icons/electron-logo-icon.png').resize({ | |
width: 18, | |
height: 18, | |
}); | |
module.exports = { | |
setTray: () => { | |
tray = new Tray(trayIcon); | |
const contextMenu = Menu.buildFromTemplate([ | |
{ label: 'Tray item 1', type: 'radio' }, | |
{ label: 'Tray item 2', type: 'radio' }, | |
{ label: 'Tray item 3', type: 'radio', checked: true } | |
]); | |
tray.setToolTip('This text comes from tray module.'); | |
// Need to call to set Context Menu. | |
tray.setContextMenu(contextMenu); | |
}, | |
destroy: () => { | |
if (tray) { | |
tray.destroy(); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment