Open-source SEO, GEO, and marketing skills for AI agents.
feat(app): Linux folder picker via zenity/kdialog (ported from #77)
Yuting Zhong1e92095b85ba
diff --git a/notfair/CHANGELOG.md b/notfair/CHANGELOG.mdindex 320f4231..26f7b4c4 100644--- a/notfair/CHANGELOG.md+++ b/notfair/CHANGELOG.md@@ -1,5 +1,9 @@# NotFair+## Unreleased++**Linux gets a native folder picker.** The Browse button now works on Linux desktops via zenity (GTK) with a kdialog (KDE/Plasma) fallback, and reports a clear error when neither is installed. Contributed by @RohithVangalla1 (#77), ported to the renamed app tree.+## 0.9.3 — 2026-07-20**Tagline refined.** "Goal-driven, loop-powered marketing agents that crush your business goals 24/7" — the identity and the hustle in one line, across npm, CLI `--help`, and the READMEs. First release published by the new auto-publish GitHub Action.diff --git a/notfair/src/server/fs/pick-folder.ts b/notfair/src/server/fs/pick-folder.tsindex 8786b7d0..d186ed60 100644--- a/notfair/src/server/fs/pick-folder.ts+++ b/notfair/src/server/fs/pick-folder.ts@@ -10,9 +10,9 @@ import { platform } from "node:os";** Implementations are platform-specific because there is no cross-platform* native picker primitive in Node. macOS uses AppleScript's `choose folder`,- * which returns a POSIX path. Linux + Windows fallbacks are TODO; callers- * receive a clear `kind: "unsupported"` they can branch on (UI falls back- * to a text input).+ * which returns a POSIX path. Linux uses zenity (GTK) with a kdialog (KDE)+ * fallback. Windows is TODO; callers receive a clear `kind: "unsupported"`+ * they can branch on (UI falls back to a text input).** The dialog is modal in the OS sense (blocks until the user picks or* cancels), so we set a generous timeout to avoid wedging the route if@@ -35,7 +35,10 @@ export async function pickFolder(opts: {if (p === "darwin") {return pickFolderMac(opts);}- // TODO: linux (zenity / kdialog), win32 (PowerShell FolderBrowserDialog).+ if (p === "linux") {+ return pickFolderLinux(opts);+ }+ // TODO: win32 (PowerShell FolderBrowserDialog).return { ok: false, kind: "unsupported", platform: p };}@@ -108,3 +111,79 @@ async function pickFolderMac(opts: {const normalized = out.replace(/\/+$/, "");return { ok: true, path: normalized };}++async function pickFolderLinux(opts: {+ prompt?: string;+ defaultLocation?: string;+}): Promise<PickFolderResult> {+ const prompt = opts.prompt ?? "Select a folder";++ // Try zenity first (GTK-based, most common on GNOME/Ubuntu/Fedora),+ // fall back to kdialog (KDE/Plasma).+ const zenityArgs = ["--file-selection", "--directory", `--title=${prompt}`];+ if (opts.defaultLocation) {+ zenityArgs.push(`--filename=${opts.defaultLocation}/`);+ }+ const zenityResult = await execDialog("zenity", zenityArgs);+ if (zenityResult !== null) {+ return zenityResult;+ }++ const kdialogArgs = [+ "--getexistingdirectory",+ opts.defaultLocation ?? "",+ "--title",+ prompt,+ ];+ const kdialogResult = await execDialog("kdialog", kdialogArgs);+ if (kdialogResult !== null) {+ return kdialogResult;+ }++ return {+ ok: false,+ kind: "error",+ message:+ "No supported dialog tool found. Install zenity (GTK) or kdialog (KDE) for folder picker support.",+ };+}++/**+ * Execute a dialog command and return the result, or null if the command+ * is not found (ENOENT), indicating we should try the next fallback.+ */+async function execDialog(+ cmd: string,+ args: string[],+): Promise<PickFolderResult | null> {+ return new Promise((resolve) => {+ execFile(cmd, args, { timeout: DIALOG_TIMEOUT_MS }, (err, stdout, stderr) => {+ if (err) {+ // ENOENT means the command doesn't exist — try next fallback.+ if ((err as NodeJS.ErrnoException).code === "ENOENT") {+ resolve(null);+ return;+ }+ // Exit code 1 in zenity/kdialog means the user cancelled.+ if ("code" in err && (err as { code: number }).code === 1) {+ resolve({ ok: false, kind: "cancelled" });+ return;+ }+ resolve({+ ok: false,+ kind: "error",+ message: stderr.trim() || err.message,+ });+ return;+ }+ const out = stdout.trim();+ if (!out) {+ resolve({ ok: false, kind: "cancelled" });+ return;+ }+ // Normalize: strip trailing slash for consistency.+ const normalized = out.replace(/\/+$/, "");+ resolve({ ok: true, path: normalized });+ });+ });+}