feat: Add emoji picker plugin to launcher with category support

This commit is contained in:
loner
2025-11-22 13:30:29 +08:00
parent 1bf54de99c
commit 6dc2bf5a16
4 changed files with 330 additions and 9 deletions

View File

@@ -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": {

74
Assets/emoji.json Normal file
View File

@@ -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"}
]

View File

@@ -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

View File

@@ -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();
}
}