moment/src/gui/TrayIcon.qml

59 lines
1.6 KiB
QML
Raw Normal View History

// Copyright Mirage authors & contributors <https://github.com/mirukana/mirage>
2020-09-06 02:06:47 +10:00
// SPDX-License-Identifier: LGPL-3.0-or-later
import QtQuick.Controls 2.12
2020-09-06 02:06:47 +10:00
import Qt.labs.platform 1.1
import Qt.labs.folderlistmodel 2.12
SystemTrayIcon {
property ApplicationWindow window
2020-09-06 02:06:47 +10:00
property alias settingsFolder: showUpWatcher.folder
property string iconPack: theme ? theme.icons.preferredPack : "thin"
2020-09-06 02:06:47 +10:00
property FolderListModel showUpWatcher: FolderListModel {
id: showUpWatcher
showDirs: false
showHidden: true
nameFilters: [".show"]
onCountChanged: {
if (count) {
window.restoreFromTray()
2020-09-06 02:06:47 +10:00
py.importModule("os", () => {
py.call("os.remove", [get(0, "filePath")])
})
}
}
}
visible: true
tooltip: Qt.application.displayName
icon.source: `../icons/${iconPack}/tray-icon.png`
2020-09-06 02:06:47 +10:00
onActivated: {
if (reason === SystemTrayIcon.MiddleClick)
Qt.quit()
else if (reason !== SystemTrayIcon.Context)
window.visible ? window.hide() : window.restoreFromTray()
}
2020-09-06 02:06:47 +10:00
menu: Menu {
MenuItem {
text:
window.visible ?
"Minimize to tray" :
qsTr("Open %1").arg(Qt.application.displayName)
2020-09-06 02:06:47 +10:00
onTriggered:
window.visible ?
window.hide() :
window.restoreFromTray()
2020-09-06 02:06:47 +10:00
}
MenuItem {
text: qsTr("Quit %1").arg(Qt.application.displayName)
2020-09-06 02:06:47 +10:00
onTriggered: Qt.quit()
}
}
}