Skip to content

Commit bdc019b

Browse files
committed
fix: catch possible read icon error
1 parent 2c81f46 commit bdc019b

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

src/main/macos.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fs from 'fs'
22
import path from 'path'
33
import plist from 'plist'
44
import { Adapter } from './adapter'
5-
import { readdirSafe, readFileSafe } from './utils'
5+
import { readdirSafe, readFileSafe, readFileAsBufferSafe } from './utils'
66

77
export class MacosAdapter extends Adapter {
88
async readApps() {
@@ -40,7 +40,9 @@ export class MacosAdapter extends Adapter {
4040
}
4141

4242
private async readIcnsAsImageUri(file: string) {
43-
let buf = await fs.promises.readFile(file)
43+
let buf = await readFileAsBufferSafe(file)
44+
if (!buf) return ''
45+
4446
const totalSize = buf.readInt32BE(4) - 8
4547
buf = buf.slice(8)
4648

src/main/utils.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,12 @@ export async function readFileSafe(p: string) {
1717
return ''
1818
}
1919
}
20+
21+
export async function readFileAsBufferSafe(p: string) {
22+
try {
23+
return await fs.promises.readFile(p)
24+
} catch (err) {
25+
console.error(err)
26+
return
27+
}
28+
}

0 commit comments

Comments
 (0)