Skip to content
Merged
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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ hqterm desktop
```

The installer puts the AppImage in `~/.local/opt/hqterm-desktop/` and adds a
launcher entry (`~/.local/share/applications/hqterm.desktop`). A plain install
launcher entry (`~/.local/share/applications/hqterm.desktop`). Where libfuse2
is missing (current Ubuntu/Kubuntu ship only fuse3) it unpacks the app once into
`~/.local/opt/hqterm-desktop/app/` and launches that instead. A plain install
does this too on Linux when `$DISPLAY` or `$WAYLAND_DISPLAY` is set;
`--no-desktop` skips it.

Expand Down
4 changes: 2 additions & 2 deletions desktop/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion desktop/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "hqterm-desktop",
"productName": "hqterm",
"version": "0.2.1",
"version": "0.2.2",
"description": "hqterm desktop: a terminal window that shows hqtui/qc images and HD emoji (xterm.js + node-pty).",
"license": "MIT",
"author": "Profullstack, Inc. <hello@profullstack.com>",
Expand Down
39 changes: 33 additions & 6 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,20 @@ install_one() {
return 0
}

# have_libfuse2: whether an AppImage can mount itself here.
have_libfuse2() {
for d in /lib /lib64 /usr/lib /usr/lib64 /lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu /lib/aarch64-linux-gnu /usr/lib/aarch64-linux-gnu; do
[ -e "$d/libfuse.so.2" ] && return 0
done
for l in ldconfig /sbin/ldconfig /usr/sbin/ldconfig; do
if command -v "$l" >/dev/null 2>&1; then
"$l" -p 2>/dev/null | grep -q 'libfuse\.so\.2' && return 0
return 1
fi
done
return 1
}

# install_desktop: the AppImage, an icon and an app-launcher entry (Linux only).
install_desktop() {
if [ "$OS" != linux ]; then
Expand Down Expand Up @@ -163,19 +177,32 @@ install_desktop() {
|| fetch "https://raw.githubusercontent.com/profullstack/openemoji/main/png/256/1f5a5-fe0f.png" "$TMP/hqterm.png" 2>/dev/null; then
mv -f "$TMP/hqterm.png" "$icons/hqterm.png"
fi
# AppImages mount through FUSE; without it they can unpack and run instead.
extra=""
if ! command -v fusermount >/dev/null 2>&1 && ! command -v fusermount3 >/dev/null 2>&1; then
extra=" --appimage-extract-and-run"
say "note: no FUSE (fusermount) here, so the launcher uses --appimage-extract-and-run"
chmod 644 "$icons/hqterm.png" 2>/dev/null || true
# An AppImage mounts itself with libfuse2 (libfuse.so.2), which many current
# distros no longer install (they ship fuse3 only). Without it, unpack the
# app once into $dir/app and launch that instead.
rm -rf "$dir/app"
exe="$dir/hqterm-desktop.AppImage"
if ! have_libfuse2; then
say "no libfuse2 here (AppImages need it to mount); unpacking the app into $dir/app"
rm -rf "$dir/squashfs-root"
if (cd "$dir" && ./hqterm-desktop.AppImage --appimage-extract >/dev/null) && [ -x "$dir/squashfs-root/hqterm-desktop" ]; then
mv "$dir/squashfs-root" "$dir/app"
chmod -R go+rX "$dir/app" 2>/dev/null || true
exe="$dir/app/hqterm-desktop"
say "installed $exe"
else
rm -rf "$dir/squashfs-root"
say "warning: could not unpack the AppImage; install libfuse2 (e.g. sudo apt install libfuse2t64) to run it"
fi
fi
cat > "$apps/hqterm.desktop" <<EOF
[Desktop Entry]
Type=Application
Name=hqterm
GenericName=Terminal
Comment=Terminal with tabs, split panes, images and HD emoji; persistent hqsh sessions
Exec=$dir/hqterm-desktop.AppImage$extra --no-sandbox
Exec=$exe --no-sandbox
Icon=$icons/hqterm.png
Terminal=false
Categories=System;TerminalEmulator;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hqterm",
"version": "0.2.1",
"version": "0.2.2",
"description": "Terminal session manager: persistent hqsh sessions with images and HD emoji, built on hqtui.",
"license": "MIT",
"private": true,
Expand Down
24 changes: 20 additions & 4 deletions src/desktop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ export function desktopCandidates(env: NodeJS.ProcessEnv = process.env, platform
out.push("/Applications/hqterm.app", join(home, "Applications", "hqterm.app"));
} else {
const opt = join(home, ".local", "opt", "hqterm-desktop");
out.push(join(opt, "hqterm-desktop.AppImage"), join(opt, "hqterm-desktop"));
// app/ is the AppImage unpacked by the installer where libfuse2 is missing.
out.push(join(opt, "app", "hqterm-desktop"), join(opt, "hqterm-desktop.AppImage"), join(opt, "hqterm-desktop"));
}
return out;
}
Expand All @@ -75,12 +76,28 @@ export function desktopLaunch(
if (opts.session) appArgs.push("--session", opts.session);
if (platform === "darwin" && path.endsWith(".app")) return ["open", "-n", "-a", path, "--args", ...appArgs];
const pre: string[] = [];
// AppImages mount with FUSE; without it they can still unpack and run.
// AppImages mount with libfuse2; without it they can still unpack (to $TMPDIR, every launch) and run.
if (path.endsWith(".AppImage") && !hasFuse) pre.push("--appimage-extract-and-run");
// Chromium's setuid sandbox is not set up inside an AppImage.
return [path, ...pre, ...(platform === "linux" ? ["--no-sandbox"] : []), ...appArgs];
}

const LIBFUSE2_DIRS = [
"/lib",
"/lib64",
"/usr/lib",
"/usr/lib64",
"/lib/x86_64-linux-gnu",
"/usr/lib/x86_64-linux-gnu",
"/lib/aarch64-linux-gnu",
"/usr/lib/aarch64-linux-gnu",
];

/** An AppImage mounts itself with libfuse.so.2; fuse3-only systems (current Ubuntu, Kubuntu) cannot. */
export function hasLibfuse2(exists: (p: string) => boolean = existsSync): boolean {
return LIBFUSE2_DIRS.some((d) => exists(join(d, "libfuse.so.2")));
}

export function hasDisplay(env: NodeJS.ProcessEnv = process.env, platform = process.platform): boolean {
return platform !== "linux" || Boolean(env.DISPLAY || env.WAYLAND_DISPLAY);
}
Expand All @@ -100,8 +117,7 @@ export async function desktop(args: string[]): Promise<number> {
console.error("hqterm desktop: no display ($DISPLAY / $WAYLAND_DISPLAY unset). Run it from your desktop session.");
return 2;
}
const hasFuse = Boolean(Bun.which("fusermount") || Bun.which("fusermount3"));
const [cmd, ...rest] = desktopLaunch(path, parsed.opts, process.platform, hasFuse);
const [cmd, ...rest] = desktopLaunch(path, parsed.opts, process.platform, hasLibfuse2());
const child = spawn(cmd!, rest, { detached: true, stdio: "ignore", env: { ...process.env, ELECTRON_DISABLE_SANDBOX: "1" } });
const failed = await new Promise<Error | undefined>((resolve) => {
child.once("error", resolve);
Expand Down
13 changes: 12 additions & 1 deletion test/desktop.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, test } from "bun:test";
import { join } from "node:path";
import { desktopCandidates, desktopLaunch, findDesktop, hasDisplay, parseDesktopArgs } from "../src/desktop.ts";
import { desktopCandidates, desktopLaunch, findDesktop, hasDisplay, hasLibfuse2, parseDesktopArgs } from "../src/desktop.ts";
import { globBasename } from "../src/sshconfig.ts";
import { main } from "../src/main.ts";

Expand All @@ -17,9 +17,13 @@ describe("hqterm desktop", () => {

test("looks in $HQTERM_DESKTOP, then the install dir (Linux) or /Applications (macOS)", () => {
expect(desktopCandidates({}, "linux", "/h")).toEqual([
"/h/.local/opt/hqterm-desktop/app/hqterm-desktop",
"/h/.local/opt/hqterm-desktop/hqterm-desktop.AppImage",
"/h/.local/opt/hqterm-desktop/hqterm-desktop",
]);
// The unpacked app (no libfuse2) wins over the AppImage beside it.
const both = new Set(["/h/.local/opt/hqterm-desktop/app/hqterm-desktop", "/h/.local/opt/hqterm-desktop/hqterm-desktop.AppImage"]);
expect(findDesktop({}, "linux", "/h", (p) => both.has(p))).toBe("/h/.local/opt/hqterm-desktop/app/hqterm-desktop");
expect(desktopCandidates({ HQTERM_DESKTOP: "/x/app" }, "linux", "/h")[0]).toBe("/x/app");
expect(desktopCandidates({}, "darwin", "/h")).toEqual(["/Applications/hqterm.app", "/h/Applications/hqterm.app"]);
const have = new Set(["/h/.local/opt/hqterm-desktop/hqterm-desktop"]);
Expand Down Expand Up @@ -50,6 +54,13 @@ describe("hqterm desktop", () => {
]);
});

test("libfuse2 check looks for libfuse.so.2, not fusermount", () => {
expect(hasLibfuse2(() => false)).toBe(false);
expect(hasLibfuse2((p) => p === "/usr/lib/x86_64-linux-gnu/libfuse.so.2")).toBe(true);
expect(hasLibfuse2((p) => p === "/usr/lib/libfuse.so.2")).toBe(true);
expect(hasLibfuse2((p) => p.endsWith("libfuse3.so.3"))).toBe(false);
});

test("display check", () => {
expect(hasDisplay({}, "linux")).toBe(false);
expect(hasDisplay({ WAYLAND_DISPLAY: "wayland-0" }, "linux")).toBe(true);
Expand Down
Loading