UNPKG

1.56 kBJavaScriptView Raw
1/**
2 * Copyright (c) Facebook, Inc. and its affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * @flow
8 */
9
10const {app, BrowserWindow} = require('electron'); // Module to create native browser window.
11const {join} = require('path');
12
13const argv = require('minimist')(process.argv.slice(2));
14const projectRoots = argv._;
15
16let mainWindow = null;
17
18app.on('window-all-closed', function() {
19 app.quit();
20});
21
22app.on('ready', function() {
23 // Create the browser window.
24 mainWindow = new BrowserWindow({
25 width: 800,
26 height: 600,
27 icon: join(__dirname, 'icons/icon128.png'),
28 frame: false,
29 //titleBarStyle: 'customButtonsOnHover',
30 webPreferences: {
31 nodeIntegration: true,
32 },
33 });
34
35 // https://stackoverflow.com/questions/32402327/
36 mainWindow.webContents.on('new-window', function(event, url) {
37 event.preventDefault();
38 require('electron').shell.openExternal(url);
39 });
40
41 // and load the index.html of the app.
42 mainWindow.loadURL('file://' + __dirname + '/app.html'); // eslint-disable-line no-path-concat
43 mainWindow.webContents.executeJavaScript(
44 // We use this so that RN can keep relative JSX __source filenames
45 // but "click to open in editor" still works. js1 passes project roots
46 // as the argument to DevTools.
47 'window.devtools.setProjectRoots(' + JSON.stringify(projectRoots) + ')',
48 );
49
50 // Emitted when the window is closed.
51 mainWindow.on('closed', function() {
52 mainWindow = null;
53 });
54});