2
2
3
3
import sys
4
4
import traceback
5
- from typing import TYPE_CHECKING
5
+ from typing import TYPE_CHECKING , overload
6
6
7
7
if TYPE_CHECKING :
8
+ from typing import Literal , NoReturn
9
+
8
10
from pystray import Icon
9
11
10
12
11
- def show_error (exc : Exception , shutdown : bool = True ) -> None :
13
+ @overload
14
+ def show_error (exc : Exception , shutdown : Literal [True ] = True ) -> NoReturn :
15
+ ...
16
+
17
+
18
+ @overload
19
+ def show_error (exc : Exception , shutdown : Literal [False ] = True ) -> None :
20
+ ...
21
+
22
+
23
+ def show_error (exc : Exception , shutdown : bool = True ) -> NoReturn :
12
24
"""
13
25
Create a native pop-up without any third party dependency.
14
26
@@ -51,7 +63,6 @@ def show_error(exc: Exception, shutdown: bool = True) -> None:
51
63
import encodings .idna # noqa: F401 (https://github.com/pyinstaller/pyinstaller/issues/1113)
52
64
import logging .config
53
65
import os
54
- import sys
55
66
import threading
56
67
import typing
57
68
import webbrowser
@@ -65,7 +76,7 @@ def show_error(exc: Exception, shutdown: bool = True) -> None:
65
76
from tribler .tribler_config import VERSION_SUBDIR , TriblerConfigManager
66
77
67
78
except Exception as e :
68
- show_error (e )
79
+ show_error (e , True )
69
80
70
81
logger = logging .getLogger (__name__ )
71
82
@@ -77,6 +88,7 @@ class Arguments(typing.TypedDict):
77
88
78
89
torrent : str
79
90
log_level : str
91
+ server : bool
80
92
81
93
82
94
def parse_args () -> Arguments :
@@ -220,7 +232,7 @@ async def main() -> None:
220
232
torrent_uri = load_torrent_uri (parsed_args )
221
233
server_url = await session .find_api_server ()
222
234
223
- headless = parsed_args .get (' server' )
235
+ headless = parsed_args .get (" server" )
224
236
if server_url :
225
237
logger .info ("Core already running at %s" , server_url )
226
238
if torrent_uri :
@@ -233,17 +245,16 @@ async def main() -> None:
233
245
234
246
await session .start ()
235
247
except Exception as exc :
236
- show_error (exc )
248
+ show_error (exc , True )
237
249
238
250
server_url = await session .find_api_server ()
239
251
if server_url and torrent_uri :
240
252
await start_download (config , server_url , torrent_uri )
241
- if not headless :
242
- icon = spawn_tray_icon (session , config )
253
+ icon = None if headless else spawn_tray_icon (session , config )
243
254
244
255
await session .shutdown_event .wait ()
245
256
await session .shutdown ()
246
- if not headless :
257
+ if icon :
247
258
icon .stop ()
248
259
logger .info ("Tribler shutdown completed" )
249
260
0 commit comments