diff --git a/src-electron/main.dev.js b/src-electron/main.dev.js new file mode 100644 index 00000000..57e43425 --- /dev/null +++ b/src-electron/main.dev.js @@ -0,0 +1,18 @@ +// Set environment for development +process.env.NODE_ENV = 'development' + +// Install `electron-debug` with `devtron` +require('electron-debug')({ showDevTools: true }) + +// Install `vue-devtools` +require('electron').app.on('ready', () => { + let installExtension = require('electron-devtools-installer') + installExtension.default(installExtension.VUEJS_DEVTOOLS) + .then(() => {}) + .catch(err => { + console.log('Unable to install `vue-devtools`: \n', err) + }) +}) + +// Require `main` process to boot app +require('./main') diff --git a/src-electron/main.js b/src-electron/main.js new file mode 100644 index 00000000..23ffba8c --- /dev/null +++ b/src-electron/main.js @@ -0,0 +1,51 @@ +const { app, BrowserWindow } = require('electron'); +const { getAppConfig } = require('frappejs/webpack/utils'); +const setupMenu = require('./menu'); + +const appConfig = getAppConfig(); + +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:${appConfig.dev.devServerPort}` + : `file://${__dirname}/index.html` + +function createWindow() { + /** + * Initial window options + */ + mainWindow = new BrowserWindow({ + width: 1024, + height: 768, + useContentSize: true + }) + + mainWindow.loadURL(winURL) + + mainWindow.on('closed', () => { + mainWindow = null + }) + + setupMenu(); +} + +app.on('ready', createWindow) + +app.on('window-all-closed', () => { + if (process.platform !== 'darwin') { + app.quit() + } +}) + +app.on('activate', () => { + if (mainWindow === null) { + createWindow() + } +}) + +// TODO: +// Enable Auto Update +// https://www.electron.build/auto-update/ diff --git a/src-electron/menu.js b/src-electron/menu.js new file mode 100644 index 00000000..53e5dffd --- /dev/null +++ b/src-electron/menu.js @@ -0,0 +1,93 @@ +const { app, Menu } = require('electron'); + +const template = [ + { + label: 'Edit', + submenu: [ + { role: 'undo' }, + { role: 'redo' }, + { type: 'separator' }, + { role: 'cut' }, + { role: 'copy' }, + { role: 'paste' }, + { role: 'pasteandmatchstyle' }, + { role: 'delete' }, + { role: 'selectall' } + ] + }, + { + label: 'View', + submenu: [ + { role: 'reload' }, + { role: 'forcereload' }, + { role: 'toggledevtools' }, + { type: 'separator' }, + { role: 'resetzoom' }, + { role: 'zoomin' }, + { role: 'zoomout' }, + { type: 'separator' }, + { role: 'togglefullscreen' } + ] + }, + { + role: 'window', + submenu: [ + { role: 'minimize' }, + { role: 'close' } + ] + }, + { + role: 'help', + submenu: [ + { + label: 'Learn More', + click() { require('electron').shell.openExternal('https://electronjs.org') } + } + ] + } +] + +if (process.platform === 'darwin') { + template.unshift({ + label: app.getName(), + submenu: [ + { role: 'about' }, + { type: 'separator' }, + { role: 'services', submenu: [] }, + { type: 'separator' }, + { role: 'hide' }, + { role: 'hideothers' }, + { role: 'unhide' }, + { type: 'separator' }, + { role: 'quit' } + ] + }) + + // Edit menu + template[1].submenu.push( + { type: 'separator' }, + { + label: 'Speech', + submenu: [ + { role: 'startspeaking' }, + { role: 'stopspeaking' } + ] + } + ) + + // Window menu + template[3].submenu = [ + { role: 'close' }, + { role: 'minimize' }, + { role: 'zoom' }, + { type: 'separator' }, + { role: 'front' } + ] +} + +function setupMenu() { + const menu = Menu.buildFromTemplate(template) + Menu.setApplicationMenu(menu); +} + +module.exports = setupMenu;