Skip to content

Commit ff49f8e

Browse files
authored
Merge pull request #153 from MathNodes/2.0v12
May 2026 PR
2 parents bd99edb + 375e9ad commit ff49f8e

13 files changed

Lines changed: 1339 additions & 792 deletions

File tree

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ rsa==4.9
8686
safe-pysha3==1.0.4
8787
screeninfo==0.8.1
8888
SecretStorage==3.3.3
89-
sentinel-sdk==0.1.1
9089
sentinel_protobuf==0.5.1
90+
sentinel_sdk==0.1.4
9191
six==1.16.0
9292
sniffio==1.3.1
9393
stripe==4.2.0

src/bin/routes.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ if [[ ${STATE} = "up" ]]; then
2121
# start v2ray
2222
echo "Running xray: /home/${USER}/.meile-gui/bin/v2ray run -c /home/${USER}/.meile-gui/v2ray_config.json &"
2323
/home/${USER}/.meile-gui/bin/xray run -c /home/${USER}/.meile-gui/v2ray_config.json &
24-
sleep 3
24+
sleep 1
2525

2626
# get v2ray proxy IP
2727
PROXY_IP=`cat /home/${USER}/.meile-gui/v2ray.proxy`
2828
#echo ${PROXY_IP} > /home/${USER}/.meile-gui/v2ray.proxy
2929
echo "Proxy IP: ${PROXY_IP}"
30-
sleep 2
30+
sleep 1
3131

3232
# add tun interface
3333
TUNID=${RANDOM}
@@ -64,7 +64,7 @@ if [[ ${STATE} = "up" ]]; then
6464
echo "Routing table: "
6565
ip route show
6666

67-
sleep 3
67+
sleep 1
6868
echo "-----------------------_CURLING_---------------------------"
6969
curl https://icanhazip.com
7070
else

src/bin/sentinelcli

-42 MB
Binary file not shown.

src/cli/v2ray.py

Lines changed: 58 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
from dataclasses import dataclass
77
import sys
88
import os
9+
import tempfile
10+
import socket, time
911

1012
from conf.meile_config import MeileGuiConfig
13+
from helpers.helpers import wait_for_port
1114

1215
# Platform-conditional imports
1316
if sys.platform == 'win32':
@@ -22,6 +25,7 @@
2225
elif sys.platform.startswith('linux'):
2326
import psutil
2427
from typedef.konstants import ConfParams
28+
import threading
2529

2630
# ---------------------------------------------------------------------------
2731
# V2RayHandler – one class per platform, selected at the bottom of this
@@ -50,15 +54,47 @@ def fork_v2ray(self):
5054

5155
self.v2ray_pid = v2ray_srvc_proc.pid
5256

57+
58+
5359
def start_daemon(self):
60+
'''
5461
5562
print("Starting v2ray service...")
5663
5764
multiprocessing.get_context('fork')
5865
warp_fork = Process(target=self.fork_v2ray)
5966
warp_fork.run()
60-
sleep(1.5)
61-
return True
67+
ok = wait_for_port(host="127.0.0.1", port=1080, timeout=120)
68+
if ok:
69+
return True
70+
else:
71+
return False
72+
'''
73+
print("Starting v2ray service...")
74+
75+
try:
76+
self.fork_v2ray()
77+
except Exception as e:
78+
print(f"[start_daemon] fork_v2ray failed: {e!r}")
79+
return False
80+
81+
result = {"ok": False}
82+
83+
def worker():
84+
try:
85+
result["ok"] = wait_for_port("127.0.0.1", 1080, timeout=120)
86+
except Exception as e:
87+
print(f"[start_daemon] worker error: {e!r}")
88+
result["ok"] = False
89+
90+
t = threading.Thread(target=worker, daemon=True)
91+
t.start()
92+
93+
while t.is_alive():
94+
print(".", end="", flush=True)
95+
time.sleep(0.3)
96+
97+
return result["ok"]
6298

6399
def kill_daemon(self):
64100
v2ray_daemon_cmd = (
@@ -253,8 +289,8 @@ def read_v2ray_config(self):
253289
class _DarwinV2RayHandler:
254290
v2ray_pid = 0
255291

256-
def __init__(self, script, **kwargs):
257-
self.script_path = script
292+
def __init__(self, script_path, **kwargs):
293+
self.script_path = script_path
258294
self.processes = []
259295
self.MeileConfig = MeileGuiConfig()
260296

@@ -325,25 +361,33 @@ def run_cmd(self, cmd, background=False):
325361

326362
def start_daemon(self):
327363
print("Starting v2ray service...")
364+
PLIST_DIR = os.path.expanduser("~/.meile-gui/launchd")
365+
xray_plist = f"{PLIST_DIR}/app.meile.xray.plist"
366+
tun2_plist = f"{PLIST_DIR}/app.meile.tun2socks.plist"
328367

329368
privileged_commands = [
330-
"launchctl bootstrap system"
331-
" /Library/LaunchDaemons/app.meile.xray.plist"
369+
'mkdir -p "/Library/Application Support/Meile/launchd"',
370+
f'cp "{xray_plist}" "/Library/Application Support/Meile/launchd/"',
371+
f'cp "{tun2_plist}" "/Library/Application Support/Meile/launchd/"',
372+
'chown -R root:wheel "/Library/Application Support/Meile"',
373+
'chmod 755 "/Library/Application Support/Meile" "/Library/Application Support/Meile/launchd"',
374+
'chmod 644 "/Library/Application Support/Meile/launchd/"*.plist',
375+
"rm -rf /Library/LaunchDaemons/app.meile.tun2socks.plist",
376+
"rm -rf /Library/LaunchDaemons/app.meile.wireguard.plist",
377+
"rm -rf /Library/LaunchDaemons/app.meile.xray.plist",
378+
"launchctl enable system/app.meile.xray",
379+
'launchctl bootstrap system "/Library/Application Support/Meile/launchd/app.meile.xray.plist"',
332380
]
333381
privileged_commands.append("sleep 3")
334382
privileged_commands.append(
335383
"curl --preproxy socks5://localhost:1080"
336384
" -s https://icanhazip.com"
337385
)
338386
privileged_commands.append("sleep 1")
339-
privileged_commands.append(
340-
"launchctl bootstrap system"
341-
" /Library/LaunchDaemons/app.meile.tun2socks.plist"
342-
)
387+
privileged_commands.append(f"launchctl enable system/app.meile.tun2socks")
388+
privileged_commands.append(f'launchctl bootstrap system "/Library/Application Support/Meile/launchd/app.meile.tun2socks.plist"')
343389
privileged_commands.append("sleep 2")
344-
privileged_commands.append(
345-
"ifconfig utun123 198.18.0.1 198.18.0.1 up"
346-
)
390+
privileged_commands.append("ifconfig utun123 198.18.0.1 198.18.0.1 up")
347391

348392
networks = [
349393
"1.0.0.0/8",
@@ -391,12 +435,7 @@ def kill_daemon(self):
391435
privileged_commands.append(
392436
"ifconfig utun123 198.18.0.1 198.18.0.1 down"
393437
)
394-
privileged_commands.append(
395-
"launchctl bootout system"
396-
" /Library/LaunchDaemons/app.meile.xray.plist"
397-
" ; launchctl bootout system"
398-
" /Library/LaunchDaemons/app.meile.tun2socks.plist"
399-
)
438+
privileged_commands.append(f'launchctl bootout system "/Library/Application Support/Meile/launchd/app.meile.xray.plist" ; launchctl bootout system "/Library/Application Support/Meile/launchd/app.meile.tun2socks.plist" ; launchctl disable system/app.meile.xray ; launchctl disable system/app.meile.tun2socks')
400439

401440
self.run_privileged_script(privileged_commands)
402441

0 commit comments

Comments
 (0)