1 | const n=(n,...t)=>new Promise(i=>require("child_process").execFile(n,t,{maxBuffer:8388608},(n,t)=>i(String(t||""))))
|
2 | module.exports={getDarwinMainBundleIdHackAsync:async()=>{const t=await(async()=>{const[t,...i]=(await n("/bin/ps","x","-ww","-o","pid,ppid,comm")).split("\n")
|
3 | const[s,e]=(n=>{let t=" "===n.charAt(0)
|
4 | let i=2
|
5 | const s=[]
|
6 | for(let e=0,r=n.length;e<r;e++){if(t!==(" "===n.charAt(e))){t=!t
|
7 | i--
|
8 | if(0===i){s.push(e)
|
9 | i=2}}}return s})(t)
|
10 | const r={}
|
11 | for(const n of i){if(!n)continue
|
12 | const t=parseInt(n.slice(0,s))
|
13 | const i=parseInt(n.slice(s,e))
|
14 | const o=n.slice(e).trim()
|
15 | r[t]={pid:t,ppid:i,comm:o}}return r})()
|
16 | let i=t[process.pid]
|
17 | for(;i&&1!==i.ppid;)i=t[i.ppid]
|
18 | if(!i)throw new Error("missing mainProcessPid")
|
19 | const s=i.comm.trim()
|
20 | const e=s.slice(0,s.indexOf("/Contents/MacOS"))
|
21 | const r=(await n("/usr/bin/defaults","read",`${e}/Contents/Info`,"CFBundleIdentifier")).trim()
|
22 | if(!i)throw new Error("missing mainBundleId")
|
23 | return r}}
|