ridereceipts
Version:
Simple automation desktop app to download and organize your tax invoices from Uber.
125 lines (107 loc) • 3.23 kB
JavaScript
import { app, BrowserWindow, ipcMain, Menu, session } from 'electron'
import fkill from 'fkill'
import Store from 'electron-store'
import updateElectron from 'update-electron-app'
import path from 'path'
import 'electron-context-menu'
// let myWindow = null
const store = new Store()
updateElectron({
repo: 'ridereceipts/ridereceipts',
updateInterval: '1 hour'
})
/**
* Set `__static` path to static files in production
* https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-static-assets.html
*/
if (process.env.NODE_ENV !== 'development') {
global.__static = require('path').join(__dirname, '/static').replace(/\\/g, '\\\\')
}
let mainWindow
const winURL = process.env.NODE_ENV === 'development'
? `http://localhost:9080`
: `file://${__dirname}/index.html`
const openAboutWindow = require('about-window').default
function createWindow () {
/**
* Initial window options
*/
mainWindow = new BrowserWindow({
height: 650,
useContentSize: true,
width: 960,
minWidth: 900,
minHeight: 600,
resizable: false
})
mainWindow.loadURL(winURL)
mainWindow.on('closed', () => {
mainWindow = null
})
// Create the Application's main menu
const template = [{
label: 'Application',
submenu: [
{
label: 'About Application',
click: () => openAboutWindow({
icon_path: path.join(__static, '/256x256.png'),
copyright: 'Copyright (c) 2018 Hello Efficiency Inc.',
open_devtools: process.env.NODE_ENV !== 'production',
homepage: 'https:/ridereceipts.io',
license: 'MIT',
product_name: 'Ride Receipts',
package_json_dir: path.join(__dirname, '../..'),
use_version_info: false
})
},
{ type: 'separator' },
{ label: 'Quit',
accelerator: 'Command+Q',
click: function () {
app.quit()
} }
] }, {
label: 'Edit',
submenu: [
{ label: 'Undo', accelerator: 'CmdOrCtrl+Z', selector: 'undo:' },
{ label: 'Redo', accelerator: 'Shift+CmdOrCtrl+Z', selector: 'redo:' },
{ type: 'separator' },
{ label: 'Cut', accelerator: 'CmdOrCtrl+X', selector: 'cut:' },
{ label: 'Copy', accelerator: 'CmdOrCtrl+C', selector: 'copy:' },
{ label: 'Paste', accelerator: 'CmdOrCtrl+V', selector: 'paste:' },
{ label: 'Select All', accelerator: 'CmdOrCtrl+A', selector: 'selectAll:' }
] }
]
Menu.setApplicationMenu(Menu.buildFromTemplate(template))
}
// Allow only one instance
app.requestSingleInstanceLock()
app.on('second-instance', function (event, argv, cwd) {
app.quit()
})
app.commandLine.appendSwitch('disable-renderer-backgrounding')
app.on('ready', createWindow)
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('quit', () => {
session.defaultSession.clearStorageData()
if (store.has('processPID')) {
fkill(store.get('processPID', {
force: true
}))
store.delete('processPID')
}
})
app.on('activate', () => {
if (mainWindow === null) {
createWindow()
}
})
ipcMain.on('online-status-changed', (event, status) => {
event.sender.send('onlinestatus', status)
})