Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update doc and scripts for electron app #4855

Merged
merged 2 commits into from
Jan 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 58 additions & 14 deletions electron/README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,71 @@
# Stratos Desktop

From the top-level Stratos folder:
Stratos Desktop packages Stratos into a Desktop application using the Electron framework.

- Install dependencies with `npm install`
- Change to the `electron folder` with `cd electron`
- Install dependencies for the electron UI with `npm install`
- Run the Electron app with `./run.sh all`
## Quick Start

> Note this builds both the frontend and backend and run the app
From the top-level folder, run:

- To build only the front end before running, use `./run.sh fe`
- To build only the back end before running, use `./run.sh be`
- To run without building either the the back end or front end, use `./run.sh`
```
cd electron
./package.sh
```

This will:

You can also run the UI with `ng serve` from the top-level folder and then start electron with:
- Install the npm dependencies for Stratos and the Electron App if needed
- Build the Stratos frontend and backend if needed
- Package the Stratos frontend and backend together with the Electron app

On a fresh checkout, this will take some time to run - at the end you'll see some log messages indicating where the packaged outputs have been written.

For Mac OS, you'll get `.app` and `.dmg` files created. The `.app` file can be opened from a terminal with the `open` command.

> Note, the Stratos back-end is written in go and currently we only build for the current architecture that you are running on - it should be possible with some extra scripts to build
the desktop application for Mac, Windows and Linux in one-go.

For more information on other scripts you can run for different build/dev scenarios, so below.

## Overview

This section provides a short overview on what goes on when Stratos runs as a desktop application.

Stratos consists of a go backend and an Angular front-end. The Angular frontend is compiled into a set of static files. The go back-end serves up the static files in addition to providing the backend API for Stratos. The frontend resources reside in the `dist` folder.

For the desktop build, we build the Stratos backend including an extra plugin `desktop` (in `src/jetstream/plugins/desktop`). This adds support for endpoints from local configuration. The frontend is also build including the additional `desktop-extensions` extension (in `src/frontend/packages/desltop-extensions`). This extension also includes a slightly modified theme and some small UI tweaks for the desktop use-case.

The Electron wrapper is in the `electron` folder - the main file being the `index.js` file. Some of the things this does:

- Finds a free port and runs the go backend, listening on that port
- Creates a window and loads the UI from the backend
- Sets up file watchers on the local config files that are read for local endpoint information and sends a notification to the Stratos app when these are changed, so that it can update the endpoints

## Scripts

From the `electron` folder:


To run the Desktop application:

- `./run.sh all` - This will build both the backend and frontend and then run the app
- `./run.sh fe` - This will build frontend and then run the app
- `./run.sh be` - This will build the backend and then run the app

> Note: You can also use `all` and `fe` and `be` with the `build.sh` script - when run without any arg, the build script will only build the frontend and backend if they have not previously been built


## Frontend Development

You can run the frontend in development mode, from the top-level folder with `ng serve` just as you would normally.

You can then run the desktop application using:

`./run.sh dev`

to load the UI from `https://127.0.0.1:4200`
This will start the backend and launch the Electron application - but it will load the UI from `https://127.0.0.1:4200` rather than from the built version that the backend serves.

# Packaging
This allows you to make changes to the frontend code and have the application refresh within the webview, just as it would for regular development.

Packaging as a DMG file for Mac:
## Packaging

`./package.sh all`
Electron Forge is used for packaging.
15 changes: 11 additions & 4 deletions electron/build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#!/usr/bin/env bash

# Colours
CYAN="\033[96m"
YELLOW="\033[93m"
RED="\033[91m"
RESET="\033[0m"
BOLD="\033[1m"

# Script folder
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
STRATOS="`cd "${DIR}/..";pwd`"
Expand Down Expand Up @@ -27,7 +34,7 @@ fi
pushd ${DIR} > /dev/null
# Checks for fresh run on checkout
if [ ! -d "./node_modules" ]; then
echo "Installing node modules ..."
echo -e "${CYAN}${BOLD}Installing node modules for Electron${RESET}"
npm install
fi
popd > /dev/null
Expand All @@ -37,18 +44,18 @@ pushd ${STRATOS} > /dev/null
cat ./package.json | jq -r .version > ${DIR}/version

if [ ! -d "./node_modules" ]; then
echo "Installing node modules in top-level folder ..."
echo -e "${CYAN}${BOLD}Installing node modules for front-end ...${RESET}"
npm install
fi

if [ "$1" != "be" ] && [ ! -d "./dist" ]; then
BUILD_FRONTEND=true
echo "Frontend has not been built - will build"
echo -e "${CYAN}${BOLD}Frontend has not been built - will build${RESET}"
fi

if [ ! -f "./src/jetstream/jetstream" ]; then
BUILD_BACKEND=true
echo "Backend has not been built - will build"
echo -e "${CYAN}${BOLD}Backend has not been built - will build${RESET}"
fi

if [ "$BUILD_FRONTEND" == "true" ]; then
Expand Down
2 changes: 1 addition & 1 deletion electron/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions electron/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"name": "Stratos",
"version": "4.0.0",
"version": "4.4.0",
"main": "index.js",
"description": "Stratos Electron",
"license" : "Apache-2.0",
"scripts": {
"ng": "ng",
"start": "electron-forge start",
Expand Down Expand Up @@ -48,9 +50,7 @@
},
{
"name": "@electron-forge/maker-zip",
"platforms": [
"darwin"
]
"platforms": []
},
{
"name": "@electron-forge/maker-deb",
Expand All @@ -68,7 +68,7 @@
}
}
],
"publishers": [
"_publishers": [
{
"name": "@electron-forge/publisher-github",
"config": {
Expand Down
32 changes: 31 additions & 1 deletion electron/package.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
#!/usr/bin/env bash

# Colours
CYAN="\033[96m"
YELLOW="\033[93m"
RED="\033[91m"
RESET="\033[0m"
BOLD="\033[1m"
NORMAL="\033[21m"

echo -e "${CYAN}${BOLD}=========================\nPackaging Stratos Desktop\n=========================\n${RESET}"

echo -e "${YELLOW}Note: This will only package for your current architecture and OS${RESET}"

OS="$(uname -s)"

# Script folder
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
STRATOS="`cd "${DIR}/..";pwd`"
Expand All @@ -8,11 +22,27 @@ source "${DIR}/build.sh"

pushd ${DIR} > /dev/null
rm -rf dist/*es5*
VERSION=$(cat ./package.json | jq -r .version)
popd > /dev/null

npm run package
#npm run package
npm run epublish

# Mac - move the app to the Applications folder
if [ "$1" == "-i" ]; then
mv ./out/Stratos-darwin-x64/Stratos.app /Applications
fi

if [ "${OS}" == "Darwin" ]; then
DMG="Stratos-${VERSION}.dmg"
if [ -d "${DIR}/out/Stratos-darwin-x64" ]; then
echo -e "${YELLOW}${BOLD}Mac App${NORMAL} is in ${BOLD}${DIR}/out/Stratos-darwin-x64/Stratos.app${RESET}"
echo -e "${CYAN}You can run the app with:"
echo -e "${YELLOW}open ${DIR}/out/Stratos-darwin-x64/Stratos.app${RESET}"
echo ""
fi

if [ -f "${DIR}/out/make/${DMG}" ]; then
echo -e "${YELLOW}${BOLD}Mac DMG${NORMAL} is in: ${BOLD}${DIR}/out/make/${DMG}${RESET}"
fi
fi