Skip to content

Instantly share code, notes, and snippets.

@shvchk
Last active June 5, 2023 23:43
Show Gist options
  • 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
@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