Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

Initial version of Electron versions of basic, app templates #31

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

clarktlaugh
Copy link

@clarktlaugh clarktlaugh commented Apr 19, 2017

Implements two new templates:

  • electron-basic
  • electron-app
    which are versions of the original 'app' and 'basic' templates that work in Electron.

@clarktlaugh clarktlaugh changed the title Initial version of electron basic template Initial version of Electron basic template Apr 19, 2017
@RyanCCollins
Copy link
Member

Wow, nice one!

@clarktlaugh
Copy link
Author

This is about 99% identical to the 'basic' template. I don't know if there is a straightforward way to accomplish the slight differences without all of the duplication?

@clarktlaugh clarktlaugh changed the title Initial version of Electron basic template Initial version of Electron versions of basic, app templates Apr 21, 2017
@clarktlaugh
Copy link
Author

clarktlaugh commented Apr 21, 2017

I just updated this to include a new 'electron-app' template which is a version of 'app' that works in Electron. It's mostly the same as the original as well.

I've added comments within the review of the code to hopefully call out all of the places that needed to change, since it might be hard to really see them with all of the files showing as new.

new CopyWebpackPlugin([
{ from: './public' },
{ from: './electron-entry.js' },
{ from: './package.json' },
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 10,11 are changed from the original -- to copy the electron entrypoint script and package.json into dist

<meta name="mobile-web-app-capable" content="yes">
<link rel="shortcut icon" type="image/png" href="/img/shortcut-icon.png" />
<link rel="apple-touch-icon" sizes="196x196" type="image/png" href="/img/mobile-app-icon.png">
<link rel="stylesheet" type="text/css" href="index.css">
Copy link
Author

@clarktlaugh clarktlaugh Apr 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The / needed to be removed

}, 100)
</script>
</div>
<script async src="index.js"></script>
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The / needed to be removed

{
"name": "<%= appName %>",
"version": "0.1.0",
"main": "electron-entry.js",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to the electron entrypoint script

"test": "grommet check",
"dev": "cross-env NODE_ENV=development grommet pack",
"dist": "cross-env NODE_ENV=production grommet pack",
"electron-dev" : "electron ./dist"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A new script to launch the electron app

"sass-lint": "^1.10.2",
"sass-loader": "^6.0.3",
"webpack": "^2.2.1",
"electron": "~1.6.2"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added electron as a dev dependency


let plugins = [
new CopyWebpackPlugin([{ from: './public' }]),
new CopyWebpackPlugin([{ from: './electron-entry.js' }, { from: './package.json' }]),
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 9 was added to copy the electron entrypoint script and package.json into dist

"test": "grommet check",
"dev-server": "nodemon ./src/server/dev",
"dev": "cross-env NODE_ENV=development grommet pack",
"dist": "cross-env NODE_ENV=production grommet pack && npm run dist-server",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed dist to include running babel on the server source

"sass-lint": "^1.10.2",
"sass-loader": "^6.0.3",
"webpack": "^2.2.1",
"electron": "^1.6.2"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added electron as a dev dependency

<meta name="mobile-web-app-capable" content="yes">
<link rel="shortcut icon" type="image/png" href="/img/shortcut-icon.png" />
<link rel="apple-touch-icon" sizes="196x196" type="image/png" href="/img/mobile-app-icon.png">
<link rel="stylesheet" type="text/css" href="index.css">
Copy link
Author

@clarktlaugh clarktlaugh Apr 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/ had to be removed from index.css

}, 100)
</script>
</div>
<script async src="index.js"></script>
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/ had to be removed from index.js

if (window.location.protocol === 'https:') {
protocol = 'wss:';
}
const host = 'localhost:8102';
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changed to not try to detect the host the app is running on, because it needs to always talk to localhost since the server is running within Electron/node

console.log(__dirname);

// and load the index.html of the app.
mainWindow.loadURL("http://localhost:8102")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was changed to point to the server running within the app

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a way to read the port from a variable?

// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.

require("./server/server");
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was added to start the server

@clarktlaugh
Copy link
Author

@tracybarmore -- is there anything else I can be doing to help here? There hasn't really been any activity since mid-April.

The changes required to enable this to work for generating an Electron app are extremely minor, but they are in some of the template files, which require completely duplicating all of them (the reason this PR has 72 files). In the comments above, I tried to point out exactly what all of the necessary changes were, and it's only about 15 lines of changes / new code. I do think that having an entirely-new template for this adds a lot of duplication that just isn't necessary, so I could see how that might necessitate a change in the way the CLI handles templates.

One thought I had was to be able to have a common set of template files, then be able to just overwrite a few of them (so 'electron-app' would just use all files from 'app' and then carry around a patch or complete replacement for the changed files. Same for 'electron-basic' and 'basic').

@@ -0,0 +1,65 @@
const electron = require('electron')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in grommet we follow the convention to add a semi-colon at the end of each line. Do you mind following that?

// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in grommet we follow the convention to use undefined instead of null. Do you mind updating that?

@alansouzati
Copy link
Contributor

What if we just start with the electron template that is just the basic structure (similar to your electron-basic)? I would stay away from adding a lot of different templates for electron.

I really like the proposal here. But I believe the main goal of this template is to show how to use grommet + electron. There are lot of things in the app template that will deviate the attention more to that than to understand what it takes to run grommet with electron. Hopefully it makes sense.

Thanks for your contribution and sorry for taking such a long time to get back to you on this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants