Skip to content

Commit 4197314

Browse files
committed
chore:run service
1 parent 227220b commit 4197314

File tree

3 files changed

+34
-18
lines changed

3 files changed

+34
-18
lines changed

main.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,6 @@ async def main(self):
224224
True,
225225
url=f"{get_ip_address()}" if open_service else None,
226226
)
227-
if open_service:
228-
run_service()
229227
except asyncio.exceptions.CancelledError:
230228
print("Update cancelled!")
231229

@@ -253,14 +251,23 @@ def scheduled_task():
253251

254252

255253
def run_service():
256-
if not os.environ.get("GITHUB_ACTIONS"):
257-
ip_address = get_ip_address()
258-
print(f"📄 Result detail: {ip_address}/result")
259-
print(f"📄 Log detail: {ip_address}/log")
260-
print(f"✅ You can use this url to watch IPTV 📺: {ip_address}")
261-
app.run(host="0.0.0.0", port=8000)
254+
try:
255+
if not os.environ.get("GITHUB_ACTIONS"):
256+
ip_address = get_ip_address()
257+
print(f"📄 Result detail: {ip_address}/result")
258+
print(f"📄 Log detail: {ip_address}/log")
259+
print(f"✅ You can use this url to watch IPTV 📺: {ip_address}")
260+
app.run(host="0.0.0.0", port=8000)
261+
except Exception as e:
262+
print(f"❌ Service start failed: {e}")
262263

263264

264265
if __name__ == "__main__":
265-
if len(sys.argv) == 1 or (len(sys.argv) > 1 and sys.argv[1] == "scheduled_task"):
266-
scheduled_task()
266+
if len(sys.argv) == 1 and config.open_service:
267+
loop = asyncio.new_event_loop()
268+
269+
async def run_service_async():
270+
loop.run_in_executor(None, run_service)
271+
272+
asyncio.run(run_service_async())
273+
scheduled_task()

tkinter_ui/tkinter_ui.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from PIL import Image, ImageTk
88
from utils.config import config
99
from utils.tools import resource_path
10-
from main import UpdateSource
10+
from main import UpdateSource, run_service
1111
import asyncio
1212
import threading
1313
import webbrowser
@@ -113,11 +113,17 @@ async def run_update(self):
113113
self.progress_label.pack_forget()
114114

115115
def on_run_update(self):
116+
loop = asyncio.new_event_loop()
117+
118+
async def run_service_async():
119+
loop.run_in_executor(None, run_service)
120+
116121
def run_loop():
117-
loop = asyncio.new_event_loop()
118122
asyncio.set_event_loop(loop)
119123
loop.run_until_complete(self.run_update())
120124

125+
if config.open_service:
126+
asyncio.run(run_service_async())
121127
self.thread = threading.Thread(target=run_loop, daemon=True)
122128
self.thread.start()
123129

utils/tools.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -400,12 +400,15 @@ def get_result_file_content(show_result=False):
400400
Get the content of the result file
401401
"""
402402
user_final_file = resource_path(config.final_file)
403-
if config.open_m3u_result:
404-
user_final_file = os.path.splitext(user_final_file)[0] + ".m3u"
405-
if show_result == False:
406-
return send_file(user_final_file, as_attachment=True)
407-
with open(user_final_file, "r", encoding="utf-8") as file:
408-
content = file.read()
403+
if os.path.exists(user_final_file):
404+
if config.open_m3u_result:
405+
user_final_file = os.path.splitext(user_final_file)[0] + ".m3u"
406+
if show_result == False:
407+
return send_file(user_final_file, as_attachment=True)
408+
with open(user_final_file, "r", encoding="utf-8") as file:
409+
content = file.read()
410+
else:
411+
content = "🔍️正在更新,请耐心等待更新完成..."
409412
return render_template_string(
410413
"<head><link rel='icon' href='{{ url_for('static', filename='images/favicon.ico') }}' type='image/x-icon'></head><pre>{{ content }}</pre>",
411414
content=content,

0 commit comments

Comments
 (0)