|
1 | 1 | #!/usr/bin/python3.9
|
2 | 2 | # -*- coding: utf-8 -*-
|
3 |
| -from types import FunctionType |
4 |
| -from typing import Callable, List, Optional |
| 3 | +import traceback |
| 4 | +from types import FunctionType, TracebackType |
| 5 | +from typing import Callable, List, Optional, Type |
5 | 6 |
|
6 | 7 | from copy import copy
|
7 | 8 | from PyQt6 import QtCore, QtGui, QtTest, QtWidgets
|
@@ -1197,22 +1198,47 @@ def exit():
|
1197 | 1198 |
|
1198 | 1199 | def main():
|
1199 | 1200 | app = QtWidgets.QApplication(sys.argv)
|
1200 |
| - app.setWindowIcon(QtGui.QIcon(':/resources/icon.ico')) |
1201 |
| - |
1202 |
| - main_window = AutoSplit() |
1203 |
| - main_window.show() |
1204 |
| - if main_window.actionCheck_for_Updates_on_Open.isChecked(): |
1205 |
| - checkForUpdates(main_window, check_for_updates_on_open=True) |
| 1201 | + try: |
| 1202 | + app.setWindowIcon(QtGui.QIcon(':/resources/icon.ico')) |
| 1203 | + main_window = AutoSplit() |
| 1204 | + main_window.show() |
| 1205 | + # Needs to be after main_window.show() to be shown over |
| 1206 | + if main_window.actionCheck_for_Updates_on_Open.isChecked(): |
| 1207 | + checkForUpdates(main_window, check_for_updates_on_open=True) |
| 1208 | + |
| 1209 | + # Kickoff the event loop every so often so we can handle KeyboardInterrupt (^C) |
| 1210 | + timer = QtCore.QTimer() |
| 1211 | + timer.timeout.connect(lambda: None) |
| 1212 | + timer.start(500) |
| 1213 | + |
| 1214 | + exit_code = app.exec() |
| 1215 | + except Exception as exception: |
| 1216 | + # Print error to console if not running in executable |
| 1217 | + if getattr(sys, 'frozen', False): |
| 1218 | + error_messages.exceptionTraceback( |
| 1219 | + "AutoSplit encountered an unrecoverable exception and will now close itself.<br/>" |
| 1220 | + "Please copy the following message over at<br/>" |
| 1221 | + "<a href='https://github.com/Toufool/Auto-Split/issues'>github.com/Toufool/Auto-Split/issues</a>", |
| 1222 | + exception) |
| 1223 | + else: |
| 1224 | + traceback.print_exception(type(exception), exception, exception.__traceback__) |
| 1225 | + sys.exit(1) |
1206 | 1226 |
|
1207 |
| - # Kickoff the event loop every so often so we can handle KeyboardInterrupt (^C) |
1208 |
| - timer = QtCore.QTimer() |
1209 |
| - timer.timeout.connect(lambda: None) |
1210 |
| - timer.start(500) |
1211 | 1227 | # Catch Keyboard Interrupts for a clean close
|
1212 |
| - signal.signal(signal.SIGINT, lambda _, __: sys.exit(app)) |
| 1228 | + signal.signal(signal.SIGINT, lambda _, __: sys.exit(exit_code)) |
| 1229 | + |
| 1230 | + sys.exit(exit_code) |
| 1231 | + |
1213 | 1232 |
|
1214 |
| - sys.exit(app.exec()) |
| 1233 | +def excepthook(type: Type[BaseException], exception: BaseException, traceback: Optional[TracebackType]): |
| 1234 | + error_messages.exceptionTraceback( |
| 1235 | + "AutoSplit encountered an unhandled exception and will try to recover, " |
| 1236 | + "however, things may not work quite right.<br/>" |
| 1237 | + "Please copy the following message over at<br/>" |
| 1238 | + "<a href='https://github.com/Toufool/Auto-Split/issues'>github.com/Toufool/Auto-Split/issues</a>", |
| 1239 | + exception) |
1215 | 1240 |
|
1216 | 1241 |
|
1217 | 1242 | if __name__ == '__main__':
|
| 1243 | + sys.excepthook = excepthook |
1218 | 1244 | main()
|
0 commit comments