refractor favicon

This commit is contained in:
end-4 2025-05-27 20:09:46 +02:00
parent 5402893c16
commit 7bd910bb44
4 changed files with 77 additions and 44 deletions

View file

@ -0,0 +1,59 @@
import "root:/modules/common"
import "root:/modules/common/widgets"
import "root:/services"
import "root:/modules/common/functions/string_utils.js" as StringUtils
import "root:/modules/common/functions/file_utils.js" as FileUtils
import Qt5Compat.GraphicalEffects
import Qt.labs.platform
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import Quickshell.Io
import Quickshell.Widgets
import Quickshell.Hyprland
IconImage {
id: root
property string url
property real size: 32
property string downloadUserAgent: ConfigOptions?.networking.userAgent ?? ""
property string faviconDownloadPath: FileUtils.trimFileProtocol(`${XdgDirectories.cache}/media/favicons`)
property string domainName: url.includes("vertexaisearch") ? displayText : StringUtils.getBaseUrl(url)
property string faviconUrl: `https://www.google.com/s2/favicons?domain=${domainName}&sz=32`
property string fileName: `${domainName}.ico`
property string faviconFilePath: `${faviconDownloadPath}/${fileName}`
Process {
id: faviconDownloadProcess
running: false
command: ["bash", "-c", `[ -f ${faviconFilePath} ] || curl -s '${root.faviconUrl}' -o '${faviconFilePath}' -L -H 'User-Agent: ${downloadUserAgent}'`]
onExited: (exitCode, exitStatus) => {
console.log("Favicon download process exited with code:", exitCode, "and status:", exitStatus)
console.log("Favicon file path:", faviconFilePath)
root.faviconUrl = root.faviconFilePath
}
}
Component.onCompleted: {
console.log("faviconDownloadPath: ", faviconDownloadPath)
console.log("faviconFilePath: ", faviconFilePath)
console.log("faviconUrl: ", root.faviconUrl)
console.log("domainName: ", root.domainName)
console.log("fileName: ", root.fileName)
console.log("downloading to ", faviconFilePath, "from", root.faviconUrl)
faviconDownloadProcess.running = true
}
source: Qt.resolvedUrl(root.faviconUrl)
implicitSize: root.size
layer.enabled: true
layer.effect: OpacityMask {
maskSource: Rectangle {
width: root.implicitSize
height: root.implicitSize
radius: Appearance.rounding.full
}
}
}

View file

@ -19,7 +19,6 @@ Item {
property var panelWindow
property var inputField: messageInputField
property string commandPrefix: "/"
property string faviconDownloadPath: FileUtils.trimFileProtocol(`${XdgDirectories.cache}/media/favicons`)
property var suggestionQuery: ""
property var suggestionList: []
@ -203,7 +202,6 @@ int main(int argc, char* argv[]) {
Ai.messageByID[modelData]
}
messageInputField: root.inputField
faviconDownloadPath: root.faviconDownloadPath
}
}

View file

@ -20,7 +20,6 @@ Rectangle {
property int messageIndex
property var messageData
property var messageInputField
property string faviconDownloadPath
property real messagePadding: 7
property real contentSpacing: 3
@ -282,7 +281,6 @@ Rectangle {
model: root.messageData?.annotationSources
delegate: AnnotationSourceButton {
id: annotationButton
faviconDownloadPath: root.faviconDownloadPath
displayText: modelData.text
url: modelData.url
}

View file

@ -16,13 +16,6 @@ RippleButton {
property string displayText
property string url
property string downloadUserAgent: ConfigOptions.networking.userAgent
property string faviconDownloadPath
property string domainName: url.includes("vertexaisearch") ? displayText : StringUtils.getBaseUrl(url)
property string faviconUrl: `https://www.google.com/s2/favicons?domain=${domainName}&sz=32`
property string fileName: `${domainName}.ico`
property string faviconFilePath: `${faviconDownloadPath}/${fileName}`
property real faviconSize: 20
implicitHeight: 30
leftPadding: (implicitHeight - faviconSize) / 2
@ -32,19 +25,6 @@ RippleButton {
colBackgroundHover: Appearance.colors.colSurfaceContainerHighestHover
colRipple: Appearance.colors.colSurfaceContainerHighestActive
Process {
id: faviconDownloadProcess
running: false
command: ["bash", "-c", `[ -f ${faviconFilePath} ] || curl -s '${root.faviconUrl}' -o '${faviconFilePath}' -L -H 'User-Agent: ${downloadUserAgent}'`]
onExited: (exitCode, exitStatus) => {
root.faviconUrl = root.faviconFilePath
}
}
Component.onCompleted: {
faviconDownloadProcess.running = true
}
PointingHandInteraction {}
onClicked: {
if (url) {
@ -53,27 +33,25 @@ RippleButton {
}
}
contentItem: RowLayout {
spacing: 5
IconImage {
id: iconImage
source: Qt.resolvedUrl(root.faviconUrl)
implicitSize: root.faviconSize
layer.enabled: true
layer.effect: OpacityMask {
maskSource: Rectangle {
width: iconImage.implicitSize
height: iconImage.implicitSize
radius: Appearance.rounding.full
}
contentItem: Item {
anchors.centerIn: parent
implicitWidth: rowLayout.implicitWidth
implicitHeight: rowLayout.implicitHeight
RowLayout {
id: rowLayout
anchors.fill: parent
spacing: 5
Favicon {
Layout.alignment: Qt.AlignVCenter
url: root.url
size: root.faviconSize
}
StyledText {
id: text
horizontalAlignment: Text.AlignHCenter
text: displayText
color: Appearance.m3colors.m3onSurface
}
}
StyledText {
id: text
horizontalAlignment: Text.AlignHCenter
text: displayText
color: Appearance.m3colors.m3onSurface
}
}
}