From 6dc2bf5a16680fee039538de5e79e502e3ee2e91 Mon Sep 17 00:00:00 2001 From: loner <2788892716@qq.com> Date: Sat, 22 Nov 2025 13:30:29 +0800 Subject: [PATCH] feat: Add emoji picker plugin to launcher with category support --- Assets/Translations/en.json | 7 +- Assets/emoji.json | 74 ++++++ Modules/Panels/Launcher/Launcher.qml | 26 +- .../Panels/Launcher/Plugins/EmojiPlugin.qml | 232 ++++++++++++++++++ 4 files changed, 330 insertions(+), 9 deletions(-) create mode 100644 Assets/emoji.json create mode 100644 Modules/Panels/Launcher/Plugins/EmojiPlugin.qml diff --git a/Assets/Translations/en.json b/Assets/Translations/en.json index 424f2974..2a2b664f 100644 --- a/Assets/Translations/en.json +++ b/Assets/Translations/en.json @@ -670,7 +670,12 @@ "clipboard-history-disabled-description": "Enable clipboard history in settings or install cliphist", "clipboard-loading": "Loading clipboard history...", "clipboard-loading-description": "Please wait", - "clipboard-search-description": "Search clipboard history" + "clipboard-search-description": "Search clipboard history", + "emoji": "Emoji picker", + "emoji-search-description": "Search and copy emojis", + "emoji-loading": "Loading emojis...", + "emoji-loading-description": "Please wait", + "emoji-no-results": "No emojis found" }, "quickSettings": { "bluetooth": { diff --git a/Assets/emoji.json b/Assets/emoji.json new file mode 100644 index 00000000..439542d8 --- /dev/null +++ b/Assets/emoji.json @@ -0,0 +1,74 @@ +[ + {"emoji": "😀", "name": "grinning face", "keywords": ["smile", "happy", "grin"], "category": "people"}, + {"emoji": "😂", "name": "face with tears of joy", "keywords": ["laugh", "cry", "happy", "joy"], "category": "people"}, + {"emoji": "😍", "name": "smiling face with heart-eyes", "keywords": ["love", "heart", "eyes", "smile"], "category": "people"}, + {"emoji": "🤔", "name": "thinking face", "keywords": ["think", "ponder", "consider"], "category": "people"}, + {"emoji": "😎", "name": "smiling face with sunglasses", "keywords": ["cool", "sunglasses", "smile"], "category": "people"}, + {"emoji": "đŸĨŗ", "name": "partying face", "keywords": ["party", "hat", "horn", "celebration"], "category": "people"}, + {"emoji": "🤩", "name": "star-struck", "keywords": ["star", "eyes", "amazed", "wow"], "category": "people"}, + {"emoji": "đŸ¤¯", "name": "exploding head", "keywords": ["mind", "blown", "explode", "shocked"], "category": "people"}, + {"emoji": "👍", "name": "thumbs up", "keywords": ["like", "good", "agree", "ok"], "category": "people"}, + {"emoji": "👎", "name": "thumbs down", "keywords": ["dislike", "bad", "disagree", "no"], "category": "people"}, + {"emoji": "🐱", "name": "cat face", "keywords": ["cat", "kitten", "pet", "meow"], "category": "animals"}, + {"emoji": "đŸļ", "name": "dog face", "keywords": ["dog", "puppy", "pet", "woof"], "category": "animals"}, + {"emoji": "đŸĻŠ", "name": "fox face", "keywords": ["fox", "animal", "cute", "wild"], "category": "animals"}, + {"emoji": "đŸŧ", "name": "panda", "keywords": ["panda", "bear", "animal", "cute"], "category": "animals"}, + {"emoji": "đŸĻ„", "name": "unicorn", "keywords": ["unicorn", "horse", "magic", "fantasy"], "category": "animals"}, + {"emoji": "đŸĻ", "name": "lion", "keywords": ["lion", "animal", "face", "majestic"], "category": "animals"}, + {"emoji": "đŸĸ", "name": "turtle", "keywords": ["turtle", "slow", "animal", "shell"], "category": "animals"}, + {"emoji": "🐙", "name": "octopus", "keywords": ["octopus", "animal", "ocean", "sea"], "category": "animals"}, + {"emoji": "đŸŒģ", "name": "sunflower", "keywords": ["sunflower", "flower", "nature", "yellow"], "category": "nature"}, + {"emoji": "đŸŒē", "name": "hibiscus", "keywords": ["hibiscus", "flower", "nature", "plant"], "category": "nature"}, + {"emoji": "🌍", "name": "earth globe europe-africa", "keywords": ["earth", "world", "globe", "nature"], "category": "nature"}, + {"emoji": "🌞", "name": "sun with face", "keywords": ["sun", "nature", "bright", "weather"], "category": "nature"}, + {"emoji": "🌙", "name": "crescent moon", "keywords": ["moon", "night", "sky", "sleep"], "category": "nature"}, + {"emoji": "🌈", "name": "rainbow", "keywords": ["rainbow", "color", "weather", "sky"], "category": "nature"}, + {"emoji": "đŸ”Ĩ", "name": "fire", "keywords": ["fire", "hot", "flame", "burn"], "category": "nature"}, + {"emoji": "💧", "name": "droplet", "keywords": ["water", "drop", "drip", "liquid"], "category": "nature"}, + {"emoji": "🍎", "name": "red apple", "keywords": ["apple", "fruit", "food", "red"], "category": "food"}, + {"emoji": "🍕", "name": "pizza", "keywords": ["pizza", "food", "italian", "cheese"], "category": "food"}, + {"emoji": " sushi", "name": "sushi", "keywords": ["sushi", "food", "japanese", "rice"], "category": "food"}, + {"emoji": "🍔", "name": "hamburger", "keywords": ["hamburger", "food", "burger", "fast food"], "category": "food"}, + {"emoji": "đŸĻ", "name": "soft ice cream", "keywords": ["ice cream", "dessert", "food", "sweet"], "category": "food"}, + {"emoji": "🍩", "name": "doughnut", "keywords": ["donut", "doughnut", "food", "sweet"], "category": "food"}, + {"emoji": "đŸĒ", "name": "cookie", "keywords": ["cookie", "food", "sweet", "biscuit"], "category": "food"}, + {"emoji": "đŸē", "name": "beer mug", "keywords": ["beer", "drink", "alcohol", "pub"], "category": "food"}, + {"emoji": "🍷", "name": "wine glass", "keywords": ["wine", "drink", "alcohol", "glass"], "category": "food"}, + {"emoji": "☕", "name": "hot beverage", "keywords": ["coffee", "hot", "drink", "cafe"], "category": "food"}, + {"emoji": "âšŊ", "name": "soccer ball", "keywords": ["soccer", "football", "ball", "sport"], "category": "activity"}, + {"emoji": "🏀", "name": "basketball", "keywords": ["basketball", "ball", "sport", "game"], "category": "activity"}, + {"emoji": "đŸŽ¯", "name": "direct hit", "keywords": ["target", "bullseye", "aim", "goal"], "category": "activity"}, + {"emoji": "🎮", "name": "video game", "keywords": ["game", "video game", "play", "console"], "category": "activity"}, + {"emoji": "🎲", "name": "game die", "keywords": ["dice", "game", "board", "random"], "category": "activity"}, + {"emoji": "🎨", "name": "artist palette", "keywords": ["art", "paint", "colors", "creative"], "category": "activity"}, + {"emoji": "🎤", "name": "microphone", "keywords": ["mic", "microphone", "sing", "karaoke"], "category": "activity"}, + {"emoji": "đŸŽŦ", "name": "clapper board", "keywords": ["movie", "film", "action", "director"], "category": "activity"}, + {"emoji": "🚗", "name": "automobile", "keywords": ["car", "vehicle", "transport", "drive"], "category": "travel"}, + {"emoji": "âœˆī¸", "name": "airplane", "keywords": ["plane", "flight", "travel", "fly"], "category": "travel"}, + {"emoji": "🚀", "name": "rocket", "keywords": ["space", "launch", "fast", "ship"], "category": "travel"}, + {"emoji": "🚲", "name": "bicycle", "keywords": ["bike", "cycle", "transport", "exercise"], "category": "travel"}, + {"emoji": "🚂", "name": "locomotive", "keywords": ["train", "steam", "vehicle", "transport"], "category": "travel"}, + {"emoji": "đŸšĸ", "name": "ship", "keywords": ["ship", "boat", "water", "transport"], "category": "travel"}, + {"emoji": "🏠", "name": "house", "keywords": ["home", "house", "building", "residence"], "category": "objects"}, + {"emoji": "đŸĸ", "name": "office building", "keywords": ["office", "building", "work", "business"], "category": "objects"}, + {"emoji": "đŸĨ", "name": "hospital", "keywords": ["hospital", "medical", "health", "doctor"], "category": "objects"}, + {"emoji": "đŸĻ", "name": "bank", "keywords": ["bank", "money", "finance", "building"], "category": "objects"}, + {"emoji": "đŸĒ", "name": "convenience store", "keywords": ["store", "shop", "convenience", "grocery"], "category": "objects"}, + {"emoji": "🎁", "name": "gift", "keywords": ["present", "gift", "box", "birthday"], "category": "objects"}, + {"emoji": "💡", "name": "light bulb", "keywords": ["idea", "light", "bright", "thinking"], "category": "objects"}, + {"emoji": "đŸ’ģ", "name": "laptop computer", "keywords": ["computer", "laptop", "pc", "work"], "category": "objects"}, + {"emoji": "📱", "name": "mobile phone", "keywords": ["phone", "smartphone", "cellphone", "mobile"], "category": "objects"}, + {"emoji": "🔑", "name": "key", "keywords": ["key", "password", "secret", "access"], "category": "objects"}, + {"emoji": "🔒", "name": "locked", "keywords": ["lock", "secure", "private", "closed"], "category": "objects"}, + {"emoji": "⭐", "name": "star", "keywords": ["star", "rating", "favorite", "bright"], "category": "symbols"}, + {"emoji": "â¤ī¸", "name": "red heart", "keywords": ["heart", "love", "like", "affection"], "category": "symbols"}, + {"emoji": "đŸ’¯", "name": "hundred points", "keywords": ["percent", "perfect", "score", "100"], "category": "symbols"}, + {"emoji": "ÂŠī¸", "name": "copyright", "keywords": ["copyright", "symbol", "c", "legal"], "category": "symbols"}, + {"emoji": "ÂŽī¸", "name": "registered", "keywords": ["registered", "symbol", "r", "trademark"], "category": "symbols"}, + {"emoji": "â„ĸī¸", "name": "trade mark", "keywords": ["trademark", "tm", "symbol", "mark"], "category": "symbols"}, + {"emoji": "âœ”ī¸", "name": "check mark", "keywords": ["check", "mark", "ok", "correct"], "category": "symbols"}, + {"emoji": "❌", "name": "cross mark", "keywords": ["x", "cross", "mark", "no", "wrong"], "category": "symbols"}, + {"emoji": "âš ī¸", "name": "warning", "keywords": ["warning", "exclamation", "caution", "alert"], "category": "symbols"}, + {"emoji": "🎉", "name": "party popper", "keywords": ["party", "celebration", "tada", "congrats"], "category": "symbols"}, + {"emoji": "🔔", "name": "bell", "keywords": ["bell", "sound", "notification", "ring"], "category": "symbols"} +] \ No newline at end of file diff --git a/Modules/Panels/Launcher/Launcher.qml b/Modules/Panels/Launcher/Launcher.qml index 8e84cb65..114bd4ee 100644 --- a/Modules/Panels/Launcher/Launcher.qml +++ b/Modules/Panels/Launcher/Launcher.qml @@ -220,6 +220,14 @@ SmartPanel { } } + EmojiPlugin { + id: emojiPlugin + Component.onCompleted: { + registerPlugin(this); + Logger.d("Launcher", "Registered: EmojiPlugin"); + } + } + // Navigation functions function selectNextWrapped() { if (results.length > 0) { @@ -492,7 +500,7 @@ SmartPanel { Layout.fillWidth: true spacing: Style.marginM - // Icon badge or Image preview + // Icon badge or Image preview or Emoji Rectangle { Layout.preferredWidth: badgeSize Layout.preferredHeight: badgeSize @@ -503,7 +511,7 @@ SmartPanel { NImageRounded { id: imagePreview anchors.fill: parent - visible: modelData.isImage + visible: modelData.isImage && !modelData.emojiChar imageRadius: Style.radiusM // This property creates a dependency on the service's revision counter @@ -542,26 +550,28 @@ SmartPanel { anchors.fill: parent anchors.margins: Style.marginXS - visible: !modelData.isImage || imagePreview.status === Image.Error + visible: !modelData.isImage && !modelData.emojiChar || (modelData.isImage && imagePreview.status === Image.Error) active: visible sourceComponent: Component { IconImage { anchors.fill: parent source: modelData.icon ? ThemeIcons.iconFromName(modelData.icon, "application-x-executable") : "" - visible: modelData.icon && source !== "" + visible: modelData.icon && source !== "" && !modelData.emojiChar asynchronous: true } } } + // Emoji display - takes precedence when emojiChar is present NText { + id: emojiDisplay anchors.centerIn: parent - visible: !imagePreview.visible && !iconLoader.visible - text: modelData.name ? modelData.name.charAt(0).toUpperCase() : "?" - pointSize: Style.fontSizeXXL + visible: modelData.emojiChar ? true : (!imagePreview.visible && !iconLoader.visible) + text: modelData.emojiChar ? modelData.emojiChar : (modelData.name ? modelData.name.charAt(0).toUpperCase() : "?") + pointSize: modelData.emojiChar ? Style.fontSizeXXXL : Style.fontSizeXXL // Larger font for emojis font.weight: Style.fontWeightBold - color: Color.mOnPrimary + color: modelData.emojiChar ? Color.mOnSurface : Color.mOnPrimary // Different color for emojis } // Image type indicator overlay diff --git a/Modules/Panels/Launcher/Plugins/EmojiPlugin.qml b/Modules/Panels/Launcher/Plugins/EmojiPlugin.qml new file mode 100644 index 00000000..8bd4690d --- /dev/null +++ b/Modules/Panels/Launcher/Plugins/EmojiPlugin.qml @@ -0,0 +1,232 @@ +import QtQuick +import Quickshell +import Quickshell.Io +import qs.Commons +import qs.Services.Keyboard + +Item { + id: root + + // Plugin metadata and configuration + property string name: I18n.tr("plugins.emoji") + property var launcher: null + property bool handleSearch: false + + // Emoji data storage + property var allEmojis: [] + property var userEmojiData: [] + property var builtInEmojis: [] + property bool emojisLoaded: false + property bool userEmojisLoaded: false + property bool builtInEmojisLoaded: false + + // User custom emoji file path + property string userEmojiFilePath: Settings.dataDir + "emoji.json" + + // Plugin initialization + Component.onCompleted: { + userEmojiFile.reload(); + } + + // User emoji file loader + FileView { + id: userEmojiFile + path: userEmojiFilePath + printErrors: false + watchChanges: true + + onLoaded: { + try { + const content = text(); + if (content) { + const parsed = JSON.parse(content); + if (parsed && Array.isArray(parsed)) { + root.userEmojiData = parsed; + } else { + root.userEmojiData = []; + } + } else { + root.userEmojiData = []; + } + } catch (e) { + root.userEmojiData = []; + } + root.userEmojisLoaded = true; + checkAllEmojisLoaded(); + } + + onLoadFailed: function (error) { + root.userEmojiData = []; + root.userEmojisLoaded = true; + checkAllEmojisLoaded(); + } + } + + // Plugin initialization method + function init() { + Logger.i("EmojiPlugin", "Initialized"); + } + + // Handler when launcher opens + function onOpened() { + if (!emojisLoaded) { + userEmojiFile.reload(); + } + } + + // Check if handles command + function handleCommand(searchText) { + return searchText.startsWith(">emoji"); + } + + // Register commands + function commands() { + return [ + { + "name": ">emoji", + "description": I18n.tr("plugins.emoji-search-description"), + "icon": "emote", + "isImage": false, + "onActivate": function () { + launcher.setSearchText(">emoji "); + } + } + ]; + } + + // Get search results + function getResults(searchText) { + if (!searchText.startsWith(">emoji")) { + return []; + } + + const query = searchText.slice(6).trim(); + + if (!emojisLoaded) { + return [ + { + "name": I18n.tr("plugins.emoji-loading"), + "description": I18n.tr("plugins.emoji-loading-description"), + "icon": "view-refresh", + "isImage": false, + "onActivate": function () {} + } + ]; + } + + let results = []; + + if (!query || query === "") { + results = allEmojis.slice(0, 20).map(emoji => formatEmojiEntry(emoji)); + } else { + const terms = query.toLowerCase().split(" "); + + results = allEmojis.filter(emoji => { + for (let term of terms) { + if (term === "") continue; + + const emojiMatch = emoji.emoji.toLowerCase().includes(term); + const nameMatch = (emoji.name || "").toLowerCase().includes(term); + const keywordMatch = (emoji.keywords || []).some(kw => kw.toLowerCase().includes(term)); + const categoryMatch = (emoji.category || "").toLowerCase().includes(term); + + if (!emojiMatch && !nameMatch && !keywordMatch && !categoryMatch) { + return false; + } + } + return true; + }).map(emoji => formatEmojiEntry(emoji)); + } + + if (results.length === 0 && query !== "") { + return [ + { + "name": I18n.tr("plugins.emoji-no-results"), + "description": I18n.tr(`No emojis found for "${query}"`), + "icon": "emote-rye", + "isImage": false, + "onActivate": function () {} + } + ]; + } + + return results; + } + + // Format emoji entry + function formatEmojiEntry(emoji) { + let title = emoji.name; + let description = (emoji.keywords || []).join(", "); + + if (emoji.category) { + description += " â€ĸ Category: " + emoji.category; + } + + const emojiChar = emoji.emoji; + + return { + "name": title, + "description": description, + "icon": null, + "isImage": false, + "emojiChar": emojiChar, + "onActivate": function () { + Quickshell.execDetached(["sh", "-c", `echo -n "${emojiChar}" | wl-copy`]); + launcher.close(); + } + }; + } + + // Check if all emojis are loaded + function checkAllEmojisLoaded() { + if (userEmojisLoaded && builtInEmojisLoaded) { + finalizeEmojiLoad(); + } + } + + // Final emoji load completion + function finalizeEmojiLoad() { + allEmojis = userEmojiData.concat(builtInEmojis); + emojisLoaded = true; + Logger.i("EmojiPlugin", `Loaded ${allEmojis.length} total emojis`); + } + + // Built-in emoji file loader + FileView { + id: builtinEmojiFile + path: `${Quickshell.shellDir}/Assets/emoji.json` + watchChanges: false + printErrors: false + + onLoaded: { + try { + const content = text(); + if (content) { + const parsed = JSON.parse(content); + if (parsed && Array.isArray(parsed)) { + root.builtInEmojis = parsed; + } else { + root.builtInEmojis = []; + } + } else { + root.builtInEmojis = []; + } + } catch (e) { + root.builtInEmojis = []; + } + root.builtInEmojisLoaded = true; + checkAllEmojisLoaded(); + } + + onLoadFailed: function(error) { + root.builtInEmojis = []; + root.builtInEmojisLoaded = true; + checkAllEmojisLoaded(); + } + } + + // Load built-in emojis + function loadBuiltInEmojis() { + builtinEmojiFile.reload(); + } +} \ No newline at end of file