ags: sync

This commit is contained in:
end-4
2024-01-02 15:55:19 +07:00
parent 577550642f
commit 49bda08cbc
11 changed files with 82 additions and 49 deletions
+1 -1
View File
@@ -82,7 +82,7 @@ export const ModuleLeftSpace = () => Widget.EventBox({
xalign: 0,
className: 'txt txt-smallie',
setup: (self) => self.hook(Hyprland.active.client, label => { // Hyprland.active.client
label.label = Hyprland.active.client._title.length === 0 ? `Workspace ${Hyprland.active.workspace.id}` : truncateTitle(Hyprland.active.client._title);
label.label = Hyprland.active.client._title.length === 0 ? `Workspace ${Hyprland.active.workspace.id}` : Hyprland.active.client._title;
}),
})
]
+20 -1
View File
@@ -1,6 +1,7 @@
import { App, Utils, Widget } from '../../imports.js';
import Audio from 'resource:///com/github/Aylur/ags/service/audio.js';
import Mpris from 'resource:///com/github/Aylur/ags/service/mpris.js';
import SystemTray from 'resource:///com/github/Aylur/ags/service/systemtray.js';
const { execAsync } = Utils;
import Indicator from '../../services/indicator.js';
import { StatusIcons } from "../../lib/statusicons.js";
@@ -43,10 +44,28 @@ export const ModuleRightSpace = () => {
children: [
Widget.Box({
hexpand: true,
className: 'spacing-h-15 txt',
className: 'spacing-h-5 txt',
children: [
Widget.Box({ hexpand: true, }),
barTray,
Widget.Revealer({
transition: 'slide_left',
revealChild: false,
properties: [
['count', 0],
['update', (self, diff) => {
self._count += diff;
self.revealChild = (self._count > 0);
}]],
child: Widget.Box({
vpack: 'center',
className: 'separator-circle',
}),
setup: (self) => self
.hook(SystemTray, (self) => self._update(self, 1), 'added')
.hook(SystemTray, (self) => self._update(self, -1), 'removed')
,
}),
barStatusIcons,
],
}),
+1 -1
View File
@@ -25,7 +25,7 @@ const SysTrayItem = item => Button({
export const Tray = (props = {}) => {
const trayContent = Box({
className: 'bar-systray spacing-h-10',
className: 'margin-right-5 spacing-h-15',
properties: [
['items', new Map()],
['onAdded', (box, id) => {
+27 -18
View File
@@ -13,6 +13,11 @@ const IMAGE_REVEAL_DELAY = 13; // Some wait for inits n other weird stuff
Utils.exec(`bash -c 'mkdir -p ${GLib.get_user_cache_dir()}/ags/media/waifus'`);
Utils.exec(`bash -c 'rm ${GLib.get_user_cache_dir()}/ags/media/waifus/*'`);
export function fileExists(filePath) {
let file = Gio.File.new_for_path(filePath);
return file.query_exists(null);
}
const CommandButton = (command) => Button({
className: 'sidebar-chat-chip sidebar-chat-chip-action txt txt-small',
onClicked: () => sendMessage(command),
@@ -30,8 +35,6 @@ export const waifuTabIcon = Box({
});
const WaifuImage = (taglist) => {
var imagePath = '';
var blockImageData = {};
const ImageState = (icon, name) => Box({
className: 'spacing-h-5',
children: [
@@ -87,17 +90,17 @@ const WaifuImage = (taglist) => {
ImageAction({
name: 'Go to source',
icon: 'link',
action: () => execAsync(['xdg-open', `${blockImageData.source}`]).catch(print),
action: () => execAsync(['xdg-open', `${thisBlock._imageData.source}`]).catch(print),
}),
ImageAction({
name: 'Hoard',
icon: 'save',
action: () => execAsync(['bash', '-c', `mkdir -p ~/Pictures/waifus && cp ${imagePath} ~/Pictures/waifus`]).catch(print),
action: () => execAsync(['bash', '-c', `mkdir -p ~/Pictures/waifus && cp ${thisBlock._imagePath} ~/Pictures/waifus`]).catch(print),
}),
ImageAction({
name: 'Open externally',
icon: 'open_in_new',
action: () => execAsync(['xdg-open', `${imagePath}`]).catch(print),
action: () => execAsync(['xdg-open', `${thisBlock._imagePath}`]).catch(print),
}),
]
})
@@ -127,14 +130,16 @@ const WaifuImage = (taglist) => {
const thisBlock = Box({
className: 'sidebar-chat-message',
properties: [
['imagePath', ''],
['imageData', ''],
['update', (imageData, force = false) => {
blockImageData = imageData;
const { status, signature, url, source, dominant_color, is_nsfw, width, height, tags } = blockImageData;
thisBlock._imageData = imageData;
const { status, signature, url, extension, source, dominant_color, is_nsfw, width, height, tags } = thisBlock._imageData;
if (status != 200) {
downloadState.shown = 'error';
return;
}
imagePath = `${GLib.get_user_cache_dir()}/ags/media/waifus/${signature}`;
thisBlock._imagePath = `${GLib.get_user_cache_dir()}/ags/media/waifus/${signature}${extension}`;
downloadState.shown = 'download';
// Width allocation
const widgetWidth = Math.min(Math.floor(waifuContent.get_allocated_width() * 0.75), width);
@@ -142,7 +147,8 @@ const WaifuImage = (taglist) => {
// Start download
const showImage = () => {
downloadState.shown = 'done';
blockImage.css = `background-image:url('${imagePath}');`;
// blockImage.css = `background-color: ${dominant_color};`;
blockImage.css = `background-image:url('${thisBlock._imagePath}');`; // TODO: use proper image widget
Utils.timeout(IMAGE_REVEAL_DELAY, () => {
blockImageRevealer.revealChild = true;
})
@@ -151,8 +157,8 @@ const WaifuImage = (taglist) => {
);
downloadIndicator._hide();
}
if (!force && Gio.File.new_for_path(imagePath).query_exists(null)) showImage();
else Utils.execAsync(['bash', '-c', `wget -O '${imagePath}' '${url}'`])
if (!force && fileExists(thisBlock._imagePath)) showImage();
else Utils.execAsync(['bash', '-c', `wget -O '${thisBlock._imagePath}' '${url}'`])
.then(showImage)
.catch(print);
colorIndicator.css = `background-color: ${dominant_color};`;
@@ -274,17 +280,19 @@ export const waifuCommands = Box({
}
});
const clearChat = () => {
const kids = waifuContent.get_children();
for (let i = 0; i < kids.length; i++) {
const child = kids[i];
if (child) child.destroy();
}
}
export const sendMessage = (text) => {
// Do something on send
// Commands
if (text.startsWith('/')) {
if (text.startsWith('/clear')) {
const kids = waifuContent.get_children();
for (let i = kids.length - 1; i >= 0; i--) {
const child = kids[i];
child.destroy();
}
}
if (text.startsWith('/clear')) clearChat();
else if (text.startsWith('/test')) {
const newImage = WaifuImage(['/test']);
waifuContent.add(newImage);
@@ -292,6 +300,7 @@ export const sendMessage = (text) => {
// This is an image uploaded to my github repo
status: 200,
url: 'https://picsum.photos/400/600',
extension: '',
signature: 0,
source: 'https://picsum.photos/400/600',
dominant_color: '#9392A6',