forked from Shinonome/dots-hyprland
favicon for links in clipboard entries
This commit is contained in:
@@ -15,14 +15,16 @@ import Quickshell.Hyprland
|
|||||||
IconImage {
|
IconImage {
|
||||||
id: root
|
id: root
|
||||||
property string url
|
property string url
|
||||||
|
property string displayText
|
||||||
|
|
||||||
property real size: 32
|
property real size: 32
|
||||||
property string downloadUserAgent: ConfigOptions?.networking.userAgent ?? ""
|
property string downloadUserAgent: ConfigOptions?.networking.userAgent ?? ""
|
||||||
property string faviconDownloadPath: FileUtils.trimFileProtocol(`${XdgDirectories.cache}/media/favicons`)
|
property string faviconDownloadPath: FileUtils.trimFileProtocol(`${XdgDirectories.cache}/media/favicons`)
|
||||||
property string domainName: url.includes("vertexaisearch") ? displayText : StringUtils.getBaseUrl(url)
|
property string domainName: url.includes("vertexaisearch") ? displayText : StringUtils.getDomain(url)
|
||||||
property string faviconUrl: `https://www.google.com/s2/favicons?domain=${domainName}&sz=32`
|
property string faviconUrl: `https://www.google.com/s2/favicons?domain=${domainName}&sz=32`
|
||||||
property string fileName: `${domainName}.ico`
|
property string fileName: `${domainName}.ico`
|
||||||
property string faviconFilePath: `${faviconDownloadPath}/${fileName}`
|
property string faviconFilePath: `${faviconDownloadPath}/${fileName}`
|
||||||
|
property string urlToLoad
|
||||||
|
|
||||||
Process {
|
Process {
|
||||||
id: faviconDownloadProcess
|
id: faviconDownloadProcess
|
||||||
@@ -31,11 +33,13 @@ IconImage {
|
|||||||
onExited: (exitCode, exitStatus) => {
|
onExited: (exitCode, exitStatus) => {
|
||||||
console.log("Favicon download process exited with code:", exitCode, "and status:", exitStatus)
|
console.log("Favicon download process exited with code:", exitCode, "and status:", exitStatus)
|
||||||
console.log("Favicon file path:", faviconFilePath)
|
console.log("Favicon file path:", faviconFilePath)
|
||||||
root.faviconUrl = root.faviconFilePath
|
root.urlToLoad = root.faviconFilePath
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
|
console.log("URL: ", root.url)
|
||||||
|
console.log("DOMAIN: ", root.domainName)
|
||||||
console.log("faviconDownloadPath: ", faviconDownloadPath)
|
console.log("faviconDownloadPath: ", faviconDownloadPath)
|
||||||
console.log("faviconFilePath: ", faviconFilePath)
|
console.log("faviconFilePath: ", faviconFilePath)
|
||||||
console.log("faviconUrl: ", root.faviconUrl)
|
console.log("faviconUrl: ", root.faviconUrl)
|
||||||
@@ -45,7 +49,7 @@ IconImage {
|
|||||||
faviconDownloadProcess.running = true
|
faviconDownloadProcess.running = true
|
||||||
}
|
}
|
||||||
|
|
||||||
source: Qt.resolvedUrl(root.faviconUrl)
|
source: Qt.resolvedUrl(root.urlToLoad)
|
||||||
implicitSize: root.size
|
implicitSize: root.size
|
||||||
|
|
||||||
layer.enabled: true
|
layer.enabled: true
|
||||||
|
|||||||
@@ -56,9 +56,17 @@ RippleButton {
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
property string displayContent: highlightContent(root.itemName, root.query)
|
property string displayContent: highlightContent(root.itemName, root.query)
|
||||||
|
|
||||||
|
property list<string> urls: {
|
||||||
|
if (!root.itemName) return [];
|
||||||
|
// Regular expression to match URLs
|
||||||
|
const urlRegex = /https?:\/\/[^\s<>"{}|\\^`[\]]+/gi;
|
||||||
|
const matches = root.itemName.match(urlRegex)
|
||||||
|
.filter(url => !url.includes("…")) // Elided = invalid
|
||||||
|
return matches ? matches : [];
|
||||||
|
}
|
||||||
|
|
||||||
visible: root.entryShown
|
visible: root.entryShown
|
||||||
property int horizontalMargin: 10
|
property int horizontalMargin: 10
|
||||||
property int buttonHorizontalPadding: 10
|
property int buttonHorizontalPadding: 10
|
||||||
@@ -144,16 +152,26 @@ RippleButton {
|
|||||||
visible: root.itemType && root.itemType != qsTr("App")
|
visible: root.itemType && root.itemType != qsTr("App")
|
||||||
text: root.itemType
|
text: root.itemType
|
||||||
}
|
}
|
||||||
StyledText {
|
RowLayout {
|
||||||
Layout.fillWidth: true
|
Repeater {
|
||||||
id: nameText
|
model: root.query == root.itemName ? [] : root.urls
|
||||||
textFormat: Text.StyledText // RichText also works, but StyledText ensures elide work
|
Favicon {
|
||||||
font.pixelSize: Appearance.font.pixelSize.small
|
required property var modelData
|
||||||
font.family: Appearance.font.family[root.fontType]
|
size: parent.height
|
||||||
color: Appearance.m3colors.m3onSurface
|
url: modelData
|
||||||
horizontalAlignment: Text.AlignLeft
|
}
|
||||||
elide: Text.ElideRight
|
}
|
||||||
text: `${root.displayContent}`
|
StyledText {
|
||||||
|
Layout.fillWidth: true
|
||||||
|
id: nameText
|
||||||
|
textFormat: Text.StyledText // RichText also works, but StyledText ensures elide work
|
||||||
|
font.pixelSize: Appearance.font.pixelSize.small
|
||||||
|
font.family: Appearance.font.family[root.fontType]
|
||||||
|
color: Appearance.m3colors.m3onSurface
|
||||||
|
horizontalAlignment: Text.AlignLeft
|
||||||
|
elide: Text.ElideRight
|
||||||
|
text: `${root.displayContent}`
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user