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
3 changes: 2 additions & 1 deletion PROGRESS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Current

In-app name dialog (New Folder / New File / Rename / favorite naming) and Explorer-style drag-drop inside and between panes, on top of the drive picker, per-pane refresh, and multi-select (Ctrl/Shift/Ctrl+A) with batch copy/cut/paste/F5/F6/delete.
File-type associations with auto-detected local apps (Settings → File apps), plus the in-app name dialog (New Folder / New File / Rename / favorite naming) and Explorer-style drag-drop inside and between panes, on top of the drive picker, per-pane refresh, and multi-select (Ctrl/Shift/Ctrl+A) with batch copy/cut/paste/F5/F6/delete.

Public on GitHub since 2026-11-10 (HappyMonkeyAI/ZeroGFileMan, MIT). The history was rewritten before publishing: personal email only, no LAN IPs or home paths. The pre-public history and code-review PRs #1–#3 are in the archived private repo `HappyMonkeyAI/ZeroGFileMan-archive`. PR numbers in this repo restart at #1.

Expand All @@ -28,6 +28,7 @@ Open check: builtin Whisper model download under the narrowed CSP `connect-src`
- Update service covered by 27 tests; `npm run typecheck`, `npm test` (164 tests), and `npm run build` pass
- Final Windows NSIS and portable artifacts rebuilt successfully as separate targets after the combined package command timed out
- Favorites polish: the global picker now has explicit rename/remove controls, and the path action toggles between Add and Remove while preserving the existing `favorites.json` model
- File-type associations: the development store is scanned for apps declaring `build.fileAssociations` (unpacked exe → portable → dev Electron fallback); Settings → File apps lists detected apps, sets a default app per extension, and adds custom programs with a `{file}` argument template; Open/double-click and the right-click menu honor the associations through the injection-safe spawner (25 new tests; 213 total)
- In-app name dialog replaces `window.prompt` (Electron never implements it): New Folder, New File type/name, Rename (F2) and favorite naming now work in both panes; inline validation, Esc/Cancel aborts, new folders land selected
- Explorer-style drag-drop inside and between panes: drag = move, Ctrl = copy, Shift = force move, cross-drive defaults to copy; targets are folder rows/tiles, pane background, ".." and breadcrumbs; whole-selection drag; both panes refresh and the transcript logs each op; same-folder moves and drops into a folder's own subtree are no-ops
- Name dialog + drag-drop rules covered by 24 new tests (188 total); `npm run ci` passes; verified in a real hidden Electron window against a temp filesystem: 14/14 UI checks (dialog in the right pane, invalid-name error, Esc cancel, F2 rename, cross-pane move, Ctrl copy, folder-row drop, same-folder no-op)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Nothing downloads or installs without explicit consent. **Later** hides the prom
- Dual local panes with breadcrumbs, history (Alt+←/→), favorites, Ctrl+K jump
- Favorites bar with direct open, rename, remove, and an add/remove toggle for the active path
- CRUD + cross-pane clipboard; F5/F6 copy/move to the other pane
- File-type associations: apps in your development store that declare file associations are detected automatically; pick a default app per extension or add any program in Settings → File apps
- Per-pane **Navigate** / **Action** jewels: click-toggle or hold-to-talk; Esc cancels
- Speech engines: demo transcript, builtin Whisper (Transformers.js), or OpenAI-compatible server (API key in OS safeStorage)
- Consent-based Windows update checks through the GitHub releases API
Expand Down
1 change: 1 addition & 0 deletions ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Repo: [HappyMonkeyAI/ZeroGFileMan](https://github.com/HappyMonkeyAI/ZeroGFileMan
| P1.6 | Global jump (⌘K / Ctrl+K) | Focus brand-bar search; Enter → Navigate | done |
| P1.7 | In-app name dialog | Electron has no `window.prompt`; New Folder / New File / Rename / favorite naming use a validated dialog | done |
| P1.8 | Drag-drop between panes | Drag = move, Ctrl = copy, Shift = force move; folder rows, pane background, "..", breadcrumbs as targets; multi-select drag | done |
| P1.9 | File-type associations | Auto-detect dev-store apps via `build.fileAssociations`; per-extension defaults + custom apps in Settings; Open and right-click honor them | done |

### P2 — Voice that works offline

Expand Down
91 changes: 91 additions & 0 deletions src/main/app-detect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// Find launchable apps in the development store: projects whose package.json
// declares electron-builder fileAssociations. Prefer the unpacked exe, then a
// portable artifact, then the project's own Electron binary in dev mode.

import { existsSync } from 'node:fs';
import { readdir, readFile } from 'node:fs/promises';
import { homedir } from 'node:os';
import { isAbsolute, join } from 'node:path';
import {
packageAppName,
packageAssociations,
pickPortableExe,
type AppLaunch,
type DetectedApp
} from '../shared/file-apps.js';

export function defaultAppsRoot(): string {
return join(homedir(), 'Documents', 'development');
}

function devElectronBinary(dir: string): string | null {
const base = join(dir, 'node_modules', 'electron', 'dist');
const candidate =
process.platform === 'win32'
? join(base, 'electron.exe')
: process.platform === 'darwin'
? join(base, 'Electron.app', 'Contents', 'MacOS', 'Electron')
: join(base, 'electron');
return existsSync(candidate) ? candidate : null;
}

async function launchForProject(dir: string, name: string, pkg: Record<string, unknown>): Promise<{ launch: AppLaunch; source: DetectedApp['source'] } | null> {
const build = (pkg.build ?? {}) as Record<string, unknown>;
const directories = (build.directories ?? {}) as Record<string, unknown>;
const outputs = [...new Set([directories.output, 'dist', 'release'].filter((value): value is string => typeof value === 'string' && Boolean(value)))];

for (const out of outputs) {
const unpacked = join(dir, out, 'win-unpacked', `${name}.exe`);
if (existsSync(unpacked)) return { launch: { command: unpacked, args: ['{file}'] }, source: 'unpacked' };
Comment on lines +37 to +39

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛑 Logic Error: The win-unpacked lookup constructs a ${name}.exe path unconditionally. On macOS, the equivalent would be a .app bundle, and on Linux there is no .exe extension. This means the unpacked source is never found on non-Windows platforms, silently falling through to the portable or dev fallback even when a proper unpacked build exists. The PR description states multi-platform support, so this will silently produce wrong results on macOS/Linux.

}
for (const out of outputs) {
try {
const exe = pickPortableExe(await readdir(join(dir, out)));
if (exe) return { launch: { command: join(dir, out, exe), args: ['{file}'] }, source: 'portable' };
} catch {
/* no output folder */
}
}
const electron = devElectronBinary(dir);
if (electron) return { launch: { command: electron, args: ['.', '{file}'], cwd: dir }, source: 'dev' };
return null;
}

/** Scan one folder depth for app projects; unreadable entries are skipped. */
export async function detectLocalApps(rootRaw: unknown): Promise<DetectedApp[]> {
const root =
typeof rootRaw === 'string' && rootRaw.trim() && isAbsolute(rootRaw.trim())
? rootRaw.trim()
: defaultAppsRoot();
Comment on lines +55 to +59

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛑 Logic Error: detectLocalApps accepts any user-supplied absolute path as rootRaw, which is exposed via the apps:detect IPC channel. A compromised renderer could pass a crafted absolute path to scan directories outside the intended development store (e.g. /etc or C:\Windows), reading arbitrary package.json files and leaking directory structure information. The IPC handler at handle('apps:detect', ...) performs no additional path restriction. Consider validating that the supplied root is confined to expected parent directories (e.g. the user's home directory), or restricting the scan to the configured prefs value only.

let entries;
try {
entries = await readdir(root, { withFileTypes: true });
} catch {
return [];
}
const apps: DetectedApp[] = [];
for (const entry of entries) {
if (!entry.isDirectory() || entry.name.startsWith('.') || entry.name === 'node_modules') continue;
const projectDir = join(root, entry.name);
try {
const pkg = JSON.parse(await readFile(join(projectDir, 'package.json'), 'utf8')) as Record<string, unknown>;
const extensions = packageAssociations(pkg);
if (!extensions.length) continue;
const name = packageAppName(pkg) || entry.name;
const found = await launchForProject(projectDir, name, pkg);
if (!found) continue;
apps.push({
id: `detected:${entry.name}`,
name,
version: typeof pkg.version === 'string' ? pkg.version : '',
extensions,
launch: found.launch,
source: found.source,
projectDir
});
} catch {
/* not an app project */
}
}
return apps.sort((a, b) => a.name.localeCompare(b.name));
}
40 changes: 39 additions & 1 deletion src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ import {
type IpcMainInvokeEvent
} from 'electron';
import { existsSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { access, constants } from 'node:fs/promises';
import { dirname, isAbsolute, join } from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';
import { detectLocalApps } from './app-detect.js';
import { buildContextMenu, parseContextMenuTarget } from '../shared/context-menu.js';
import { appCommandProblem, resolveAppArgs } from '../shared/file-apps.js';
import { parseServerTranscriptionInput, transcribeViaServer } from '../shared/speech-server.js';
import { isAppUrl, type AppLocation } from './app-origin.js';
import { installApplicationMenu } from './app-menu.js';
Expand Down Expand Up @@ -231,6 +234,41 @@ handle('shell:openTerminal', (_e, path: unknown, options?: unknown) => {
});
});

handle('apps:detect', (_e, root: unknown) => detectLocalApps(root));

handle('apps:open', async (_e, raw: unknown) => {
const request = (raw ?? {}) as { filePath?: unknown; command?: unknown; args?: unknown; cwd?: unknown };
const filePath = resolveLocalPath(request.filePath);
if (!existsSync(filePath)) throw new Error('That file no longer exists.');
const command = typeof request.command === 'string' ? request.command.trim() : '';
if (!command || !isAbsolute(command) || !existsSync(command)) throw new Error('App executable not found.');
const commandProblem = appCommandProblem(command, process.platform);
if (commandProblem) throw new Error(commandProblem);
if (process.platform !== 'win32') {
try {
await access(command, constants.X_OK);
} catch {
throw new Error('The app must be an executable file.');
}
}
const args = Array.isArray(request.args) ? request.args : [];
if (
args.length > 32 ||
args.some((arg) => typeof arg !== 'string' || arg.length > 2048 || /[\0\r\n]/.test(arg))
) {
throw new Error('Invalid app arguments.');
}
const cwd =
typeof request.cwd === 'string' && request.cwd && isAbsolute(request.cwd) && existsSync(request.cwd)
? request.cwd
: undefined;
const resolved = resolveAppArgs(args as string[], filePath);
await new Promise<void>((resolvePromise, reject) => {
spawnDetached(command, resolved, { cwd, onError: reject });
Comment on lines +265 to +267

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛑 Security Vulnerability: The apps:open handler resolves {file} into the args array via resolveAppArgs and then passes those resolved args directly to spawnDetached. If spawnDetached internally uses child_process.exec or joins args into a shell command string (rather than using child_process.spawn with an array), a file path containing shell metacharacters (e.g. ; rm -rf ~) would be executed as a shell command. Confirm that spawnDetached always uses spawn/execFile with a separate args array — never a shell-interpolated command string — to prevent OS command injection.1

Footnotes

  1. CWE-78: OS Command Injection - https://cwe.mitre.org/data/definitions/78.html ↩

setTimeout(resolvePromise, 150);
});
});

handle('contextMenu:show', (event, raw: unknown) => {
const target = parseContextMenuTarget(raw);
const window = BrowserWindow.fromWebContents(event.sender) ?? undefined;
Expand Down
2 changes: 2 additions & 0 deletions src/main/preload.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ contextBridge.exposeInMainWorld('fileman', {
openPath: (path) => ipcRenderer.invoke('shell:openPath', path),
showItemInFolder: (path) => ipcRenderer.invoke('shell:showItem', path),
openWith: (path, app) => ipcRenderer.invoke('shell:openWith', path, app),
detectFileApps: (root) => ipcRenderer.invoke('apps:detect', root),
openWithApp: (request) => ipcRenderer.invoke('apps:open', request),
openTerminal: (path, options) => ipcRenderer.invoke('shell:openTerminal', path, options),
speechApiKeyStatus: () => ipcRenderer.invoke('speechKey:status'),
saveSpeechApiKey: (key) => ipcRenderer.invoke('speechKey:save', key),
Expand Down
21 changes: 21 additions & 0 deletions src/renderer/file-apps-settings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { DEFAULT_FILE_APP_PREFS, parseFileAppPrefs, type FileAppPrefs } from '../shared/file-apps.js';

const STORAGE_KEY = 'zerogfileman.fileApps';

export function loadStoredFileAppPrefs(): FileAppPrefs {
try {
const raw = localStorage.getItem(STORAGE_KEY);
if (!raw) return { ...DEFAULT_FILE_APP_PREFS, defaults: {}, customApps: [] };
return parseFileAppPrefs(JSON.parse(raw));
} catch {
return { ...DEFAULT_FILE_APP_PREFS, defaults: {}, customApps: [] };
}
}

export function storeFileAppPrefs(prefs: FileAppPrefs): void {
try {
localStorage.setItem(STORAGE_KEY, JSON.stringify(parseFileAppPrefs(prefs)));
} catch {
/* ignore */
}
}
Loading
Loading