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

Script to build "native" apps #142

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
33 changes: 33 additions & 0 deletions script/build-app
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/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 nativefier" >&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())")
export ELECTRON_VERSION=${ELECTRON_VERSION:-7.1.1}

if [ "$OS_NAME" = "linux" ] && ! which snapcraft >/dev/null; then
echo "snapcraft not available!" >&2
echo "we need snapcrat to build the snap package" >&2
exit 1
fi

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
69 changes: 69 additions & 0 deletions script/build-app-darwin
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/bash
set -e

cleanup_macos() {
if [ -f "$icns_file" ]; then
rm -f $icns_file
fi
}

trap cleanup_macos EXIT

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"
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.muesli.beehive</string>

<key>ProgramArguments</key>
<array>
<string>@@bin_path@@</string>
<string>--config</string>
<string>/Users/@@user@@/Library/Application Support/Beehive/beehive.conf</string>
</array>

<key>KeepAlive</key>
<true/>

<key>LowPriorityIO</key>
<true/>

<key>ProcessType</key>
<string>Background</string>
</dict>
</plist>
EOF
32 changes: 32 additions & 0 deletions script/build-app-linux
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash
set -e

cleanup_linux() {
true
}

trap cleanup_linux EXIT

nativefier -e $ELECTRON_VERSION --icon $BASE_PATH/assets/logo.png --name Beehive http://localhost:8181 build/app

mkdir -p build/app
cp beehive build/app
chmod +x build/app/beehive
cat > build/app/beehive-linux-x64/beehive.wrapper << "EOF"
#!/bin/bash

export BASE_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")/../" && pwd )"

# Start the daemon
$BASE_PATH/beehive --config $SNAP_USER_DATA/beehive.conf &
bpid=$!
finish() {
[[ -z "$bpid" ]] || kill $bpid > /dev/null 2>&1
}
trap finish EXIT

# Start the GUI shell
$BASE_PATH/beehive-linux-x64/beehive
EOF
chmod +x build/app/beehive-linux-x64/beehive.wrapper
snapcraft
30 changes: 30 additions & 0 deletions script/build-icns
Original file line number Diff line number Diff line change
@@ -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/[email protected]
sips -z 32 32 assets/logo.png --out $tmpd/icon_32x32.png
sips -z 64 64 assets/logo.png --out $tmpd/[email protected]
sips -z 128 128 assets/logo.png --out $tmpd/icon_128x128.png
sips -z 256 256 assets/logo.png --out $tmpd/[email protected]
sips -z 256 256 assets/logo.png --out $tmpd/icon_256x256.png
sips -z 512 512 assets/logo.png --out $tmpd/[email protected]
sips -z 512 512 assets/logo.png --out $tmpd/icon_512x512.png
cp assets/logo.png $tmpd/[email protected]
iconutil -c icns $tmpd
} > $logfile 2>&1

echo $icns
10 changes: 10 additions & 0 deletions snap/gui/beehive.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Desktop Entry]
Name=Beehive
Comment=Beehive
Exec=beehive
Terminal=false
Type=Application
Icon=${SNAP}/meta/gui/icon.png
StartupWMClass=beehive
X-Desktop-File-Install-Version=0.24

Binary file added snap/gui/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 47 additions & 0 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: beehive # you probably want to 'snapcraft register <name>'
base: core18 # the base snap is the execution environment for this snap
version: '0.4' # just for humans, typically '1.2+git' or '1.3.2'
summary: A flexible event/agent & automation system with lots of bees 🐝
description: |
Beehive is an event and agent system, which allows you to create your own
agents that perform automated tasks triggered by events and filters.
It is modular, flexible and really easy to extend for anyone. It has
modules (we call them Hives), so it can interface with, talk to, or retrieve
information from Twitter, Tumblr, Email, IRC, Jabber, RSS, Jenkins,
Hue - to name just a few.

grade: stable # must be 'stable' to release into candidate/stable channels
confinement: classic # use 'strict' once you have the right plugs and slots
apps:
beehive:
command: bin/beehive
extensions: [gnome-3-28]
parts:
beehive:
plugin: dump
source: build/app
organize:
beehive-linux-x64/beehive.wrapper: bin/beehive
stage-packages:
- libx11-6
- libxcb-xtest0
- libx11-xcb1
- libnotify4
- libappindicator1
- libxtst6
- libnss3
- libxss1
- fontconfig-config
- gconf2
- libasound2
- pulseaudio
- libatk-bridge2.0-0
- libatspi2.0-0
- libcairo-gobject2
- libepoxy0
- libgtk-3-0
- libwayland-client0
- libwayland-cursor0
- libwayland-egl1
- libxkbcommon0