Font: auto reloading with cache busting.

This commit is contained in:
ItsLemmy
2025-09-24 08:37:29 -04:00
parent 72475cd29b
commit 2e1f6f0323
2 changed files with 63 additions and 29 deletions
+51 -14
View File
@@ -9,16 +9,36 @@ Singleton {
id: root
// Expose the font family name for easy access
readonly property string fontFamily: fontLoader.name
readonly property string fontFamily: currentFontLoader ? currentFontLoader.name : ""
readonly property string defaultIcon: TablerIcons.defaultIcon
readonly property var icons: TablerIcons.icons
readonly property var aliases: TablerIcons.aliases
readonly property string fontPath: "/Assets/Fonts/tabler/tabler-icons.ttf"
// Current active font loader
property FontLoader currentFontLoader: null
property int fontVersion: 0
// Create a unique cache-busting path
readonly property string cacheBustingPath: Quickshell.shellDir + fontPath + "?v=" + fontVersion + "&t=" + Date.now()
// Signal emitted when font is reloaded
signal fontReloaded
Component.onCompleted: {
Logger.log("Icons", "Service started")
loadFontWithCacheBusting()
}
Connections {
target: Quickshell
function onReloadCompleted() {
Logger.log("Icons", "Quickshell reload completed - forcing font reload")
reloadFont()
}
}
// ---------------------------------------
function get(iconName) {
// Check in aliases first
if (aliases[iconName] !== undefined) {
@@ -29,20 +49,37 @@ Singleton {
return icons[iconName]
}
FontLoader {
id: fontLoader
source: Quickshell.shellDir + fontPath
function loadFontWithCacheBusting() {
Logger.log("Icons", "Loading font with cache busting:", cacheBustingPath)
// Destroy old loader first
if (currentFontLoader) {
currentFontLoader.destroy()
currentFontLoader = null
}
// Create new loader with cache-busting URL
currentFontLoader = Qt.createQmlObject(`
import QtQuick
FontLoader {
source: "${cacheBustingPath}"
}
`, root, "dynamicFontLoader_" + fontVersion)
// Connect to the new loader's status changes
currentFontLoader.statusChanged.connect(function () {
if (currentFontLoader.status === FontLoader.Ready) {
Logger.log("Icons", "Font loaded successfully:", currentFontLoader.name, "(version " + fontVersion + ")")
fontReloaded()
} else if (currentFontLoader.status === FontLoader.Error) {
Logger.error("Icons", "Font failed to load (version " + fontVersion + ")")
}
})
}
// Monitor font loading status
Connections {
target: fontLoader
function onStatusChanged() {
if (fontLoader.status === FontLoader.Ready) {
Logger.log("Icons", "Font loaded successfully:", fontFamily)
} else if (fontLoader.status === FontLoader.Error) {
Logger.error("Icons", "Font failed to load")
}
}
function reloadFont() {
Logger.log("Icons", "Forcing font reload...")
fontVersion++
loadFontWithCacheBusting()
}
}
+12 -15
View File
@@ -187,9 +187,7 @@ Singleton {
running: activeList.count > 0
onTriggered: {
const now = Date.now()
const durations = [Settings.data.notifications?.lowUrgencyDuration * 1000 || 3000,
Settings.data.notifications?.normalUrgencyDuration * 1000 || 8000,
Settings.data.notifications?.criticalUrgencyDuration * 1000 || 15000]
const durations = [Settings.data.notifications?.lowUrgencyDuration * 1000 || 3000, Settings.data.notifications?.normalUrgencyDuration * 1000 || 8000, Settings.data.notifications?.criticalUrgencyDuration * 1000 || 15000]
for (var i = activeList.count - 1; i >= 0; i--) {
const notif = activeList.get(i)
@@ -197,9 +195,9 @@ Singleton {
var expire = 0
if (Settings.data.notifications?.respectExpireTimeout)
expire = notif.expireTimeout > 0 ? notif.expireTimeout : durations[notif.urgency]
expire = notif.expireTimeout > 0 ? notif.expireTimeout : durations[notif.urgency]
else
expire = durations[notif.urgency]
expire = durations[notif.urgency]
const progress = Math.max(1.0 - (elapsed / expire), 0.0)
updateModel(activeList, notif.id, "progress", progress)
@@ -288,22 +286,21 @@ Singleton {
}
historyList.append({
"id": item.id || "",
"summary": item.summary || "",
"body": item.body || "",
"appName": item.appName || "",
"urgency": item.urgency < 0 || item.urgency > 2 ? 1 : item.urgency,
"timestamp": time,
"originalImage": item.originalImage || "",
"cachedImage": cachedImage
})
"id": item.id || "",
"summary": item.summary || "",
"body": item.body || "",
"appName": item.appName || "",
"urgency": item.urgency < 0 || item.urgency > 2 ? 1 : item.urgency,
"timestamp": time,
"originalImage": item.originalImage || "",
"cachedImage": cachedImage
})
}
} catch (e) {
Logger.error("Notifications", "Load failed:", e)
}
}
// Helpers
function getAppName(name) {
if (!name?.includes("."))