Open jessegreenberg opened 4 weeks ago
Sounds like Electron might be the way to go here. We've used it in the past and we currently use it for other PhET projects I believe (was there a desktop app?). Either way, it sounds the easiest and has certainly worked before.
Any ideas on how we deal with .env file? Should we keep it as a thing that needs to be edited inside of the installation directory or would there need to be any key-value pairs transformed into settings inside the running Paper Playground itself?
We can auto-deploy from e.g., the main
branch or just manually release when we feel like it. Can start somewhere before 1.0.0 and set to 1.0.0 at the end of the grant work?
Release Interface on GitHub:
GPT-generated suggested GitHub Actions workflow:
Any ideas on how we deal with .env file
Good question. I think we have options, what is the ideal experience?
1) Just leave as is. Local build does not support ChatGPT and only runs on local file system. 2) As you suggested, let them edit somehow. If the .env can't be usesd then another config file. 3) Add a UI that lets them enter in keys for the AI or DB usage, and access to restricted files. I have seen projects do this, but it could raise security questions - I wouldn't want to enter my keys if I were a developer finding this project for the first time.
Something else?
Yeah, just to note what we currently have as possible variables:
DATABASE_URL=
STORAGE_TYPE=
ALLOW_ACCESS_TO_RESTRICTED_FILES=
OPENAI_API_KEY=
PORT=
The restricted file access should probably be revisited as well, since it is very specific to our database. I'll make another issue for that.
Is it obvious what other config files are for option 2 (json, yml)? I know Minecraft uses json settings/preferences. I think probably the hidden nature of .env makes it most difficult. Makes sense for some of those keys, but as long as it doesn't go to git (.gitignore settings.json or something), perhaps we are ok?
After a quick search it seems possible to use a config file that the electron app can read without needing to rebuild it, and it seems like we can use whatever format we want.
Taking some notes on changes necessary (will continue to edit):
engine
lines from package.json.
"engines": {
"node": "9.3.x",
"npm": "5.6.x"
}
Hopefully this doesn;t break something else.
npx electron-forge import
- Failed the first time and had to run it from terminal with admin priveleges. Eventually it succeeded but made significant automated changes to the project structure."main": "main.js",
"scripts": {
"start": "electron-forge start",
"package": "electron-forge package",
"make": "electron-forge make"
},
"config": {
"forge": {
"packagerConfig": {},
"makers": [
{
"name": "@electron-forge/maker-squirrel",
"config": {}
},
{
"name": "@electron-forge/maker-zip",
"platforms": [
"darwin"
]
},
{
"name": "@electron-forge/maker-deb",
"config": {}
},
{
"name": "@electron-forge/maker-rpm",
"config": {}
}
]
}
}
start-forge
because we already use start
to start the local server."build": "webpack",
. The command got stuck at one point and I had to hit 'enter' to get it to continue (this is a general Windows thing that I have seen on various tasks but it still bit me here).npm run start-forge
seems to just work!! It opens Paper Playground index in an Electron window. Using "Camera", "Canvas" and "Display opens each of those in a new Electron window. It is able to use the remote database, and each Electron window is able to communicate over localStorage - I can successfully add debug programs and see results on the Display page 🥳 npm run package
seems to create win32 build, I can enter the directory and launch electron windows by doubel clicking out/paperprograms-win32-x64/paperprograms.exe
npm run make
seems stuck after ~5 minutes.npm prune
, no luck."config": {
"forge": {
"packagerConfig": {
"asar": true
},
HOWEVER, that zips everything into a single file. One drawback with that is that it is not possible to have a configuration file for the user to edit values (like OpenAI keys, or database configurations).
I have been having a heck of a time packaging the server-side code for Electron. As a stepping stone I have been trying to bundle the server code with webpack so we have a single file to run within Electron. The node_modules used by this project have made that very difficult. But finally made a breakthrough today, I can bundle the server-side code with webpack if I remove this line:
// app.use( require( 'heroku-ssl-redirect' )( [ 'production' ] ) );
Seems totally safe to remove, and it looks like this is just for an old heroku deployment of the legacy project.
Next is configuring the full-stack electron app to use bundled front end/back end code and start a server from its entry point.
OK, I have a package that I can run from the root paper-land directory like this:
./out/paperprograms-win32-x64/paperprograms.exe
That is a great step forward!
However, it does not work if I try to run paperprograms.exe if I run from paperprograms-win32-x64. Error is
stderr: Error copying default data: Error: ENOENT: no such file or directory, scandir 'C:\Users\Jesse\Documents\Development\phetsims\paper-land\out\paperprograms-win32-x64\resources\app\server-dist\default-data
A couple of problems to solve
1) Relative path to default-data is a problem.
2) We will need to package the contents of www/ directory into the electron build so that the bundled server can serve relevant files from within the package.
3) The .env file will need to be packaged. I am not sure yet if we will be able to support configurations without rebuilding because of "asar": true
4) There will likely be other problems with relative paths in the existing code.
5) There will be MacOS specific problems to solve (there have been a few Windows specific things already).
@brettfiedler FYI, I am about 9 hours into this - I have made progress but it is difficult to say how much more time this will take.
We want to make it as easy as possible to run paper playground. This means packaging it in a way that it can be launched without using the command line. Putting some notes here now from a quick search on how this is done.
pkg
to package the app.I believe Electron with electron-forge (to package into a .exe and .dmg) is the most promising. We also have a little experience with it since we used it briefly for quadrilateral/haptics exploration many years ago.
Apparently, once we have a .dmg and .exe, we can publish it as a release on github. @brettfiedler may already have experience with that.
@brettfiedler does electron seem reasonable to you? Are you aware of any other options you would like us to explore?
I am putting the steps I got from ChatGPT here for future reference. It shouldn't require a lot of code changes, but I do expect troubleshooting and fiddling to get it right.