perf: consolidate notif timeStr timers into one global tick; fix osd open-on-start
This commit is contained in:
parent
9fa2a72a0b
commit
6c37b6640c
4 changed files with 28 additions and 23 deletions
|
|
@ -12,9 +12,12 @@ M.BarSection {
|
||||||
|
|
||||||
property int percent: 0
|
property int percent: 0
|
||||||
property bool _osdActive: false
|
property bool _osdActive: false
|
||||||
|
property bool _ready: false
|
||||||
readonly property bool _showPanel: root._hovered || hoverPanel.panelHovered || _osdActive
|
readonly property bool _showPanel: root._hovered || hoverPanel.panelHovered || _osdActive
|
||||||
|
|
||||||
onPercentChanged: if (percent > 0)
|
Component.onCompleted: _ready = true
|
||||||
|
|
||||||
|
onPercentChanged: if (_ready && percent > 0)
|
||||||
_flashPanel()
|
_flashPanel()
|
||||||
|
|
||||||
function _flashPanel() {
|
function _flashPanel() {
|
||||||
|
|
|
||||||
|
|
@ -29,29 +29,17 @@ QtObject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Relative time string
|
// Relative time string — recomputed whenever NotifService._now ticks (single global 5s timer)
|
||||||
property string timeStr: "now"
|
readonly property string timeStr: {
|
||||||
readonly property Timer _timeStrTimer: Timer {
|
const diff = M.NotifService._now - time;
|
||||||
running: root.state !== "dismissed"
|
|
||||||
repeat: true
|
|
||||||
interval: 5000
|
|
||||||
onTriggered: root._updateTimeStr()
|
|
||||||
}
|
|
||||||
|
|
||||||
function _updateTimeStr() {
|
|
||||||
const diff = Date.now() - time;
|
|
||||||
const m = Math.floor(diff / 60000);
|
const m = Math.floor(diff / 60000);
|
||||||
if (m < 1) {
|
if (m < 1)
|
||||||
timeStr = "now";
|
return "now";
|
||||||
return;
|
|
||||||
}
|
|
||||||
const h = Math.floor(m / 60);
|
const h = Math.floor(m / 60);
|
||||||
if (h < 1) {
|
if (h < 1)
|
||||||
timeStr = m + "m";
|
return m + "m";
|
||||||
return;
|
|
||||||
}
|
|
||||||
const d = Math.floor(h / 24);
|
const d = Math.floor(h / 24);
|
||||||
timeStr = d > 0 ? d + "d" : h + "h";
|
return d > 0 ? d + "d" : h + "h";
|
||||||
}
|
}
|
||||||
|
|
||||||
function beginDismiss() {
|
function beginDismiss() {
|
||||||
|
|
|
||||||
|
|
@ -124,6 +124,15 @@ QtObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Persistence
|
// Persistence
|
||||||
|
// Single global tick for all NotifItem.timeStr bindings — replaces per-item 5s timers
|
||||||
|
property real _now: Date.now()
|
||||||
|
property Timer _nowTimer: Timer {
|
||||||
|
running: root.count > 0
|
||||||
|
repeat: true
|
||||||
|
interval: 5000
|
||||||
|
onTriggered: root._now = Date.now()
|
||||||
|
}
|
||||||
|
|
||||||
property Timer _saveTimer: Timer {
|
property Timer _saveTimer: Timer {
|
||||||
interval: 1000
|
interval: 1000
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
|
|
|
||||||
|
|
@ -39,11 +39,16 @@ M.BarSection {
|
||||||
}
|
}
|
||||||
|
|
||||||
property bool _osdActive: false
|
property bool _osdActive: false
|
||||||
|
property bool _ready: false
|
||||||
readonly property bool _anyHover: root._hovered || hoverPanel.panelHovered
|
readonly property bool _anyHover: root._hovered || hoverPanel.panelHovered
|
||||||
readonly property bool _showPanel: _anyHover || _osdActive
|
readonly property bool _showPanel: _anyHover || _osdActive
|
||||||
|
|
||||||
onVolumeChanged: _flashPanel()
|
Component.onCompleted: _ready = true
|
||||||
onMutedChanged: _flashPanel()
|
|
||||||
|
onVolumeChanged: if (_ready)
|
||||||
|
_flashPanel()
|
||||||
|
onMutedChanged: if (_ready)
|
||||||
|
_flashPanel()
|
||||||
|
|
||||||
function _flashPanel() {
|
function _flashPanel() {
|
||||||
_osdActive = true;
|
_osdActive = true;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue