-
Notifications
You must be signed in to change notification settings - Fork 18
Initial version of Electron versions of basic, app templates #31
base: master
Are you sure you want to change the base?
Conversation
Wow, nice one! |
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? |
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' }, |
There was a problem hiding this comment.
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"> |
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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' }]), |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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"> |
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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
@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') |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
What if we just start with the 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 Thanks for your contribution and sorry for taking such a long time to get back to you on this. |
Implements two new templates:
which are versions of the original 'app' and 'basic' templates that work in Electron.