launcher search service: use proper type instead of json clumps

This commit is contained in:
end-4
2025-12-03 22:07:06 +01:00
parent 05aae36e82
commit 4055ad48fa
5 changed files with 161 additions and 82 deletions
@@ -590,8 +590,9 @@ Singleton {
// false will make (some) stuff also be like that for accuracy.
// Example: the right-click menu of the Start button
property JsonObject tweaks: JsonObject {
property bool smootherMenuAnimations: true
property bool switchHandlePositionFix: true
property bool smootherMenuAnimations: true
property bool smootherSearchBar: true
}
property JsonObject bar: JsonObject {
property bool bottom: true
@@ -0,0 +1,29 @@
import QtQuick
import Quickshell
QtObject {
enum IconType { Material, Text, System, None }
enum FontType { Normal, Monospace }
// General stuff
property string type: ""
property var fontType: LauncherSearchResult.FontType.Normal
property string name: ""
property string rawValue: ""
property string iconName: ""
property var iconType: LauncherSearchResult.IconType.None
property string verb: ""
property bool blurImage: false
property var execute: () => {
print("Not implemented");
}
property var actions: []
// Stuff needed for DesktopEntry objects
property bool shown: true
property string comment: ""
property bool runInTerminal: false
property string genericName: ""
property list<string> keywords: []
}
@@ -2,6 +2,7 @@
import qs
import qs.services
import qs.modules.common
import qs.modules.common.models
import qs.modules.common.widgets
import qs.modules.common.functions
import QtQuick
@@ -12,20 +13,27 @@ import Quickshell.Hyprland
RippleButton {
id: root
property var entry
property LauncherSearchResult entry
property string query
property bool entryShown: entry?.shown ?? true
property string itemType: entry?.type ?? Translation.tr("App")
property string itemName: entry?.name ?? ""
property string itemIcon: entry?.icon ?? ""
property var iconType: entry?.iconType
property string iconName: entry?.iconName ?? ""
property var itemExecute: entry?.execute
property string fontType: entry?.fontType ?? "main"
property string itemClickActionName: entry?.clickActionName ?? "Open"
property string bigText: entry?.bigText ?? ""
property string materialSymbol: entry?.materialSymbol ?? ""
property string cliphistRawString: entry?.cliphistRawString ?? ""
property var fontType: switch(entry?.fontType) {
case LauncherSearchResult.FontType.Monospace:
return "monospace"
case LauncherSearchResult.FontType.Normal:
return "main"
default:
return "main"
}
property string itemClickActionName: entry?.verb ?? "Open"
property string bigText: entry?.iconType === LauncherSearchResult.IconType.Text ? entry?.iconName ?? "" : ""
property string materialSymbol: entry.iconType === LauncherSearchResult.IconType.Material ? entry?.iconName ?? "" : ""
property string cliphistRawString: entry?.rawValue ?? ""
property bool blurImage: entry?.blurImage ?? false
property string blurImageText: entry?.blurImageText ?? "Image hidden"
visible: root.entryShown
property int horizontalMargin: 10
@@ -97,7 +105,7 @@ RippleButton {
}
Keys.onPressed: (event) => {
if (event.key === Qt.Key_Delete && event.modifiers === Qt.ShiftModifier) {
const deleteAction = root.entry.actions.find(action => action.name == "Delete");
const deleteAction = root.entry.actions.find(action => action.name == Translation.tr("Delete"));
if (deleteAction) {
deleteAction.execute()
@@ -126,16 +134,24 @@ RippleButton {
Loader {
id: iconLoader
active: true
sourceComponent: root.materialSymbol !== "" ? materialSymbolComponent :
root.bigText ? bigTextComponent :
root.itemIcon !== "" ? iconImageComponent :
null
sourceComponent: switch(root.iconType) {
case LauncherSearchResult.IconType.Material:
return materialSymbolComponent
case LauncherSearchResult.IconType.Text:
return bigTextComponent
case LauncherSearchResult.IconType.System:
return iconImageComponent
case LauncherSearchResult.IconType.None:
return null
default:
return null
}
}
Component {
id: iconImageComponent
IconImage {
source: Quickshell.iconPath(root.itemIcon, "image-missing")
source: Quickshell.iconPath(root.iconName, "image-missing")
width: 35
height: 35
}
@@ -217,7 +233,6 @@ RippleButton {
maxWidth: contentColumn.width
maxHeight: 140
blur: root.blurImage
blurText: root.blurImageText
}
}
}
@@ -243,8 +258,8 @@ RippleButton {
delegate: RippleButton {
id: actionButton
required property var modelData
property string iconName: modelData.icon ?? ""
property string materialIconName: modelData.materialIcon ?? ""
property var iconType: modelData.iconType
property string iconName: modelData.iconName ?? ""
implicitHeight: 34
implicitWidth: 34
@@ -256,16 +271,16 @@ RippleButton {
anchors.centerIn: parent
Loader {
anchors.centerIn: parent
active: !(actionButton.iconName !== "") || actionButton.materialIconName
active: actionButton.iconType === LauncherSearchResult.IconType.Material || actionButton.iconName === ""
sourceComponent: MaterialSymbol {
text: actionButton.materialIconName || "video_settings"
text: actionButton.iconName || "video_settings"
font.pixelSize: Appearance.font.pixelSize.hugeass
color: Appearance.m3colors.m3onSurface
}
}
Loader {
anchors.centerIn: parent
active: actionButton.materialIconName.length == 0 && actionButton.iconName && actionButton.iconName !== ""
active: actionButton.iconType === LauncherSearchResult.IconType.System && actionButton.iconName !== ""
sourceComponent: IconImage {
source: Quickshell.iconPath(actionButton.iconName)
implicitSize: 20
@@ -42,12 +42,6 @@ Item { // Wrapper
LauncherSearch.query = text;
}
function containsUnsafeLink(entry) {
if (entry == undefined) return false;
const unsafeKeywords = Config.options.workSafety.triggerCondition.linkKeywords;
return StringUtils.stringListContainsSubstring(entry.toLowerCase(), unsafeKeywords);
}
Keys.onPressed: event => {
// Prevent Esc and Backspace from registering
if (event.key === Qt.Key_Escape)