Skip to content

Instantly share code, notes, and snippets.

@shvchk
Last active June 5, 2023 23:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save shvchk/c5ef39c52024758da4f6fdaed154cd6f to your computer and use it in GitHub Desktop.
Save shvchk/c5ef39c52024758da4f6fdaed154cd6f to your computer and use it in GitHub Desktop.
nativefier wrapper removing bundled electron to use shared / system-wide elecron
#! /usr/bin/env bash
# To use apps created with this script you will need Electron installed e.g. with npm install -g electron
set -e
if [ -z "$1" ] || [ -z "$2" ]; then
echo "Please specify app name and URL. E.g. $0 Example https://example.com"
exit 1
fi
name="$1"
url="$2"
if [ -d "$name" ]; then
echo "Error: $name already exists, please delete or rename the directory"
exit 1
fi
nativefier --disable-dev-tools --single-instance --user-agent "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/999 Safari/537.36" -n "$name" "$url" "$name"
suf=$(head /dev/urandom | tr -d -C a-z0-9 | head -c 8)
tmp_dir="${name}_${suf}"
mv "$name" "$tmp_dir"
subdirs=("$tmp_dir"/*)
if [ ${#subdirs[@]} -eq 1 ]; then
app_dir="${subdirs[0]}"
mv "${app_dir}/resources/app" "$name"
rm -rf "$tmp_dir"
echo "Done. Now you can launch this app with electron $(readlink -f $name)"
else
echo "Something went wrong"
mv "$tmp_dir" "$name"
fi
@allo-
Copy link

allo- commented Dec 11, 2019

You can create a temporary directory by using mktemp. This is more simple and robust against name collisions.

@voltechs
Copy link

Got an error. Tried a simple GitHub app.

$ lean-nativefier GitHub https://github.com

Preparing Electron app...

Converting icons...

Packaging... This will take a few seconds, maybe minutes if the requested Electron isn't cached yet...
Packaging app for platform darwin x64 using electron v9.1.0

Finalizing build...
App built to GitHub/GitHub-darwin-x64
tr: Illegal byte sequence
mv: rename GitHub_/GitHub-darwin-x64/resources/app to GitHub: No such file or directory

@shvchk
Copy link
Author

shvchk commented Jul 23, 2020

@voltechs I've updated the script, try it. Never tested on MacOS, which you seem to be using. I've used this tr man page: https://ss64.com/osx/tr.html — hope it's correct.

@voltechs
Copy link

Ah, I see what you're trying to do here (I didn't spend a lot of time digging into it earlier). the -C doesn't help on mac, keep it as -dc. Here's a snippet that works for me. Maybe it works for you too and or there's a middle ground?

suf=$(cat /dev/urandom | LC_CTYPE=C tr -dc 'a-z0-9' | fold -w 8 | head -n 1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment