|
|
@@ -7,6 +7,7 @@ from datetime import datetime
|
|
|
from src.services.proxy_manager import ProxyManager
|
|
|
from utils.config import PROXY_POLL_DIR,config,Sub,Proxy,Config
|
|
|
from utils.mihomo import get_sub,update_config,save_yaml_dump,find_free_port
|
|
|
+from utils.logu import get_logger,logger
|
|
|
|
|
|
class SubscriptionManager:
|
|
|
"""管理订阅的生命周期,包括下载、更新、启动、停止等操作"""
|
|
|
@@ -78,6 +79,7 @@ class SubscriptionManager:
|
|
|
proxy:Proxy = self.sub.proxies.get(port)
|
|
|
if not proxy:
|
|
|
return False
|
|
|
+ proxy.startup = True
|
|
|
self.list_proxies_mgr[port] = ProxyManager(self.config.mimo_exe, proxy.file_path)
|
|
|
return await self.list_proxies_mgr[port].start_proxy()
|
|
|
|
|
|
@@ -88,6 +90,7 @@ class SubscriptionManager:
|
|
|
proxy:Proxy = self.sub.proxies.get(port)
|
|
|
if not proxy:
|
|
|
return False
|
|
|
+ proxy.startup = False
|
|
|
self.list_proxies_mgr[port] = ProxyManager(self.config.mimo_exe, proxy.file_path)
|
|
|
return await self.list_proxies_mgr[port].stop_proxy()
|
|
|
|
|
|
@@ -121,4 +124,20 @@ class SubscriptionManager:
|
|
|
return self.save_config()
|
|
|
|
|
|
def get_proxy_manager(self, port: int) -> ProxyManager:
|
|
|
- return self.list_proxies_mgr.get(port)
|
|
|
+ return self.list_proxies_mgr.get(port)
|
|
|
+
|
|
|
+ def save_startup(self, auto_start: bool = False):
|
|
|
+ self.sub.auto_start = auto_start
|
|
|
+ for proxy in self.sub.proxies.values():
|
|
|
+ if self.get_proxy_manager(proxy.port).running:
|
|
|
+ proxy.startup = True
|
|
|
+ return self.save_config()
|
|
|
+
|
|
|
+ async def startup(self):
|
|
|
+ if not self.sub.auto_start:
|
|
|
+ return
|
|
|
+ for proxy in self.sub.proxies.values():
|
|
|
+ if proxy.startup:
|
|
|
+ logger.info(f"{proxy.port} 自动启动")
|
|
|
+ self.select_proxy(proxy.port, proxy.name)
|
|
|
+ await self.start_proxy(proxy.port)
|