Repository navigation
Detect native apps via zerogapp.json manifests #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,7 +47,7 @@ export type DetectedApp = { | |
| version: string; | ||
| extensions: string[]; | ||
| launch: AppLaunch; | ||
| source: 'unpacked' | 'portable' | 'dev'; | ||
| source: 'unpacked' | 'portable' | 'dev' | 'manifest'; | ||
| projectDir: string; | ||
| }; | ||
|
|
||
|
|
@@ -249,6 +249,43 @@ export function packageAppName(pkg: unknown): string { | |
| return typeof source.name === 'string' ? source.name.trim() : ''; | ||
| } | ||
|
|
||
| /** A native (non-Electron) app's zerogapp.json manifest, validated. */ | ||
| export type ZerogAppManifest = { | ||
| name: string; | ||
| version: string; | ||
| extensions: string[]; | ||
| launch: AppLaunch; | ||
| }; | ||
|
|
||
| export function zerogAppManifest(raw: unknown): ZerogAppManifest | null { | ||
| if (!raw || typeof raw !== 'object') return null; | ||
| const source = raw as Record<string, unknown>; | ||
| const name = typeof source.name === 'string' ? source.name.trim() : ''; | ||
| if (!name || name.length > 80) return null; | ||
| const version = typeof source.version === 'string' ? source.version.trim() : ''; | ||
| const extensions = parseExtensionList( | ||
| Array.isArray(source.extensions) ? source.extensions.join(',') : source.extensions | ||
| ); | ||
| if (!extensions.length) return null; | ||
| const launchRaw = source.launch; | ||
| if (!launchRaw || typeof launchRaw !== 'object') return null; | ||
| const launchSource = launchRaw as Record<string, unknown>; | ||
| const command = typeof launchSource.command === 'string' ? launchSource.command.trim() : ''; | ||
| if (!command || command.length > 2048) return null; | ||
| const args = Array.isArray(launchSource.args) | ||
| ? launchSource.args | ||
| .filter((arg): arg is string => typeof arg === 'string' && arg.length <= 2048 && !/[\0\r\n]/.test(arg)) | ||
| .slice(0, 32) | ||
| : []; | ||
| const cwd = typeof launchSource.cwd === 'string' && launchSource.cwd.trim() ? launchSource.cwd.trim() : undefined; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛑 Security Vulnerability: The |
||
| return { | ||
| name, | ||
| version, | ||
| extensions, | ||
| launch: { command, args: args.length ? args : ['{file}'], ...(cwd ? { cwd } : {}) } | ||
| }; | ||
| } | ||
|
|
||
| /** Best launchable exe among build artifacts: portable over installer-free, newest version first. */ | ||
| export function pickPortableExe(names: readonly string[]): string | null { | ||
| const candidates = names.filter( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛑 Logic Error: The
catchblock at line 91 swallows all exceptions from the entiretryblock, including errors thrown bylaunchForProject(which performs async file I/O). IflaunchForProjectthrows — for example, due to a filesystem permission error — the exception is treated as "no package.json",detectedstaysfalse, and the code then tries to readzerogapp.jsonfor a project that actually has a validpackage.json. This silently drops legitimate Electron projects from detection results. The catch block should only guard thereadFile/JSON.parseforpackage.json, not the launch resolution logic.