Show/Hide the main window in KDE when clicking on the tray icon (#143)

This commit is contained in:
Antonio Larrosa 2019-02-01 13:41:40 +01:00 committed by Manuel Riel
parent 3af27d9603
commit 2eac612bd7
2 changed files with 16 additions and 0 deletions

View File

@ -82,6 +82,12 @@ class VortaApp(QApplication):
self.main_window.show()
self.main_window.raise_()
def toggle_main_window_visibility(self):
if self.main_window.isVisible():
self.main_window.hide()
else:
self.open_main_window_action()
def backup_started_event_response(self):
set_tray_icon(self.tray, active=True)

View File

@ -1,3 +1,4 @@
import os
from PyQt5.QtWidgets import QMenu, QSystemTrayIcon
from .borg.borg_thread import BorgThread
@ -16,9 +17,18 @@ class TrayMenu(QSystemTrayIcon):
menu.aboutToShow.connect(self.on_user_click)
self.setContextMenu(menu)
self.activated.connect(self.on_activation)
self.setVisible(True)
self.show()
def on_activation(self, reason):
if reason == QSystemTrayIcon.Trigger:
if os.environ.get('XDG_CURRENT_DESKTOP', '') == 'KDE':
self.app.toggle_main_window_visibility()
else:
self.on_user_click()
def on_user_click(self):
"""Build system tray menu based on current state."""