refactor(desktop): tighten autoLaunch helpers per code review
This commit is contained in:
@@ -47,6 +47,15 @@ describe('parseExecPathFromDesktopFile', () => {
|
|||||||
it('returns null on empty input', () => {
|
it('returns null on empty input', () => {
|
||||||
expect(parseExecPathFromDesktopFile('')).toBeNull();
|
expect(parseExecPathFromDesktopFile('')).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('returns null on an empty quoted Exec= path', () => {
|
||||||
|
expect(parseExecPathFromDesktopFile('Exec=""\n')).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles CRLF line endings', () => {
|
||||||
|
const content = '[Desktop Entry]\r\nExec=/opt/Backspace/backspace --hidden\r\n';
|
||||||
|
expect(parseExecPathFromDesktopFile(content)).toBe('/opt/Backspace/backspace');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('shouldReapplyAppImage', () => {
|
describe('shouldReapplyAppImage', () => {
|
||||||
|
|||||||
@@ -18,12 +18,13 @@ export function parseExecPathFromDesktopFile(content: string): string | null {
|
|||||||
const line = raw.trim();
|
const line = raw.trim();
|
||||||
if (!line || line.startsWith('#')) continue;
|
if (!line || line.startsWith('#')) continue;
|
||||||
if (!line.startsWith('Exec=')) continue;
|
if (!line.startsWith('Exec=')) continue;
|
||||||
const value = line.slice('Exec='.length).trimStart();
|
const value = line.slice('Exec='.length);
|
||||||
if (!value) continue;
|
if (!value) continue;
|
||||||
if (value.startsWith('"')) {
|
if (value.startsWith('"')) {
|
||||||
const end = value.indexOf('"', 1);
|
const end = value.indexOf('"', 1);
|
||||||
if (end === -1) return null;
|
if (end === -1) return null;
|
||||||
return value.slice(1, end);
|
const extracted = value.slice(1, end);
|
||||||
|
return extracted === '' ? null : extracted;
|
||||||
}
|
}
|
||||||
const sp = value.indexOf(' ');
|
const sp = value.indexOf(' ');
|
||||||
return sp === -1 ? value : value.slice(0, sp);
|
return sp === -1 ? value : value.slice(0, sp);
|
||||||
|
|||||||
Reference in New Issue
Block a user