@dns-data/remote 0.2.10 → 0.2.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,6 +12,12 @@ const CONTENT = Object.freeze({
12
12
  darwin: '#!/bin/zsh\n' +
13
13
  'cd "$HOME"\n' +
14
14
  'export PATH="$HOME/.local/bin:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:$PATH"\n' +
15
+ 'if /usr/sbin/lsof -nP -iTCP:18761 -sTCP:LISTEN 2>/dev/null | /usr/bin/grep -q "dns-data-"; then\n' +
16
+ ' if /usr/bin/curl --noproxy "*" --silent --fail --max-time 2 http://127.0.0.1:18761/ | /usr/bin/grep -q "DNS-DATA"; then\n' +
17
+ ' /usr/bin/open http://127.0.0.1:18761/\n' +
18
+ ' exit 0\n' +
19
+ ' fi\n' +
20
+ 'fi\n' +
15
21
  'exec npx -y @dns-data/remote@latest\n',
16
22
  win32: '@echo off\r\n' +
17
23
  'cd /d "%USERPROFILE%"\r\n' +
package/bin/dns-data.js CHANGED
@@ -90,15 +90,62 @@ if(args.length===0 || (args.length===1 && (args[0]==='--start' || args[0]==='--p
90
90
  console.warn('[WARN] DNS-DATA desktop launcher: '+e.message);
91
91
  }
92
92
  }
93
- console.log('DNS-DATA Remote Connection - V2');
94
- const child=spawn(runtimeBinary,args,{stdio:'inherit',shell:false,windowsHide:false,env:process.env});
95
- let done=false;
96
- function finish(code){
97
- if(done)return;done=true;
98
- process.exitCode=code;
93
+ // Reusing an existing macOS session must not attempt another native agent.
94
+ // The panel is bound to loopback and is verified before opening. No impact
95
+ // on Windows, diagnostic commands, pairing or direct LAN transfers.
96
+ // An immediately preceding browser navigation or listener startup may make
97
+ // the first probe transiently fail. Retry before attempting another session.
98
+ async function activeMacPanel(){
99
+ for(let attempt=0;attempt<3;attempt++){
100
+ if(await probeMacPanelOnce())return true;
101
+ if(attempt<2)await new Promise(resolve=>setTimeout(resolve,180));
102
+ }
103
+ return false;
104
+ }
105
+ function probeMacPanelOnce(){
106
+ return new Promise(resolve=>{
107
+ const http=require('http');
108
+ let finished=false;
109
+ const complete=ok=>{if(!finished){finished=true;resolve(ok);}};
110
+ const req=http.get({
111
+ hostname:'127.0.0.1',port:18761,path:'/',timeout:1500,
112
+ headers:{Host:'127.0.0.1:18761'}
113
+ },res=>{
114
+ if(res.statusCode!==200){res.resume();complete(false);return;}
115
+ let body='';
116
+ res.setEncoding('utf8');
117
+ res.on('data',chunk=>{
118
+ body+=chunk;
119
+ if(body.length>16384){req.destroy();complete(false);}
120
+ });
121
+ res.on('end',()=>complete(body.includes('<title>DNS-DATA · 统一记忆</title>') &&
122
+ body.includes('id="navigation"') &&
123
+ String(res.headers['content-security-policy']||'').includes("default-src 'none'")));
124
+ res.on('error',()=>complete(false));
125
+ });
126
+ req.on('timeout',()=>req.destroy(new Error('panel probe timeout')));
127
+ req.on('error',()=>complete(false));
128
+ });
129
+ }
130
+ function launchNative(){
131
+ console.log('DNS-DATA Remote Connection - V2');
132
+ const child=spawn(runtimeBinary,args,{stdio:'inherit',shell:false,windowsHide:false,env:process.env});
133
+ let done=false;
134
+ function finish(code){if(done)return;done=true;process.exitCode=code;}
135
+ child.once('error',e=>{console.error('[ERROR] V2 launcher: '+e.message);finish(1);});
136
+ child.once('exit',(code,signal)=>finish(code===null?(signal==='SIGINT'?130:1):code));
137
+ for(const sig of ['SIGINT','SIGTERM','SIGHUP']){
138
+ try{process.on(sig,()=>{if(process.platform!=='win32'&&!child.killed)child.kill(sig);});}catch(_){}
139
+ }
99
140
  }
100
- child.once('error',e=>{console.error('[ERROR] V2 launcher: '+e.message);finish(1);});
101
- child.once('exit',(code,signal)=>finish(code===null?(signal==='SIGINT'?130:1):code));
102
- for(const sig of ['SIGINT','SIGTERM','SIGHUP']){
103
- try{process.on(sig,()=>{if(process.platform!=='win32'&&!child.killed)child.kill(sig);});}catch(_){}
141
+ if(process.platform==='darwin' && (args.length===0 || (args.length===1&&args[0]==='--start'))){
142
+ activeMacPanel().then(active=>{
143
+ if(!active){launchNative();return;}
144
+ const url='http://127.0.0.1:18761/';
145
+ console.log('DNS-DATA already running. Local management page: '+url);
146
+ // Do not open another browser tab when npm is invoked repeatedly.
147
+ // The desktop shortcut remains the explicit Open UI action.
148
+ }).catch(()=>launchNative());
149
+ }else{
150
+ launchNative();
104
151
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dns-data/remote",
3
- "version": "0.2.10",
3
+ "version": "0.2.11",
4
4
  "description": "DNS-DATA native Windows and macOS launcher with automatic npm desktop shortcuts and LAN Direct v3",
5
5
  "license": "UNLICENSED",
6
6
  "private": false,