Skip to content
Draft
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
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,15 @@ typings/
# Electron-Forge
out/

bin/
bin/*/thv
bin/*/README.md
bin/*/LICENSE

# Playwright
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
/test-videos/


19 changes: 19 additions & 0 deletions bin/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM docker:dind

RUN apk add --no-cache dbus dbus-x11 gnome-keyring libsecret

RUN setcap -r /usr/bin/gnome-keyring-daemon 2>/dev/null || true

ENV XDG_CURRENT_DESKTOP=GNOME \
XDG_SESSION_DESKTOP=gnome \
DESKTOP_SESSION=gnome \
# a writable runtime dir (glib falls back to /tmp if this is unset)
XDG_RUNTIME_DIR=/tmp/xdg-runtime
ENV DOCKER_HOST=unix:///var/run/docker.sock

COPY --chmod=755 linux-x64/thv /usr/local/bin/thv
COPY ./ephemeral/entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/entrypoint.sh

ENTRYPOINT ["entrypoint.sh"]
CMD []
21 changes: 21 additions & 0 deletions bin/ephemeral/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env sh
set -eu

export CI=true

/usr/local/bin/dockerd-entrypoint.sh &
until docker info >/dev/null 2>&1; do sleep 0.5; done
echo "🐳 Docker-in-Docker daemon is ready."

mkdir -p /tmp/xdg-runtime/keyring
chmod 700 /tmp/xdg-runtime /tmp/xdg-runtime/keyring

eval "$(dbus-launch --sh-syntax)"
export XDG_RUNTIME_DIR=/tmp/xdg-runtime

echo "default-password" | gnome-keyring-daemon --unlock --components=secrets,ssh &
sleep 2

export GNOME_KEYRING_CONTROL GNOME_KEYRING_PID

exec "$@"
19 changes: 19 additions & 0 deletions bin/ephemeral/thv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
set -euo pipefail
set -x

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"

(
cd "${ROOT_DIR}"
docker run --privileged \
--cap-drop=SETPCAP \
--cap-add=IPC_LOCK \
--tmpfs /run \
--rm -i \
--network host \
-v "${ROOT_DIR}:/workspace" \
-w /workspace \
thv-containerized thv "$@"
)
25 changes: 10 additions & 15 deletions main/src/toolhive-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,16 @@ import type { Tray } from 'electron'
import { updateTrayStatus } from './system-tray'
import log from './logger'
import * as Sentry from '@sentry/electron/main'
import { delay } from '../../utils/delay'

// Use environment variables for binary customization with Windows fallback
const binName =
process.env.BIN_NAME ?? (process.platform === 'win32' ? 'thv.exe' : 'thv')
const binArch = process.env.BIN_ARCH ?? `${process.platform}-${process.arch}`

const binName = process.platform === 'win32' ? 'thv.exe' : 'thv'
const binPath = app.isPackaged
? path.join(
process.resourcesPath,
'bin',
`${process.platform}-${process.arch}`,
binName
)
: path.resolve(
__dirname,
'..',
'..',
'bin',
`${process.platform}-${process.arch}`,
binName
)
? path.join(process.resourcesPath, 'bin', binArch, binName)
: path.resolve(__dirname, '..', '..', 'bin', binArch, binName)

let toolhiveProcess: ReturnType<typeof spawn> | undefined
let toolhivePort: number | undefined
Expand Down Expand Up @@ -75,6 +68,8 @@ export async function startToolhive(tray?: Tray): Promise<void> {
}
)

await delay(4000)

log.info(`[startToolhive] Process spawned with PID: ${toolhiveProcess.pid}`)

if (tray) {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
},
"scripts": {
"start": "electron-forge start",
"e2e": "env CI=true sh -c \"tsc -b --clean && tsc -b && electron-forge package && playwright test\"",
"start:ephemeral": "BIN_NAME='thv.sh' BIN_ARCH='ephemeral' electron-forge start",
"e2e": "env CI=true sh -c \"tsc -b --clean && tsc -b && electron-forge package && BIN_NAME='thv.sh' BIN_ARCH='ephemeral' playwright test\"",
"start:mockUpdate": "MOCK_UPDATE_SERVER=true ELECTRON_IS_DEV=0 electron-forge start",
"package": "tsc -b --clean && tsc -b && electron-forge package",
"make": "tsc -b --clean && tsc -b && electron-forge make",
Expand Down
Loading