58
src/gui/TrayIcon.qml
Normal file
58
src/gui/TrayIcon.qml
Normal file
@@ -0,0 +1,58 @@
|
||||
// SPDX-License-Identifier: LGPL-3.0-or-later
|
||||
|
||||
import QtQuick.Controls 2.12
|
||||
import Qt.labs.platform 1.1
|
||||
import Qt.labs.folderlistmodel 2.12
|
||||
|
||||
SystemTrayIcon {
|
||||
property ApplicationWindow window
|
||||
property alias settingsFolder: showUpWatcher.folder
|
||||
|
||||
property string iconPack: theme ? theme.icons.preferredPack : "thin"
|
||||
|
||||
property FolderListModel showUpWatcher: FolderListModel {
|
||||
id: showUpWatcher
|
||||
showDirs: false
|
||||
showHidden: true
|
||||
nameFilters: [".show"]
|
||||
|
||||
onCountChanged: {
|
||||
if (count) {
|
||||
window.restoreFromTray()
|
||||
py.importModule("os", () => {
|
||||
py.call("os.remove", [get(0, "filePath")])
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
visible: true
|
||||
tooltip: Qt.application.displayName
|
||||
icon.source: `../icons/${iconPack}/tray-icon.png`
|
||||
|
||||
onActivated: {
|
||||
if (reason === SystemTrayIcon.MiddleClick)
|
||||
Qt.quit()
|
||||
else if (reason !== SystemTrayIcon.Context)
|
||||
window.visible ? window.hide() : window.restoreFromTray()
|
||||
}
|
||||
|
||||
menu: Menu {
|
||||
MenuItem {
|
||||
text:
|
||||
window.visible ?
|
||||
"Minimize to tray" :
|
||||
qsTr("Open %1").arg(Qt.application.displayName)
|
||||
onTriggered:
|
||||
window.visible ?
|
||||
window.hide() :
|
||||
window.restoreFromTray()
|
||||
}
|
||||
|
||||
MenuItem {
|
||||
text: qsTr("Quit %1").arg(Qt.application.displayName)
|
||||
onTriggered: Qt.quit()
|
||||
}
|
||||
}
|
||||
}
|
@@ -22,6 +22,7 @@ ApplicationWindow {
|
||||
property var uiState: ({})
|
||||
property var history: ({})
|
||||
property var theme: null
|
||||
property string settingsFolder
|
||||
|
||||
readonly property var visibleMenus: ({})
|
||||
readonly property var visiblePopups: ({})
|
||||
@@ -64,6 +65,11 @@ ApplicationWindow {
|
||||
)
|
||||
}
|
||||
|
||||
function restoreFromTray() {
|
||||
window.show()
|
||||
window.raise()
|
||||
window.requestActivate()
|
||||
}
|
||||
|
||||
|
||||
flags: Qt.WA_TranslucentBackground
|
||||
@@ -80,6 +86,11 @@ ApplicationWindow {
|
||||
onUiStateChanged: py.saveConfig("ui_state", uiState)
|
||||
onHistoryChanged: py.saveConfig("history", history)
|
||||
|
||||
onClosing: {
|
||||
close.accepted = ! settings.closeMinimizesToTray
|
||||
settings.closeMinimizesToTray ? hide() : Qt.quit()
|
||||
}
|
||||
|
||||
PythonRootBridge { id: py }
|
||||
|
||||
Utils { id: utils }
|
||||
@@ -100,4 +111,9 @@ ApplicationWindow {
|
||||
|
||||
Behavior on scale { HNumberAnimation { overshoot: 3; factor: 1.2 } }
|
||||
}
|
||||
|
||||
TrayIcon {
|
||||
window: window
|
||||
settingsFolder: window.settingsFolder
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user