From b065e8d02d686abe89679c0ef5a53a21aa64fc8c Mon Sep 17 00:00:00 2001 From: Sergio Rubio Date: Thu, 28 Sep 2017 19:10:09 +0200 Subject: [PATCH] Scripts to build "native" apps Use nativefier to wrap the beehive binary and build a desktop app. --- script/build-app | 26 +++++++++++++++ script/build-app-darwin | 70 +++++++++++++++++++++++++++++++++++++++++ script/build-icns | 30 ++++++++++++++++++ 3 files changed, 126 insertions(+) create mode 100644 script/build-app create mode 100644 script/build-app-darwin create mode 100644 script/build-icns diff --git a/script/build-app b/script/build-app new file mode 100644 index 00000000..34a411aa --- /dev/null +++ b/script/build-app @@ -0,0 +1,26 @@ +#!/bin/bash +# Build "native" desktop app using nativefier +# https://github.com/jiahaog/nativefier +set -e + +if !which nativefier >/dev/null 2>&1; then + echo "nativefier not found!" >&2 + echo "npm install -g nativifier" >&2 + exit 1 +fi + +export BASE_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")/../" && pwd )" +export OS_NAME=$(node -e "console.log(os.platform())") +export OS_ARCH=$(node -e "console.log(os.arch())") + +if [ ! -f $BASE_PATH/script/build-app-$OS_NAME ]; then + echo "$OS_NAME is not currently supported." >&2 + exit 1 +fi + +if [ ! -f beehive ]; then + echo "Run 'make embed' first." >&2 + exit 1 +fi + +$BASE_PATH/script/build-app-$OS_NAME diff --git a/script/build-app-darwin b/script/build-app-darwin new file mode 100644 index 00000000..5b81b14c --- /dev/null +++ b/script/build-app-darwin @@ -0,0 +1,70 @@ +#!/bin/bash +set -e + +cleanup_macos() { + if [ -f "$icns_file" ]; then + rm -f $icns_file + fi +} + +trap cleanup_macos EXIT + +ELECTRON_VERSION=${ELECTRON_VERSION:-1.6.14} +BIN_PATH=build/app/Beehive-$OS_NAME-$OS_ARCH/Beehive.app/Contents/MacOS +RES_PATH=build/app/Beehive-$OS_NAME-$OS_ARCH/Beehive.app/Contents/Resources +icns_file=$($BASE_PATH/script/build-icns) +nativefier -e $ELECTRON_VERSION --icon $icns_file --name Beehive http://localhost:8181 $BASE_PATH/build/app +mkdir -p $RES_PATH +cp beehive $BIN_PATH/beehived +chmod +x $BIN_PATH/beehived +mv $BIN_PATH/Beehive $BIN_PATH/Beehive.bin + +cat > $BIN_PATH/Beehive << "EOF" +#!/bin/bash +set -e + +BASE_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd )" +RES_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")/../Resources" && pwd )" +LIBRARY_PATH=$HOME/Library/Application\ Support/Beehive +LA_PLIST=$HOME/Library/LaunchAgents/com.github.muesli.beehive.plist +mkdir -p "$LIBRARY_PATH" +cp $RES_PATH/launchagent.plist $LA_PLIST +sed -i '' s/@@user@@/$USER/ $LA_PLIST +sed -i '' s,@@bin_path@@,$BASE_PATH/beehived, $LA_PLIST +launchctl load $LA_PLIST +# Wait a bit for beehived to be ready +for i in $(seq 20); do + s=$(curl -s -o /dev/null -w "%{http_code}" localhost:8181) + [ "$s" = 200 ] && break + sleep 0.1 +done +$BASE_PATH/Beehive.bin +EOF +chmod +x build/app/Beehive-$OS_NAME-$OS_ARCH/Beehive.app/Contents/MacOS/Beehive + +cat > $RES_PATH/launchagent.plist << "EOF" + + + + + Label + com.muesli.beehive + + ProgramArguments + + @@bin_path@@ + --config + /Users/@@user@@/Library/Application Support/Beehive/beehive.conf + + + KeepAlive + + + LowPriorityIO + + + ProcessType + Background + + +EOF diff --git a/script/build-icns b/script/build-icns new file mode 100644 index 00000000..f09632a1 --- /dev/null +++ b/script/build-icns @@ -0,0 +1,30 @@ +#!/bin/bash +set -e + +tmpd=$TMPDIR/beehive.iconset +icns=$TMPDIR/beehive.icns +logfile=$TMPDIR/build-icns.log + +cleanup() { + rm -rf $tmpd + rm -f $logfile +} + +trap cleanup EXIT + +{ + mkdir $tmpd + sips -z 16 16 assets/logo.png --out $tmpd/icon_16x16.png + sips -z 32 32 assets/logo.png --out $tmpd/icon_16x16@2x.png + sips -z 32 32 assets/logo.png --out $tmpd/icon_32x32.png + sips -z 64 64 assets/logo.png --out $tmpd/icon_32x32@2x.png + sips -z 128 128 assets/logo.png --out $tmpd/icon_128x128.png + sips -z 256 256 assets/logo.png --out $tmpd/icon_128x128@2x.png + sips -z 256 256 assets/logo.png --out $tmpd/icon_256x256.png + sips -z 512 512 assets/logo.png --out $tmpd/icon_256x256@2x.png + sips -z 512 512 assets/logo.png --out $tmpd/icon_512x512.png + cp assets/logo.png $tmpd/icon_512x512@2x.png + iconutil -c icns $tmpd +} > $logfile 2>&1 + +echo $icns