added emoji widget

This commit is contained in:
sankalp committed 2024-07-01 00:45:38 +05:45
1 parent 8cfefa60fd
commit dd0db242bf
20 files changed
+7615 -1875

No files matched your search

+2 -1
View File
@@ -1,6 +1,6 @@
import { Binding } from "types/service"
const GLib = imports.gi.GLib;
import { cpu_cores, cpu_name, kernel_name, amount_of_ram, gpu_name, hostname } from "variables";
import { cpu_cores, cpu_name, kernel_name, amount_of_ram, gpu_name, hostname, current_os } from "variables";
type StringOrBinding = string | Binding<any, any, string> | null;
@@ -52,6 +52,7 @@ export function Info() {
Utils.execAsync(`xdg-open "${repo_link}"`).catch(print)
}),
Widget.Separator(),
Row("OS", current_os),
Row("DE", current_de!),
Row("Kernel", kernel_name),
Row("CPU", `${cpu_name} (${cpu_cores} Cores)`),
File diff suppressed because it is too large. Load diff
+2
View File
@@ -8,6 +8,7 @@ import { Notifications } from "./modules/notificationPopups.ts"
import { applauncher } from "./modules/applauncher.js"
import { media } from "./modules/media.ts"
import { cliphist } from "./modules/cliphist.ts"
import { emoji } from "./modules/emoji.ts"
import { sidebar } from "./modules/sidebar/main.ts"
import {} from 'apps/settings/main.ts';
import Window from 'types/widgets/window';
@@ -31,6 +32,7 @@ const Windows = () => [
media,
applauncher,
cliphist,
emoji,
sidebar,
];
+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,
+6
View File
@@ -37,6 +37,10 @@ get_hostname() {
cat /etc/hostname
}
get_os() {
hostnamectl | grep "Operating System" | awk '{for (i=3; i<=NF; i++) printf $i " "; print ""}'
}
if [[ "$1" == "--cpu-usage" ]]; then
get_cpu_usage
elif [[ "$1" == "--ram-usage" ]]; then
@@ -57,4 +61,6 @@ if [[ "$1" == "--cpu-usage" ]]; then
get_gpu
elif [[ "$1" == "--hostname" ]]; then
get_hostname
elif [[ "$1" == "--os" ]]; then
get_os
fi
+20
View File
@@ -342,6 +342,25 @@ window.notification-popups box.notifications {
* Clipboard history
* ----------------------------------------------------- */
.emoji_box {
border-radius: 24px;
background-color: @background;
border: 2px solid;
border-color: @outlineVariant;
padding: 11px;
}
.emoji_entry {
background-color: @surfaceContainerHigh;
color: @onSurface;
border: none;
outline: none;
border-radius: 100px;
margin-bottom: 16px;
padding: 5px;
padding-left: 25px;
}
.cliphistory_box {
border-radius: 24px;
background-color: @background;
@@ -397,6 +416,7 @@ window.notification-popups box.notifications {
font-weight: normal;
}
/* -----------------------------------------------------
* Media player
* ----------------------------------------------------- */
+1
View File
@@ -16,6 +16,7 @@ export const cpu_cores = await Utils.execAsync(`${App.configDir}/scripts/system.
export const amount_of_ram = await Utils.execAsync(`${App.configDir}/scripts/system.sh --ram`);
export const kernel_name = await Utils.execAsync(`${App.configDir}/scripts/system.sh --kernel`);
export const hostname = await Utils.execAsync(`${App.configDir}/scripts/system.sh --hostname`);
export const current_os = await Utils.execAsync(`${App.configDir}/scripts/system.sh --os`);
export const wallpaper_cache_file = `${GLib.get_home_dir()}/.cache/current_wallpaper`
+1 -1
View File
@@ -37,7 +37,7 @@ bind = $mainMod, Slash, exec, pypr toggle nvim && hyprctl dispatch bringactiv
# FEATURES / EXTRAS
bind = $mainMod_SHIFT, G, exec, $RunCMD gamemode
bind = $mainMod, PERIOD, exec, $scriptsDir/RofiEmoji.sh
bind = $mainMod, PERIOD, exec, ags -t emoji
bind = ALT, F3, exec, $RunCMD kb_changer
bind = $mainMod_SHIFT, B, exec, $RunCMD toggle_blur
bind = $mainMod, space, exec, $RunCMD change_layout
File diff suppressed because it is too large. Load diff