Add config option closeMinimizesToTray

Options of the system tray icon:
- Hide/show Mirage
- Quit Mirage

Draw attention to Mirage when clicking on the icon
This commit is contained in:
vslg 2020-09-04 15:31:17 -03:00
parent 6061b2f061
commit 56ad0b9975
3 changed files with 31 additions and 3 deletions

View File

@ -273,6 +273,7 @@ class UISettings(JSONDataFile):
"clearRoomFilterOnEnter": True, "clearRoomFilterOnEnter": True,
"clearRoomFilterOnEscape": True, "clearRoomFilterOnEscape": True,
"clearMemberFilterOnEscape": True, "clearMemberFilterOnEscape": True,
"closeMinimizesToTray": False,
"collapseSidePanesUnderWindowWidth": 450, "collapseSidePanesUnderWindowWidth": 450,
"enableKineticScrolling": True, "enableKineticScrolling": True,
"hideProfileChangeEvents": True, "hideProfileChangeEvents": True,

View File

@ -23,6 +23,7 @@ ApplicationWindow {
property var uiState: ({}) property var uiState: ({})
property var history: ({}) property var history: ({})
property var theme: null property var theme: null
property bool closing: false
readonly property var visibleMenus: ({}) readonly property var visibleMenus: ({})
readonly property var visiblePopups: ({}) readonly property var visiblePopups: ({})
@ -65,6 +66,11 @@ ApplicationWindow {
) )
} }
function drawAttention() {
window.show()
window.raise()
window.requestActivate()
}
flags: Qt.WA_TranslucentBackground flags: Qt.WA_TranslucentBackground
@ -81,6 +87,11 @@ ApplicationWindow {
onUiStateChanged: py.saveConfig("ui_state", uiState) onUiStateChanged: py.saveConfig("ui_state", uiState)
onHistoryChanged: py.saveConfig("history", history) onHistoryChanged: py.saveConfig("history", history)
onClosing: {
close.accepted = ! settings.closeMinimizesToTray
onTriggered: if (settings.closeMinimizesToTray) hide()
}
PythonRootBridge { id: py } PythonRootBridge { id: py }
Utils { id: utils } Utils { id: utils }
@ -109,12 +120,25 @@ ApplicationWindow {
tooltip: qsTr("Mirage") tooltip: qsTr("Mirage")
icon.source: `../icons/${iconPack}/tray-icon.png` icon.source: `../icons/${iconPack}/tray-icon.png`
onActivated: window.show() onActivated:
if (reason !== SystemTrayIcon.Context)
window.drawAttention()
menu: Menu { menu: Menu {
MenuItem { MenuItem {
text: qsTr("Quit") text: window.visible ? "Hide Mirage" : "Show Mirage"
onTriggered: window.hide() onTriggered:
window.visible ?
window.hide() :
window.drawAttention()
}
MenuItem {
text: qsTr("Quit Mirage")
onTriggered: {
Qt.quit()
}
} }
} }
} }

View File

@ -180,6 +180,9 @@ int main(int argc, char *argv[]) {
QQmlEngine engine; QQmlEngine engine;
QQmlContext *objectContext = new QQmlContext(engine.rootContext()); QQmlContext *objectContext = new QQmlContext(engine.rootContext());
// For being able to use Qt.quit() in QML side
QObject::connect(&engine, &QQmlEngine::quit, &QApplication::quit);
// Set the debugMode properties depending of if we're running in debug mode // Set the debugMode properties depending of if we're running in debug mode
// or not (`qmake CONFIG+=dev ...`, default in live-reload.sh) // or not (`qmake CONFIG+=dev ...`, default in live-reload.sh)
#ifdef QT_DEBUG #ifdef QT_DEBUG