forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresolveHelperPath.ts
More file actions
28 lines (27 loc) · 1.04 KB
/
Copy pathresolveHelperPath.ts
File metadata and controls
28 lines (27 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { app } from 'electron'
import { join } from 'path'
import { existsSync } from 'fs'
/**
* Resolve the on-disk path to the bundled win-ocr-helper.exe.
*
* Locations, in priority order:
* 1. Packaged via `asarUnpack: resources/**`:
* `<resourcesPath>/app.asar.unpacked/resources/win-ocr-helper/win-ocr-helper.exe`
* 2. Packaged via extraResources:
* `<resourcesPath>/win-ocr-helper/win-ocr-helper.exe`
* 3. Dev (electron-vite): `<appPath>/resources/win-ocr-helper/win-ocr-helper.exe`
*/
export function resolveHelperPath(): string {
const exe = 'win-ocr-helper.exe'
const candidates = [
join(process.resourcesPath, 'app.asar.unpacked', 'resources', 'win-ocr-helper', exe),
join(process.resourcesPath, 'win-ocr-helper', exe),
join(app.getAppPath(), 'resources', 'win-ocr-helper', exe)
]
for (const c of candidates) {
if (existsSync(c)) return c
}
// Return the dev path so the supervisor surfaces a clear "helper not found"
// error rather than spawning a nonexistent path.
return candidates[candidates.length - 1]
}