added emoji widget

This commit is contained in:
sankalp committed 2024-07-01 00:45:38 +05:45
1 parent 3be1c05741
commit 4a9469099f
20 files changed
+7615 -1875

No files matched your search

+1 -1
View File
@@ -3,12 +3,12 @@ const { query } = await Service.import("applications")
const encoder = new TextEncoder();
const decoder = new TextDecoder();
const Gio = imports.gi.Gio;
const { Gtk } = imports.gi;
const GLib = imports.gi.GLib;
const WINDOW_NAME = "applauncher"
import Box from 'types/widgets/box';
import popupwindow from './misc/popupwindow.ts';
import { Application } from 'types/service/applications';
import Gtk from "gi://Gtk?version=3.0"
const LAUNCH_COUNT_FILE = Gio.File.new_for_path(
+2 -2
View File
@@ -1,7 +1,7 @@
const WINDOW_NAME = "cliphist"
import popupwindow from './misc/popupwindow.ts';
import Box from 'types/widgets/box.js';
const { Gtk } = imports.gi;
import Gtk from "gi://Gtk?version=3.0"
type EntryObject = {
@@ -27,7 +27,7 @@ function ClipHistItem(entry: string) {
button.connect('clicked', () => {
clickCount++;
if (clickCount === 2) {
if (clickCount === 1) {
App.closeWindow(WINDOW_NAME);
Utils.execAsync(`${App.configDir}/scripts/cliphist.sh --copy-by-id ${id}`)
clickCount = 0;
+166
View File
@@ -0,0 +1,166 @@
const WINDOW_NAME = "emoji";
import popupwindow from './misc/popupwindow.ts';
import Box from 'types/widgets/box.js';
import Gtk from "gi://Gtk?version=3.0";
import Gio from 'gi://Gio';
type EmojiObject = {
emoji: string;
description: string;
};
let emojisCache: EmojiObject[] = []; // Cache for emojis
async function loadEmojis(filePath: string): Promise<EmojiObject[]> {
try {
const file = Gio.File.new_for_path(filePath);
const [success, contents, etag] = await new Promise<[boolean, Uint8Array | null, string | null]>((resolve, reject) => {
file.load_contents_async(null, (file, res) => {
try {
resolve(file.load_contents_finish(res));
} catch (e) {
reject(e);
}
});
});
if (!success || !contents) {
throw new Error('Failed to load file contents');
}
const decoder = new TextDecoder();
const jsonContent = decoder.decode(contents);
return JSON.parse(jsonContent) as EmojiObject[];
} catch (error) {
throw new Error('Failed to load emojis');
}
}
function execAsync(command: string): Promise<void> {
return new Promise((resolve, reject) => {
const [success, stdout, stderr] = GLib.spawn_command_line_async(command, null);
if (!success) {
reject(new Error(`Failed to execute command: ${stderr}`));
} else {
resolve();
}
});
}
function EmojiItem(entry: EmojiObject) {
let { emoji, description } = entry;
let clickCount = 0;
let button = Widget.Button({
class_name: "entry_container",
child: Widget.Label({
label: `${emoji} ${description}`, // Display emoji and description
class_name: "entry_label",
xalign: 0,
vpack: "center",
truncate: "end",
})
});
button.connect('clicked', () => {
clickCount++;
if (clickCount === 1) {
App.closeWindow(WINDOW_NAME);
// Execute wl-copy command asynchronously
execAsync(`wl-copy '${emoji}'`)
.then(() => {})
.catch(() => {});
clickCount = 0;
}
});
button.connect('focus-out-event', () => {
clickCount = 0;
});
return Widget.Box({
attribute: { description: description.trim() },
orientation: Gtk.Orientation.VERTICAL,
children: [
button,
Widget.Separator({
class_name: "entry_divider",
orientation: Gtk.Orientation.HORIZONTAL
})
]
});
}
function debounce(func: Function, wait: number) {
let timeout: number;
return function (...args: any[]) {
clearTimeout(timeout);
timeout = setTimeout(() => func.apply(this, args), wait);
};
}
function Emoji({ width = 500, height = 500, spacing = 12 }) {
const WINDOW_NAME = "emoji";
const list = Widget.Box({
vertical: true,
spacing,
});
const entry = Widget.Entry({
hexpand: true,
class_name: "emoji_entry",
placeholder_text: "Search",
on_change: debounce(({ text }) => {
const searchText = (text ?? '').toLowerCase();
list.children.forEach(item => {
const description = item.attribute?.description?.toLowerCase() ?? '';
item.visible = description.includes(searchText);
});
}, 300),
});
return Widget.Box({
vertical: true,
class_name: "emoji_box",
margin_top: 14,
margin_right: 14,
children: [
entry,
Widget.Scrollable({
hscroll: "never",
css: `min-width: ${width}px; min-height: ${height}px;`,
child: list,
}),
],
setup: self => self.hook(App, (_, windowName, visible) => {
if (windowName !== WINDOW_NAME) return;
if (visible && emojisCache.length === 0) {
loadEmojis(`${App.configDir}/emojis.json`)
.then(emojis => {
emojisCache = emojis;
list.children = emojis.map(entry => EmojiItem(entry));
entry.text = '';
})
.catch(error => console.error('Failed to load emojis:', error));
}
}),
});
}
export const emoji = popupwindow({
name: WINDOW_NAME,
class_name: "emoji",
visible: false,
keymode: "exclusive",
child: Emoji({
width: 500,
height: 500,
spacing: 0,
}),
anchor: ["bottom", "right"]
});
@@ -1,6 +1,6 @@
import Widget from 'resource:///com/github/Aylur/ags/widget.js';
const { Gtk } = imports.gi;
const Lang = imports.lang;
import Gtk from "gi://Gtk?version=3.0"
export const RoundedCorner = (place, props) => Widget.DrawingArea({
...props,
@@ -48,4 +48,4 @@ export const RoundedCorner = (place, props) => Widget.DrawingArea({
// cr.stroke();
}));
}),
});
});
+1 -1
View File
@@ -1,7 +1,7 @@
import App from 'resource:///com/github/Aylur/ags/app.js';
import Widget from 'resource:///com/github/Aylur/ags/widget.js';
import { WindowProps, Window } from 'types/widgets/window';
const { Gtk, GLib } = imports.gi;
import Gtk from "gi://Gtk?version=3.0"
type _WindowProps = WindowProps<any, unknown, Window<any, unknown>> | undefined[];
+1 -1
View File
@@ -7,7 +7,7 @@ import Pango from "gi://Pango";
import Label from "types/widgets/label";
const notifications = await Service.import("notifications")
const { Gtk } = imports.gi;
import Gtk from "gi://Gtk?version=3.0"
function NotificationIcon({ app_entry, app_icon, image }: NotificationType): Box<GtkType.Widget, any> {
if (image) {
+1 -1
View File
@@ -1,4 +1,4 @@
const { Gtk, GLib } = imports.gi;
const { GLib } = imports.gi;
const lock_command = `hyprlock`;
const logout_command = `loginctl kill-session $XDG_SESSION_ID`;
const shutdown_command = `systemctl poweroff`;
+2 -1
View File
@@ -1,4 +1,3 @@
const { Gtk } = imports.gi;
const notifications = await Service.import("notifications")
const network = await Service.import('network')
@@ -7,6 +6,8 @@ import { OpenSettings } from "apps/settings/main.ts";
import { WINDOW_NAME } from "./main.ts"
import { bluetooth_enabled, idle_inhibitor, night_light, screen_recorder } from "variables.ts";
import Gtk from "gi://Gtk?version=3.0"
const currentPage = Variable(0);
+2 -1
View File
@@ -1,7 +1,8 @@
const { Gtk } = imports.gi;
import { NotificationsBox } from "./notifications.ts"
import { SystemBox } from "./system.ts"
let shown = Variable("Messages");
import Gtk from "gi://Gtk?version=3.0"
type ButtonType = {
+1 -1
View File
@@ -3,7 +3,7 @@ import { NotificationPopups, Notification } from "modules/notificationPopups";
import Box from "types/widgets/box";
const notifications = await Service.import("notifications")
const { Gtk, Gdk } = imports.gi;
type NotificationsBoxType = {
exclude?: string[],
+1 -1
View File
@@ -1,7 +1,7 @@
import { Management } from "./management.ts"
import { Buttons } from "./buttons.ts";
import { Navigation } from "./navigation.ts";
const { Gtk } = imports.gi;
import Gtk from "gi://Gtk?version=3.0"
export function SideBar() {
return Widget.Box({
+1 -1
View File
@@ -1,5 +1,5 @@
const { Gtk } = imports.gi;
import { cpu_cores, cpu_name, kernel_name, amount_of_ram, gpu_name } from "variables";
import Gtk from "gi://Gtk?version=3.0"
type InfoType = {
cpu: string,