Skip to content

Commit 9f51e2c

Browse files
committed
Auto-update & build process with NSIS for windows
Amalgamate the electron build packaging into one script. Use update_base_url so we can compute the actual URL in the script for windows (because we need to put it in the build) and at runtime for mac os.
1 parent 2930a94 commit 9f51e2c

6 files changed

Lines changed: 154 additions & 78 deletions

File tree

‎README.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ You can configure the app by copying `vector/config.sample.json` to
107107
valid location on this network. This is used as a hint to the user to indicate
108108
when a valid location has been entered so it's not necessary for this to be
109109
exactly correct. Optional.
110+
1. `update_base_url` (electron app only): HTTPS URL to a web server to download
111+
updates from. This should be the path to the directory containing `install`
112+
and `update`.
110113

111114
Running as a Desktop app
112115
========================

‎electron/src/electron-main.js‎

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ function pollForUpdates() {
9999
}
100100
}
101101

102-
function startAutoUpdate(update_url) {
103-
if (update_url.slice(-1) !== '/') {
104-
update_url = update_url + '/';
102+
function startAutoUpdate() {
103+
if (process.platform != 'darwin' && process.platform != 'win32') {
104+
return;
105105
}
106106
try {
107107
// Since writing, the electron auto update process has changed from being
@@ -111,7 +111,19 @@ function startAutoUpdate(update_url) {
111111
// package.json. There is no autoupdate for Linux: it's expected that
112112
// the distro will provide it.
113113
if (process.platform == 'darwin') {
114-
autoUpdater.setFeedURL(update_base_url + 'update/macos/');
114+
const update_base_url = vectorConfig.update_base_url;
115+
if (!update_base_url) {
116+
console.log("No update_base_url: disabling auto-update");
117+
return;
118+
}
119+
if (update_base_url.slice(-1) !== '/') {
120+
update_base_url = update_url + '/';
121+
}
122+
const update_url = update_base_url + 'update/macos/tmp/';
123+
console.log("Starting auto update with URL: " + update_url);
124+
autoUpdater.setFeedURL(update_url);
125+
} else {
126+
console.log("Starting auto update with baked-in URL");
115127
}
116128
// We check for updates ourselves rather than using 'updater' because we need to
117129
// do it in the main process (and we don't really need to check every 10 minutes:
@@ -138,12 +150,7 @@ process.on('uncaughtException', function (error) {
138150
electron.ipcMain.on('install_update', installUpdate);
139151

140152
electron.app.on('ready', () => {
141-
if (vectorConfig.update_url) {
142-
console.log("Starting auto update with URL: " + vectorConfig.update_url);
143-
startAutoUpdate(vectorConfig.update_url);
144-
} else {
145-
console.log("No update_url is defined: auto update is disabled");
146-
}
153+
startAutoUpdate();
147154

148155
mainWindow = new electron.BrowserWindow({
149156
icon: `${__dirname}/../img/riot.ico`,

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"build:compile": "babel --source-maps -d lib src",
3636
"build:bundle": "NODE_ENV=production webpack -p --progress",
3737
"build:bundle:dev": "webpack --optimize-occurence-order --progress",
38-
"build:electron": "rimraf electron/dist && npm run clean && npm run build && build -wml --ia32 --x64 && scripts/check-electron.sh",
38+
"build:electron": "rimraf electron/dist && npm run clean && npm run build && build -wml --ia32 --x64",
3939
"build": "node scripts/babelcheck.js && npm run build:res && npm run build:config && npm run build:emojione && npm run build:css && npm run build:bundle",
4040
"build:dev": "node scripts/babelcheck.js && npm run build:res && npm run build:config && npm run build:emojione && npm run build:css && npm run build:bundle:dev",
4141
"dist": "scripts/package.sh",

‎scripts/check-electron.sh‎

Lines changed: 0 additions & 13 deletions
This file was deleted.

‎scripts/electron-dist.sh‎

Lines changed: 0 additions & 54 deletions
This file was deleted.

‎scripts/electron-package.sh‎

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
usage() {
6+
echo "Usage: $0 -v <version> -c <config file> [-n]"
7+
echo
8+
echo "version: commit-ish to check out and build"
9+
echo "config file: a path to a json config file to"
10+
echo "ship with the build. In addition, update_base_url:"
11+
echo "from this file is used to set up auto-update."
12+
echo "-n: build with no config file."
13+
echo
14+
echo "Values may also be passed as environment variables"
15+
}
16+
17+
conffile=
18+
version=
19+
skipcfg=0
20+
while getopts "c:v:n" opt; do
21+
case $opt in
22+
c)
23+
conffile=$OPTARG
24+
;;
25+
v)
26+
version=$OPTARG
27+
;;
28+
n)
29+
skipcfg=1
30+
;;
31+
\?)
32+
echo "Invalid option: -$OPTARG" >&2
33+
usage
34+
exit
35+
;;
36+
esac
37+
done
38+
39+
if [ -z "$version" ]; then
40+
echo "No version supplied"
41+
usage
42+
exit
43+
fi
44+
45+
if [ -z "$conffile" ] && [ "$skipcfg" = 0 ]; then
46+
echo "No config file given. Use -c to supply a config file or"
47+
echo "-n to build with no config file (and no auto update)."
48+
exit
49+
fi
50+
51+
if [ -n "$conffile" ]; then
52+
update_base_url=`jq -r .update_base_url $conffile`
53+
54+
if [ -z "$update_base_url" ]; then
55+
echo "No update URL supplied. Use update_base_url: null if you really"
56+
echo "want a build with no auto-update."
57+
usage
58+
exit
59+
fi
60+
# Make sure the base URL ends in a slash if it doesn't already
61+
update_base_url=`echo $update_base_url | sed -e 's#\([^\/]\)$#\1\/#'`
62+
fi
63+
64+
if [ ! -f package.json ]; then
65+
echo "No package.json found. This script must be run from"
66+
echo "the vector-web directory."
67+
exit
68+
fi
69+
70+
echo "Building $version using Update base URL $update_base_url"
71+
72+
projdir=`pwd`
73+
builddir=`mktemp -d 2>/dev/null || mktemp -d -t 'buildtmp'`
74+
pushd "$builddir"
75+
git clone "$projdir" .
76+
git checkout "$version"
77+
78+
if [ -n "$conffile" ]; then
79+
popd
80+
cp "$conffile" "$builddir/"
81+
pushd "$builddir"
82+
fi
83+
84+
if [ "$update_base_url" != "null" ]; then
85+
# Inject a 'publish' configuration into the package.json. This is what
86+
# electron-builder needs for auto-update on windows but we don't want to
87+
# keep it in the package.json as we don't want everyone cloning the source
88+
# and building it for themselves to get our auto-update URL.
89+
update_url=$update_base_url/install/win32/
90+
jq '.build.publish.provider="generic"' package.json \
91+
| jq '.build.publish.url="$update_url"' \
92+
> package.json.tmp
93+
mv package.json.tmp package.json
94+
fi
95+
96+
npm install
97+
npm run build:electron
98+
99+
popd
100+
101+
distdir="$builddir/electron/dist"
102+
pubdir="$projdir/electron/pub"
103+
rm -r "$pubdir" || true
104+
mkdir -p "$pubdir"
105+
106+
# figure out what version this build is known as
107+
# (since we could be building from a branch or indeed
108+
# any commit-ish, not just a version tag)
109+
vername=`python -c 'import yaml; import sys; print yaml.load(sys.stdin)["version"]' < $builddir/electron/dist/latest.yml`
110+
111+
# Install packages: what the user downloads the first time,
112+
# (DMGs for mac, exe installer for windows)
113+
mkdir -p "$pubdir/install/macos"
114+
cp $distdir/mac/*.dmg "$pubdir/install/macos/"
115+
116+
mkdir -p "$pubdir/install/win32/"
117+
cp $distdir/*.exe "$pubdir/install/win32/"
118+
cp $distdir/latest.yml "$pubdir/install/win32/"
119+
120+
# Packages for auto-update on mac (Windows (NSIS) uses the installer exe)
121+
mkdir -p "$pubdir/update/macos"
122+
cp $distdir/mac/*.zip "$pubdir/update/macos/"
123+
echo "$ver" > "$pubdir/update/macos/latest"
124+
125+
# Move the debs to the main project dir's dist folder
126+
rm -r "$projdir/electron/dist" || true
127+
mkdir -p "$projdir/electron/dist"
128+
cp $distdir/*.deb "$projdir/electron/dist/"
129+
130+
rm -rf "$builddir"
131+
132+
echo "Riot Desktop $vername is ready to go in $pubdir: this directory can be hosted on your web server."
133+
echo "deb archives are in electron/dist/ - these should be added into your debian repository"

0 commit comments

Comments
 (0)