fix opening log file on macos and linux

This commit is contained in:
dries.k
2022-08-21 17:42:30 +02:00
parent 966b86ce12
commit ff392f96c1
2 changed files with 13 additions and 3 deletions

View File

@@ -1,13 +1,12 @@
import logging import logging
import platform import platform
import os import os
import webbrowser
from gotify_tray.database import Settings from gotify_tray.database import Settings
from gotify_tray.gotify import GotifyMessageModel from gotify_tray.gotify import GotifyMessageModel
from gotify_tray.gui.models import MessagesModelItem from gotify_tray.gui.models import MessagesModelItem
from . import MessageWidget from . import MessageWidget
from gotify_tray.utils import verify_server from gotify_tray.utils import verify_server, open_file
from gotify_tray.tasks import ExportSettingsTask, ImportSettingsTask from gotify_tray.tasks import ExportSettingsTask, ImportSettingsTask
from PyQt6 import QtCore, QtGui, QtWidgets from PyQt6 import QtCore, QtGui, QtWidgets
@@ -157,7 +156,7 @@ class SettingsDialog(QtWidgets.QDialog, Ui_Dialog):
# Logging # Logging
self.combo_logging.currentTextChanged.connect(self.settings_changed_callback) self.combo_logging.currentTextChanged.connect(self.settings_changed_callback)
self.pb_open_log.clicked.connect( self.pb_open_log.clicked.connect(
lambda: webbrowser.open(logger.root.handlers[0].baseFilename) lambda: open_file(logger.root.handlers[0].baseFilename)
) )
# Fonts # Fonts

View File

@@ -1,5 +1,7 @@
import os import os
import platform
import re import re
import subprocess
from pathlib import Path from pathlib import Path
@@ -46,3 +48,12 @@ def get_abs_path(s) -> str:
h = Path(__file__).parent.parent h = Path(__file__).parent.parent
p = Path(s) p = Path(s)
return os.path.join(h, p).replace("\\", "/") return os.path.join(h, p).replace("\\", "/")
def open_file(filename: str):
if platform.system() == "Linux":
subprocess.call(["xdg-open", filename])
elif platform.system() == "Windows":
os.startfile(filename)
elif platform.system() == "Darwin":
subprocess.call(["open", filename])