diff --git a/src/path.ts b/src/path.ts index 396a70a..c412af5 100644 --- a/src/path.ts +++ b/src/path.ts @@ -1,24 +1,16 @@ -import { app } from 'electron' -import { platform } from 'os' -import { join, parse, resolve } from 'path' +import { existsSync } from 'fs' +import { join, sep } from 'path' export function resolvePath(path: string) { - if (platform() === 'win32') { - if (process.execPath.includes('node_modules')) { - return join(process.execPath.split('node_modules')[0], path) - } - const parsedPath = parse(process.execPath) - return join(parsedPath.dir, path) - } - if (process.execPath.includes('node_modules/electron/dist/Electron.app')) { - return resolve(path) - } - const appName = `${app.getName()}.app` - let execPath = process.execPath + const origin = process.execPath + const parts = origin.split(sep) + while (parts.length) { + const currentPath = join(sep, ...parts, path) - if (execPath.includes(appName)) { - execPath = execPath.split(appName)[0] + if (existsSync(currentPath)) { + return currentPath + } + parts.pop() } - - return join(execPath, path) + throw Error(`Path ${path} is not found`) }