feat(app): hide the hex tip when hex is installed (#64130)

This commit is contained in:
Dax
2026-11-15 17:53:11 -05:00
committed by GitHub
Unverified
parent aa2960fa26
commit 141be750b2
4 changed files with 110 additions and 1 deletions
+10 -1
View File
@@ -33,7 +33,15 @@ export function createTipToasts() {
const location = () => server()?.data.location
const [awake, setAwake] = createSignal(false)
const startup = setTimeout(() => setAwake(true), STARTUP_DELAY)
const [hexInstalled, setHexInstalled] = createSignal<boolean>()
const startup = setTimeout(() => {
setAwake(true)
if (!platform.checkAppExists) return setHexInstalled(false)
void platform.checkAppExists("hex").then(setHexInstalled, () => setHexInstalled(false))
}, STARTUP_DELAY)
onCleanup(() => clearTimeout(startup))
createEffect(() => {
const ctx = server()
@@ -66,6 +74,7 @@ export function createTipToasts() {
id: "hex",
title: "tips.hex.title",
description: "tips.hex.description",
when: () => hexInstalled() === false,
action: {
label: "tips.hex.install",
// anoma.ly/hex 404s with a query string; the trailing slash is required.
+8
View File
@@ -1,10 +1,18 @@
import { execFile } from "node:child_process"
import { homedir } from "node:os"
import util from "node:util"
import { Effect, FileSystem, Path } from "effect"
import { detectHex, hexPaths } from "./hex"
const execFilePromise = util.promisify(execFile)
let hex: Promise<boolean> | undefined
export const checkAppExists = Effect.fn("DesktopFiles.checkAppExists")(function* (appName: string) {
if (appName === "hex") {
return yield* Effect.promise(() => (hex ??= detectHex(hexPaths(process.platform, homedir(), process.env))))
}
if (process.platform === "win32") return true
if (process.platform === "linux") return true
@@ -0,0 +1,36 @@
import { expect, test } from "bun:test"
import { mkdtemp, mkdir, rm, writeFile } from "node:fs/promises"
import { tmpdir } from "node:os"
import path from "node:path"
import { detectHex, hexPaths } from "./hex"
test("uses the Hex installers' per-user layouts and desktop PATH", () => {
const mac = hexPaths("darwin", "/Users/test", { PATH: "/bin" })
expect([...mac]).toContain("/Users/test/Applications/Hex.app/Contents/MacOS/hex")
expect([...mac]).toContain("/bin/hex")
const windows = hexPaths("win32", "C:\\Users\\test", { APPDATA: "D:\\roaming", PATH: "D:\\bin;C:\\tools" })
expect([...windows]).toContain("D:\\roaming\\hex\\current-version")
expect([...windows]).toContain("C:\\tools\\hex.com")
const linux = hexPaths("linux", "/home/test", { XDG_DATA_HOME: "/data" })
expect([...linux]).toContain("/data/applications/anomaly.hex.desktop")
expect([...linux]).toContain("/data/hex/service.sock")
expect([...linux]).toContain("/usr/bin/hex")
})
test("retained Hex settings alone do not count as an installation", async () => {
const root = await mkdtemp(path.join(tmpdir(), "hex-detect-"))
try {
const support = path.join(root, "hex")
await mkdir(support)
await writeFile(path.join(support, "settings.json"), "{}")
const marker = path.join(support, "current-version")
expect(await detectHex([marker])).toBe(false)
await writeFile(marker, "3.1.0")
expect(await detectHex([marker])).toBe(true)
} finally {
await rm(root, { recursive: true, force: true })
}
})
+56
View File
@@ -0,0 +1,56 @@
import { stat } from "node:fs/promises"
import path from "node:path"
export function hexPaths(platform: NodeJS.Platform, home: string, env: NodeJS.ProcessEnv) {
const paths = platform === "win32" ? path.win32 : path.posix
const files = installedPaths(platform, home, env)
const names = platform === "win32" ? ["hex.com", "hex.exe"] : ["hex"]
const dirs = (env.PATH ?? "").split(paths.delimiter).filter((dir) => paths.isAbsolute(dir))
return new Set([...files, ...dirs.flatMap((dir) => names.map((name) => paths.join(dir, name)))])
}
export async function detectHex(files: Iterable<string>) {
for (const file of files) {
const info = await stat(file).catch(() => undefined)
if (!info) continue
if (file.endsWith("/service.sock")) {
if (info.isSocket()) return true
continue
}
if (info.isFile() && (path.basename(file) !== "hex" || (info.mode & 0o111) !== 0)) return true
}
return false
}
function installedPaths(platform: NodeJS.Platform, home: string, env: NodeJS.ProcessEnv) {
if (platform === "darwin") {
const binary = "Applications/Hex.app/Contents/MacOS/hex"
return [`/${binary}`, path.posix.join(home, binary)]
}
if (platform === "win32") {
const roaming = env.APPDATA || path.win32.join(home, "AppData", "Roaming")
return ["hex", "voice-control"].map((dir) => path.win32.join(roaming, dir, "current-version"))
}
if (platform !== "linux") return []
const data = env.XDG_DATA_HOME || path.posix.join(home, ".local/share")
const support = env.HEX_APPLICATION_SUPPORT_DIR || path.posix.join(data, "hex")
return [
"/usr/bin/hex",
"/usr/share/applications/anomaly.hex.desktop",
path.posix.join(data, "applications/anomaly.hex.desktop"),
path.posix.join(env.HEX_INSTALL_DIR || path.posix.join(home, ".local/bin"), "hex"),
path.posix.join(support, "current/hex"),
path.posix.join(support, "service.sock"),
]
}