Move system tray icon code to its file
This commit is contained in:
parent
9ee4b14aa2
commit
bde7af8a5a
52
src/gui/Base/HTrayIcon.qml
Normal file
52
src/gui/Base/HTrayIcon.qml
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
||||||
|
|
||||||
|
import Qt.labs.platform 1.1
|
||||||
|
import Qt.labs.folderlistmodel 2.12
|
||||||
|
|
||||||
|
SystemTrayIcon {
|
||||||
|
property string iconPack: theme ? theme.icons.preferredPack : "thin"
|
||||||
|
property alias settingsFolder: showUpWatcher.folder
|
||||||
|
|
||||||
|
property var window
|
||||||
|
|
||||||
|
property FolderListModel showUpWatcher: FolderListModel {
|
||||||
|
id: showUpWatcher
|
||||||
|
showDirs: false
|
||||||
|
showHidden: true
|
||||||
|
nameFilters: [".show"]
|
||||||
|
|
||||||
|
onCountChanged: {
|
||||||
|
if (count) {
|
||||||
|
window.drawAttention()
|
||||||
|
py.importModule("os", () => {
|
||||||
|
py.call("os.remove", [get(0, "filePath")])
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
visible: true
|
||||||
|
tooltip: qsTr("Mirage")
|
||||||
|
icon.source: `../../icons/${iconPack}/tray-icon.png`
|
||||||
|
|
||||||
|
onActivated:
|
||||||
|
if (reason !== SystemTrayIcon.Context)
|
||||||
|
window.drawAttention()
|
||||||
|
|
||||||
|
|
||||||
|
menu: Menu {
|
||||||
|
MenuItem {
|
||||||
|
text: window.visible ? "Hide Mirage" : "Show Mirage"
|
||||||
|
onTriggered:
|
||||||
|
window.visible ?
|
||||||
|
window.hide() :
|
||||||
|
window.drawAttention()
|
||||||
|
}
|
||||||
|
|
||||||
|
MenuItem {
|
||||||
|
text: qsTr("Quit Mirage")
|
||||||
|
onTriggered: Qt.quit()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
import QtQuick 2.12
|
import QtQuick 2.12
|
||||||
import QtQuick.Controls 2.12
|
import QtQuick.Controls 2.12
|
||||||
import Qt.labs.platform 1.1
|
|
||||||
import Qt.labs.folderlistmodel 2.12
|
|
||||||
import "Base"
|
import "Base"
|
||||||
import "PythonBridge"
|
import "PythonBridge"
|
||||||
|
|
||||||
@ -90,7 +88,7 @@ ApplicationWindow {
|
|||||||
|
|
||||||
onClosing: {
|
onClosing: {
|
||||||
close.accepted = ! settings.closeMinimizesToTray
|
close.accepted = ! settings.closeMinimizesToTray
|
||||||
onTriggered: if (settings.closeMinimizesToTray) hide()
|
if (settings.closeMinimizesToTray) hide()
|
||||||
}
|
}
|
||||||
|
|
||||||
PythonRootBridge { id: py }
|
PythonRootBridge { id: py }
|
||||||
@ -114,50 +112,8 @@ ApplicationWindow {
|
|||||||
Behavior on scale { HNumberAnimation { overshoot: 3; factor: 1.2 } }
|
Behavior on scale { HNumberAnimation { overshoot: 3; factor: 1.2 } }
|
||||||
}
|
}
|
||||||
|
|
||||||
SystemTrayIcon {
|
HTrayIcon {
|
||||||
property string iconPack: theme ? theme.icons.preferredPack : "thin"
|
window: window
|
||||||
|
settingsFolder: configDir
|
||||||
visible: true
|
|
||||||
tooltip: qsTr("Mirage")
|
|
||||||
icon.source: `../icons/${iconPack}/tray-icon.png`
|
|
||||||
|
|
||||||
onActivated:
|
|
||||||
if (reason !== SystemTrayIcon.Context)
|
|
||||||
window.drawAttention()
|
|
||||||
|
|
||||||
|
|
||||||
menu: Menu {
|
|
||||||
MenuItem {
|
|
||||||
text: window.visible ? "Hide Mirage" : "Show Mirage"
|
|
||||||
onTriggered:
|
|
||||||
window.visible ?
|
|
||||||
window.hide() :
|
|
||||||
window.drawAttention()
|
|
||||||
}
|
|
||||||
|
|
||||||
MenuItem {
|
|
||||||
text: qsTr("Quit Mirage")
|
|
||||||
onTriggered: {
|
|
||||||
Qt.quit()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
FolderListModel {
|
|
||||||
id: showUpWatcher
|
|
||||||
folder: window.configDir
|
|
||||||
showDirs: false
|
|
||||||
showHidden: true
|
|
||||||
nameFilters: [".show"]
|
|
||||||
|
|
||||||
onCountChanged: {
|
|
||||||
if (count) {
|
|
||||||
window.drawAttention()
|
|
||||||
py.importModule("os", () => {
|
|
||||||
py.call("os.remove", [get(0, "filePath")])
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user