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

Support installation in Flatpaks. #70

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
46 changes: 34 additions & 12 deletions installers/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ sedEscape() {
run() {
set -e

XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}/tridactyl"
XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}/tridactyl"
HOME="${HOME:-$(echo ~)}"

# Decide where to put the manifest based on OS
# Get OSTYPE from bash if it's installed. If it's not, then this will
Expand Down Expand Up @@ -58,14 +57,41 @@ run() {
native_loc="https://github.com/tridactyl/native_messenger/releases/download/$native_version/native_main-$binary_suffix"
fi

mkdir -p "$manifest_home" "$XDG_DATA_HOME"
install_to "$manifest_home" "$manifest_home"

manifest_file="$manifest_home/tridactyl.json"
native_file="$XDG_DATA_HOME/native_main"
for flatpak_dir in ~/.var/app/*/.mozilla; do
Copy link
Member

@bovine3dom bovine3dom Nov 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit nervous about running this on OSX - could you set a flag around line 36 to skip it on them?

[ -d "$flatpak_dir" ] || continue
echo
echo "Detected flatpak installation in $flatpak_dir"
install_to "$flatpak_dir/native-messaging-hosts/" "$HOME/.mozilla/native-messaging-hosts/"
done

echo "Installing manifest here: $manifest_home"
echo "Installing script here: XDG_DATA_HOME: $XDG_DATA_HOME"
echo
echo "Successfully installed Tridactyl native messenger!"
echo "Run ':native' in Firefox to check."
}

# install_to takes two arguments:
# 1. The path to the manifest home as seen by the install script.
# 2. The path to the manifest home as seen by Firefox.
#
# For regular Firefox installations, these are the same. They are different in
# the case of sandboxed installations (like Flatpak).
install_to() {
manifest_home_on_host="$1"
manifest_home_in_sandbox="$2"

mkdir -p "$manifest_home_on_host"

manifest_file="$manifest_home_on_host/tridactyl.json"
# For Flatpak installations, we must install the native binary inside
# `~/.mozilla/native-messaging-hosts` as well, because everything outside
# of `~/.mozilla` is wiped when restarted.
native_binary_name="tridactyl_native_main"
native_file="$manifest_home_on_host/$native_binary_name"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we're supposed to put anything except the JSON manifests in this folder but it probably doesn't matter.

Is there a good reason for abandoning the old $XDG_DATA_HOME/.local/share directory on non-flatpak installations?

I can guarantee that some people will have ill-advised scripts that are rely on the location of the executable, e.g. :! ls ../../.. - I would prefer it if we could refrain from breaking them


echo "Installing manifest here: $manifest_home_on_host"
echo "Installing script here: $native_file"

curl -sSL --create-dirs -o "$manifest_file" "$manifest_loc"
curl -sSL --create-dirs -o "$native_file" "$native_loc"
Expand All @@ -80,7 +106,7 @@ run() {
exit 1
fi

sed -i.bak "s/REPLACE_ME_WITH_SED/$(sedEscape "$native_file")/" "$manifest_file"
sed -i.bak "s/REPLACE_ME_WITH_SED/$(sedEscape "$manifest_home_in_sandbox/$native_binary_name")/" "$manifest_file"
chmod +x "$native_file"

## Apparently `curl`'d things don't get quarantined, so maybe we don't need this after all?
Expand All @@ -91,10 +117,6 @@ run() {
# sudo xattr -d com.apple.quarantine "$native_file"
# ;;
# esac

echo
echo "Successfully installed Tridactyl native messenger!"
echo "Run ':native' in Firefox to check."
Comment on lines -94 to -97
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that this message is confusing, but I'd rather we improved it rather than removed it totally.

E.g. Tridactyl native messenger installed; run :native in Tridactyl to check that it works

}

# Run the run function in a subshell so that it can be exited early if an error
Expand Down