Files
moho/scripts/install-desktop.sh
T
SalastilandClaude Opus 5 69549c97ae Follow an irc:// link from the browser
Clicking irc://irc.coreirc.net/elitewarez anywhere on the machine now
brings moho up on that channel.

What happens depends on whether it is a network moho is already on. If
it is, there is nothing to set up: the channel is joined on that
connection and opened, which is what clicking a link to a channel meant.
If it is not, the accounts page opens with the host, port and channel
already filled in - the nick is the only thing such a link cannot
supply, which is why there is a form at all rather than an account
simply appearing. Being on the network is not string equality either: a
link to irc.libera.chat is somewhere you already are if you connected
through irc.eu.libera.chat.

The parser is written against what people actually write rather than
against the drafts, which expired twenty years ago without agreeing. A
bare # starts a fragment, so browsers split the channel off and it has
to be put back; it also arrives percent-encoded, or doubled for a
network-wide channel. A comma is usually another channel and sometimes
one of a small fixed set of flags. A key is never kept - a password out
of a link anybody could have posted is not a thing to write to disk.

Getting there needs three separate paths because the desktops disagree:
an argument on a cold start, a second-instance event once one is already
running, and open-url on macOS. A link arriving before there is a window
is held rather than dropped, since a click that launches the app is
exactly when there is not one yet. The scheme is checked again on the
way in: it arrives as a command-line argument, and an argument is not a
promise about its own contents.

The same links in a message body are now clickable and go the same way,
rather than being handed to the desktop and bounced straight back here.

Parser checked against fifteen link shapes, including the reported one.
Two of them found real faults: several channels being cut to one, and a
key being read where the drafts put a flag.

Points at nobilis 6aa2a1e, without which a new account would have joined
nothing.

Co-Authored-By: Claude Opus 5 <[email protected]>
2026-08-30 23:33:12 -04:00

64 lines
2.3 KiB
Bash
Executable File

#!/usr/bin/env sh
# Puts the built AppImage where the desktop can find it, with a launcher entry
# and icons.
#
# Separate from packaging because building and installing are different acts -
# but paired with it in `npm run deploy`, because the gap between them is where
# a stale copy lives. An AppImage sitting in dist/ while an older one runs from
# ~/.local/bin is exactly the kind of confusion that costs an evening.
set -eu
APP_ID=moho
SRC_DIR="$(cd "$(dirname "$0")/.." && pwd)"
APPIMAGE="$(ls "$SRC_DIR"/dist/*.AppImage 2>/dev/null | head -1)"
BIN_DIR="${XDG_BIN_HOME:-$HOME/.local/bin}"
APPS_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/applications"
ICON_ROOT="${XDG_DATA_HOME:-$HOME/.local/share}/icons/hicolor"
if [ -z "$APPIMAGE" ]; then
echo "no AppImage in $SRC_DIR/dist - run 'npm run pack' first" >&2
exit 1
fi
install -Dm755 "$APPIMAGE" "$BIN_DIR/$APP_ID.AppImage"
# Every size the panel, launcher and window switcher might ask for. Scaling one
# 512px icon down at display time is blurrier than shipping the sizes.
for size in 16 24 32 48 64 96 128 256 512; do
target="$ICON_ROOT/${size}x${size}/apps/$APP_ID.png"
mkdir -p "$(dirname "$target")"
if command -v magick >/dev/null 2>&1; then
magick "$SRC_DIR/resources/icons/$APP_ID.png" -resize "${size}x${size}" "$target"
else
install -Dm644 "$SRC_DIR/resources/icons/$APP_ID.png" "$target"
fi
done
mkdir -p "$APPS_DIR"
cat > "$APPS_DIR/$APP_ID.desktop" <<EOF
[Desktop Entry]
Type=Application
Name=moho
GenericName=Chat Client
Comment=IRC, Discord, Matrix and Sneedchat in one client
Exec=$BIN_DIR/$APP_ID.AppImage %U
Icon=$APP_ID
Terminal=false
Categories=Network;InstantMessaging;Chat;
# What makes an irc:// link in a browser offer moho at all. Exec already takes
# %U, so the desktop has somewhere to put the URL once it decides to.
MimeType=x-scheme-handler/irc;x-scheme-handler/ircs;
Keywords=chat;irc;discord;matrix;sneedchat;messaging;
StartupWMClass=moho
StartupNotify=true
SingleMainWindow=true
EOF
chmod 644 "$APPS_DIR/$APP_ID.desktop"
command -v update-desktop-database >/dev/null 2>&1 && update-desktop-database "$APPS_DIR" || true
command -v gtk-update-icon-cache >/dev/null 2>&1 && gtk-update-icon-cache -f -t "$ICON_ROOT" >/dev/null 2>&1 || true
echo "installed $(basename "$APPIMAGE") -> $BIN_DIR/$APP_ID.AppImage"
echo "launcher -> $APPS_DIR/$APP_ID.desktop"