This commit is contained in:
sankalp committed 2024-07-12 12:44:18 +05:45
1 parent 8b0cde6e86
commit 0389156702
10 files changed
+281 -120

No files matched your search

@@ -6,9 +6,9 @@ const { execAsync, exec } = Utils;
import { MaterialIcon } from "icons.ts";
import md2pango from "./md2pango.ts";
import { theme } from "variables.ts";
import Pango10 from "gi://Pango?version=1.0";
const LATEX_DIR = `${GLib.get_user_cache_dir()}/ags/media/latex`;
const CUSTOM_SCHEME_ID = `custom${theme.value == "dark" ? "" : "-light"}`;
const USERNAME = GLib.get_user_name();
function substituteLang(str) {
@@ -29,10 +29,11 @@ const HighlightedCode = (content, lang) => {
wrap_mode: Gtk.WrapMode.NONE
});
const langManager = GtkSource.LanguageManager.get_default();
let displayLang = langManager.get_language(substituteLang(lang)); // Set your preferred language
let displayLang = langManager.get_language(substituteLang(lang));
if (displayLang) {
buffer.set_language(displayLang);
}
const CUSTOM_SCHEME_ID = `custom${theme.value == "dark" ? "" : "-light"}`;
const schemeManager = GtkSource.StyleSchemeManager.get_default();
buffer.set_style_scheme(schemeManager.get_scheme(CUSTOM_SCHEME_ID));
buffer.set_text(content, -1);
@@ -46,6 +47,7 @@ const TextBlock = (content = "") =>
useMarkup: true,
xalign: 0,
wrap: true,
wrap_mode: Pango10.WrapMode.WORD_CHAR,
selectable: true,
label: content
});
@@ -53,6 +55,7 @@ const TextBlock = (content = "") =>
Utils.execAsync(["bash", "-c", `rm -rf ${LATEX_DIR}`])
.then(() => Utils.execAsync(["bash", "-c", `mkdir -p ${LATEX_DIR}`]))
.catch(print);
const Latex = (content = "") => {
const latexViewArea = Box({
// vscroll: 'never',
@@ -193,7 +196,7 @@ const Divider = () =>
class_name: "divider"
});
const MessageContent = (content) => {
export const MessageContent = (content) => {
const contentBox = Box({
vertical: true,
attribute: {
+5 -3
View File
@@ -1,5 +1,4 @@
// Converts from Markdown to Pango. This does not support code blocks.
// For illogical-impulse, code blocks are treated separately, in their own GtkSourceView widgets.
// Partly inherited from https://github.com/ubunatic/md2pango
const monospaceFonts = 'JetBrains Mono NF, JetBrains Mono Nerd Font, JetBrains Mono NL, SpaceMono NF, SpaceMono Nerd Font, monospace';
@@ -28,7 +27,7 @@ const replacements = {
{ name: 'EMPH', re: /\*(\S.*?\S)\*/g, sub: "<i>$1</i>" },
// { name: 'EMPH', re: /_(\S.*?\S)_/g, sub: "<i>$1</i>" },
{ name: 'HEXCOLOR', re: /#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})/g, sub: '<span bgcolor="#$1" fgcolor="#000000" font_family="' + monospaceFonts + '">#$1</span>' },
{ name: 'INLCODE', re: /(`)([^`]*)(`)/g, sub: '<span font_weight="bold" font_family="' + monospaceFonts + '">$2</span>' },
{ name: 'INLCODE', re: /(`)([^`]*)(`)/g, sub: '<span font_weight="500" font_family="' + monospaceFonts + '">$2</span>' },
// { name: 'UND', re: /(__|\*\*)(\S[\s\S]*?\S)(__|\*\*)/g, sub: "<u>$2</u>" },
],
}
@@ -68,8 +67,11 @@ export const markdownTest = `## Inline formatting
const std::string GREETING="UwU";
int main() { std::cout << GREETING; }
\`\`\`
\`\`\`py
print("Hello world!")
\`\`\`
## LaTeX
\`\`\`latex
\\frac{d}{dx} \\left( \\frac{x-438}{x^2+23x-7} \\right) = \\frac{-x^2 + 869}{(x^2+23x-7)^2} \\\\ → \\\\ cos(2x) = 2cos^2(x) - 1 = 1 - 2sin^2(x) = cos^2(x) - sin^2(x)
\`\`\`
`;
`;
+3
View File
@@ -0,0 +1,3 @@
import Gtk from "gi://Gtk?version=3.0";
export const TextView = Widget.subclass<typeof Gtk.TextView, Gtk.TextView.ConstructorProperties>(Gtk.TextView, "AgsTextView");
+4 -4
View File
@@ -37,9 +37,9 @@ export const Notification = (notification: NotificationType, dismiss = true) =>
vertical: true,
children: [
Widget.EventBox({
on_primary_click_release: (box) => {
// @ts-ignore
const label: Label<any> = box.child.children[1].children[1];
on_primary_click: (box) => {
// @ts-expect-error
const label: Label<any> = box.child.children[1]!.children[1]!;
if (label.lines < 0) {
label.lines = 3;
label.truncate = "end";
@@ -73,7 +73,7 @@ export const Notification = (notification: NotificationType, dismiss = true) =>
}),
Widget.Label({
class_name: "notification-time",
label: GLib.DateTime.new_from_unix_local(notification.time).format("%I:%M %p")
label: GLib.DateTime.new_from_unix_local(notification.time).format("%H:%M")
}),
Widget.Button({
class_name: "standard_icon_button notification-close",
+68 -15
View File
@@ -1,11 +1,11 @@
import Gtk from "gi://Gtk?version=3.0";
import GeminiService from "services/gemini.js";
import GeminiService from "services/gemini.ts";
import { MaterialIcon } from "icons.ts";
import { ChatMessage, SystemMessage } from "modules/misc/ai_chat_message.ts";
import { ChatMessage, SystemMessage } from "modules/misc/chat_message.ts";
import { markdownTest } from "modules/misc/md2pango.ts";
import Gdk from "gi://Gdk";
const TextView = Widget.subclass<typeof Gtk.TextView, Gtk.TextView.ConstructorProperties>(Gtk.TextView, "AgsTextView");
import { enableClickThrough } from "../misc/clickthrough.js";
import { TextView } from "modules/misc/textview.js";
function apiSendMessage(textView: any) {
// Get text
@@ -26,12 +26,15 @@ const chatEntry: any = TextView({
wrap_mode: Gtk.WrapMode.WORD_CHAR,
accepts_tab: false,
class_name: "chat_entry",
attribute: { placeholder: "Message Gemini..." },
setup: (self: any) => {
self.set_valign(Gtk.Align.CENTER);
self.hook(
GeminiService,
(self) => {
self.placeholderText =
() => {
self.attribute.placeholder =
GeminiService.key.length > 0 ? "Message Gemini..." : "Enter Google AI API Key...";
chatPlaceholder.label = self.attribute.placeholder;
},
"hasKey"
).on("key-press-event", (widget, event) => {
@@ -45,11 +48,6 @@ const chatEntry: any = TextView({
return false;
}
});
const buffer = self.get_buffer();
buffer.connect("changed", () => {
const line_count = buffer.get_line_count();
chatEntryWrapper.toggleClassName("chat_wrapper_extended", line_count >= 2);
});
}
});
@@ -60,14 +58,69 @@ const chatEntryWrapper = Widget.Scrollable({
child: chatEntry,
setup: (self) => {
chatEntry.connect("focus-in-event", () => {
self.toggleClassName("focused", true);
textboxArea.toggleClassName("focused", true);
});
chatEntry.connect("focus-out-event", () => {
self.toggleClassName("focused", false);
textboxArea.toggleClassName("focused", false);
});
}
});
chatEntry.get_buffer().connect("changed", (buffer) => {
const bufferText = buffer.get_text(buffer.get_start_iter(), buffer.get_end_iter(), true);
// chatSendButton.toggleClassName("chat_wrapper_extended", bufferText.length > 0);
chatPlaceholderRevealer.reveal_child = bufferText.length == 0;
if (buffer.get_line_count() > 2 || bufferText.length > 30) {
chatEntryWrapper.toggleClassName("chat_wrapper_extended", true);
chatEntry.set_valign(Gtk.Align.FILL);
chatPlaceholder.set_valign(Gtk.Align.FILL);
} else {
chatEntryWrapper.toggleClassName("chat_wrapper_extended", false);
chatEntry.set_valign(Gtk.Align.CENTER);
chatPlaceholder.set_valign(Gtk.Align.CENTER);
}
});
const chatPlaceholder = Widget.Label({
className: "placeholder",
hpack: "start",
vpack: "center",
label: chatEntry.attribute.placeholder
});
const chatPlaceholderRevealer = Widget.Revealer({
revealChild: true,
transition: "crossfade",
transitionDuration: 200,
child: chatPlaceholder,
setup: enableClickThrough
});
const chatSendButton = Widget.Button({
className: "send standard_icon_button",
child: MaterialIcon("send", "24px"),
vpack: "center",
hpack: "end",
css: "font-size: 24px",
onClicked: (self) => {
apiSendMessage(chatEntry);
}
});
const textboxArea = Widget.Box({
// Entry area
className: "textbox",
children: [
Widget.Overlay({
passThrough: true,
child: chatEntryWrapper,
overlays: [chatPlaceholderRevealer]
}),
Widget.Box({ className: "width-10" }),
chatSendButton
]
});
const GeminiInfo = () => {
const geminiLogo = Widget.Icon({
hpack: "center",
@@ -96,7 +149,7 @@ const GeminiInfo = () => {
label: "Powered by Google"
}),
Widget.Button({
class_name: "description",
class_name: "description icon material_icon",
label: "info",
tooltipText:
"Uses gemini-pro.\nNot affiliated, endorsed, or sponsored by Google.\n\nPrivacy: Chat messages aren't linked to your account,\n but will be read by human reviewers to improve the model."
@@ -269,5 +322,5 @@ const geminiView = Widget.Box({
export const geminiPage = Widget.Box({
class_name: "page gemini",
vertical: true,
children: [geminiView, geminiCommands, chatEntryWrapper]
children: [geminiView, geminiCommands, textboxArea]
});
+7 -6
View File
@@ -1,8 +1,8 @@
import popupwindow from "../misc/popupwindow.js";
import popupwindow from "../misc/popupwindow.ts";
import Gtk from "gi://Gtk?version=3.0";
import { MaterialIcon } from "icons.ts";
import { WeatherBox } from "./weather.js";
import { Media } from "./players.js";
import { WeatherBox } from "./weather.ts";
import { Media } from "./players.ts";
import { Applauncher } from "./applauncher.ts";
import { geminiPage } from "./gemini.ts";
@@ -31,13 +31,14 @@ type ButtonType = {
page: string;
label: string;
icon?: string;
icon_widget?: Gtk.Widget
icon_widget?: Gtk.Widget;
};
function Button({ page, label, icon, icon_widget }: ButtonType) {
return Widget.Button({
class_name: `navigation_button _${page}`,
hexpand: true,
vpack: "start",
child: Widget.Box({
orientation: Gtk.Orientation.VERTICAL,
class_name: "container_outer",
@@ -48,7 +49,7 @@ function Button({ page, label, icon, icon_widget }: ButtonType) {
hpack: "center",
class_name: "container"
}),
overlay: (icon) ? MaterialIcon(icon!, "20px") : icon_widget!,
overlay: icon ? MaterialIcon(icon!, "20px") : icon_widget!,
pass_through: true
}),
Widget.Label({
@@ -111,7 +112,7 @@ function Navigation() {
size: 20,
class_name: "icon"
})
})
}),
]
});
return Widget.Box({
+4 -3
View File
@@ -1,5 +1,5 @@
import { MprisPlayer } from "types/service/mpris.js";
import Label from "types/widgets/label.js";
import { MprisPlayer } from "types/service/mpris.ts";
import Label from "types/widgets/label.ts";
import { MaterialIcon } from "icons.ts";
const mpris = await Service.import("mpris");
const players = mpris.bind("players");
@@ -98,7 +98,7 @@ function Player(player: MprisPlayer) {
on_clicked: () => player.playPause(),
visible: player.bind("can_play"),
child: MaterialIcon(
// @ts-ignore
// @ts-expect-error
player.bind("play_back_status").transform((s) => {
switch (s) {
case "Playing":
@@ -155,6 +155,7 @@ export function Media() {
return Widget.Box({
vertical: true,
css: "min-height: 2px; min-width: 2px;",
vpack: "start",
visible: players.as((p) => p.length > 0),
children: players.as((p) => p.map(Player))
});
+23 -27
View File
@@ -16,31 +16,32 @@ const MATERIAL_ICONS = {
"40d": "air", "40n": "air"
};
const ICON_COLORS = {
mist: "#90A4AE",
clear_day: "#FFF176",
bedtime: "#7986CB",
partly_cloudy_day: "#2196F3",
partly_cloudy_night: "#7986CB",
cloud: "#4FC3F7",
mist: "#B0BEC5",
clear_day: "#FFEB3B",
bedtime: "#9575CD",
partly_cloudy_day: "#42A5F5",
partly_cloudy_night: "#8C9EFF",
cloud: "#81D4FA",
rainy_heavy: "#039BE5",
rainy: "#2196F3",
thunderstorm: "#FFC107",
weather_snowy: "#00BCD4",
air: "#00BCD4"
rainy: "#64B5F6",
thunderstorm: "#FFB300",
weather_snowy: "#4DD0E1",
air: "#00ACC1"
};
const _T = "°";
function WeatherFirstCard(weather: WeatherJson) {
const _box = (icon: string, info: string, tooltip?: string) => Widget.Box({
class_name: "info_box",
children: [
MaterialIcon(icon, "20px"),
Widget.Label({
label: info
})
],
tooltip_text: tooltip
})
const _box = (icon: string, info: string, tooltip?: string) =>
Widget.Box({
class_name: "info_box",
children: [
MaterialIcon(icon, "20px"),
Widget.Label({
label: info
})
],
tooltip_text: tooltip
});
const temp_label = Widget.Label({
class_name: "current",
vpack: "end",
@@ -83,7 +84,7 @@ function WeatherFirstCard(weather: WeatherJson) {
_box("cloud", `${weather.clouds.all}%`, "Cloudiness"),
_box("humidity_percentage", `${weather.main.humidity}%`, "Humidity")
]
})
});
const color = ICON_COLORS[MATERIAL_ICONS[weather.weather[0].icon]];
const temp = Widget.Box({
class_name: "card",
@@ -96,7 +97,6 @@ function WeatherFirstCard(weather: WeatherJson) {
hpack: "start",
children: [
MaterialIcon(MATERIAL_ICONS[weather.weather[0].icon], "", {
vpack: "end",
css: `font-size: 32px; color: ${color}`
}),
temp_label,
@@ -178,11 +178,7 @@ export function WeatherBox() {
label: cur_weather.name,
hpack: "start"
});
self.children = [
title,
WeatherFirstCard(cur_weather),
WeatherSecondCard(cur_weather)
];
self.children = [title, WeatherFirstCard(cur_weather), WeatherSecondCard(cur_weather)];
}
});
}
+57 -23
View File
@@ -9,28 +9,62 @@ type NotificationsBoxType = {
include?: string[];
};
const NotificationNoReveal = (notification: NotificationType, visible = false, dismiss = true) => {
const _notification = Notification(notification, dismiss);
const destroyWithAnims = () => {
box.destroy();
};
let box: Box<any, { destroyWithAnims: any; count: number; id: number }> = Widget.Box({
const NotificationReveal = (notification: NotificationType, visible = false, dismiss = true) => {
const transition_duration = 200;
const secondRevealer = Widget.Revealer({
vpack: "center",
child: Notification(notification, dismiss),
reveal_child: visible,
transition: "crossfade",
transition_duration: transition_duration,
hexpand: true,
attribute: {
destroyWithAnims,
count: 0,
id: notification.id,
},
children: [_notification],
class_name: "second_revealer",
setup: (revealer) => {
Utils.timeout(1, () => {
revealer.reveal_child = true;
});
}
});
const firstRevealer = Widget.Revealer({
child: secondRevealer,
reveal_child: true,
transition: "slide_down",
transition_duration: transition_duration,
class_name: "first_revealer"
});
type BoxAttrs = {
destroyWithAnims: any;
count: number;
id: number;
};
let box: Box<any, BoxAttrs>;
const destroyWithAnims = () => {
secondRevealer.reveal_child = false;
Utils.timeout(transition_duration, () => {
firstRevealer.reveal_child = false;
Utils.timeout(transition_duration, () => {
box.destroy();
});
});
};
box = Widget.Box({
hexpand: true,
attribute: {
destroyWithAnims: destroyWithAnims,
count: 0,
id: notification.id
},
children: [firstRevealer]
});
return box;
};
export function NotificationsBox({ exclude = [], include = [] }: NotificationsBoxType) {
const popups = NotificationPopups(false, { exclude, include }, false, NotificationNoReveal);
const popups = NotificationPopups(false, { exclude: exclude, include: include }, false, NotificationReveal);
const menu = Widget.Menu({
class_name: "notifications_menu",
@@ -38,19 +72,19 @@ export function NotificationsBox({ exclude = [], include = [] }: NotificationsBo
Widget.MenuItem({
child: Widget.Label({
label: "Close all",
hpack: "start",
hpack: "start"
}),
class_name: "notifications_menu_item",
on_activate: () => {
notifications.notifications.forEach((n) => {
for (let n of notifications.notifications) {
if (n) {
n.dismiss();
n.close();
}
});
},
}),
],
}
}
})
]
});
return Widget.EventBox({
@@ -63,7 +97,7 @@ export function NotificationsBox({ exclude = [], include = [] }: NotificationsBo
class_name: "notifications_sidebar_scrollable",
hscroll: "never",
child: popups,
hexpand: true,
}),
hexpand: true
})
});
}
+104 -36
View File
@@ -514,15 +514,36 @@ window.notification-popups box.notifications {
transition: all 0.25s ease-in-out;
}
.notifications_sidebar_scrollable {
padding-top: 6px;
}
.notifications_sidebar_scrollable scrollbar {
opacity: 0.1;
}
.notifications_sidebar_scrollable .notification {
margin-left: 10px;
margin-right: 9px;
border-radius: 14px;
margin-top: 10px;
margin-top: 4px;
border-radius: 6px;
padding: 15px;
background-color: @surfaceContainerLow;
box-shadow: 0px 0px 2px mix(@shadow, transparent, 0.75);
transition: all 0.25s ease-in-out;
box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.12), 0px 1px 2px rgba(0, 0, 0, 0.24);
transition: all 0.2s ease-in-out, border-radius 0.1s ease-in-out;
}
.notifications_sidebar_scrollable viewport > box > :first-child .notification {
border-radius: 14px 14px 6px 6px;
}
.notifications_sidebar_scrollable viewport > box > :last-child .notification {
border-radius: 6px 6px 14px 14px;
margin-bottom: 10px;
}
.notifications_sidebar_scrollable viewport > box > :last-child:first-child .notification {
border-radius: 14px;
}
.notifications_sidebar_scrollable .notification-time {
@@ -593,7 +614,7 @@ window.notification-popups box.notifications {
background-color: @surfaceContainerLow;
padding: 26px;
border-radius: 14px;
box-shadow: 0px 0px 2px mix(@shadow, transparent, 0.75);
box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.12), 0px 1px 2px rgba(0, 0, 0, 0.24);
}
.system_box .usage_box {
@@ -856,6 +877,10 @@ filled_button.disabled .awesome_icon,
color: @onSurface;
}
.rail .label {
font-weight: 500;
}
.navigation_button .container {
transition-property: all, border-image, background-size, background-image;
transition-duration: 0.3s, 0.3s, 0.3s, 0.3s;
@@ -875,6 +900,7 @@ filled_button.disabled .awesome_icon,
.rail .navigation_button .container {
padding-left: 12px;
padding-right: 12px;
min-height: 28px;
}
.navigation_button .icon {
@@ -1015,7 +1041,7 @@ switch:checked:active slider {
border-radius: 17px;
padding-top: 7px;
padding-bottom: 7px;
box-shadow: 0px 0px 2px mix(@shadow, transparent, 0.75);
box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.12), 0px 1px 2px rgba(0, 0, 0, 0.24);
}
.cheatsheet .category separator {
@@ -1082,10 +1108,6 @@ switch:checked:active slider {
padding-top: 12px;
}
.sideleft label {
color: @onSurface;
}
.sideleft .page {
min-width: 320px;
}
@@ -1096,10 +1118,14 @@ switch:checked:active slider {
border-radius: 12px;
margin-bottom: 10px;
margin-right: 12px;
box-shadow: 0px 0px 2px mix(@shadow, transparent, 0.75);
box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.12), 0px 1px 2px rgba(0, 0, 0, 0.24);
margin-left: 2px;
}
.sideleft .card {
color: @onSurface;
}
.sideleft .main_title {
color: @onSurface;
font-size: 24px;
@@ -1328,30 +1354,64 @@ switch:checked:active slider {
margin-right: 16px;
color: @onSurface;
}
/* Gemini */
.gemini .chat_wrapper {
/* Chats */
.sideleft .textbox {
background-color: transparent;
padding: 5px;
border-radius: 4px;
margin-right: 12px;
margin-bottom: 8px;
box-shadow: inset 0 0 0 1px @outline;
transition: box-shadow 0.2s ease-in-out, min-height 0.35s ease-in-out;
transition: box-shadow 0.2s ease-in-out;
}
.gemini .chat_wrapper_extended {
.sideleft .textbox scrollbar {
opacity: 0;
}
.sideleft .send .icon {
font-weight: 400;
}
.sideleft .send {
padding: 5px;
padding-left: 0.5rem;
padding-right: 0.5rem;
}
.sideleft .placeholder label {
color: @onSurfaceVariant;
}
.sideleft .chat_wrapper {
transition: min-height 0.35s ease-in-out;
}
.sideleft .chat_wrapper scrollbar {
opacity: 0;
}
.sideleft .chat_wrapper_extended {
min-height: 5rem;
}
.gemini .chat_wrapper.focused {
.sideleft .chat_wrapper_extended scrollbar {
opacity: 0.1;
}
.sideleft .textbox.focused {
box-shadow: inset 0 0 0 2px @primary;
}
.gemini .chat_wrapper text {
.sideleft .chat_wrapper text {
background-color: transparent;
}
.gemini .message {
.sideleft .latex * {
color: @onSurface;
}
.sideleft .message {
background-color: @surfaceContainerLow;
padding: 14px;
border-radius: 12px;
@@ -1361,6 +1421,12 @@ switch:checked:active slider {
margin-left: 2px;
}
.sideleft .message.ephemeral {
background-color: @surface;
box-shadow: none;
border: 1px solid @outlineVariant;
}
.codeblock_top_bar {
border-radius: 12px 12px 0px 0px;
background-color: @surfaceContainerLowest;
@@ -1395,10 +1461,24 @@ switch:checked:active slider {
background-color: @surfaceContainerLowest;
}
.gemini .divider {
.sideleft .divider {
background-color: @outlineVariant;
}
.sideleft .chat_name {
font-size: 17px;
font-weight: 500;
}
.sideleft .description {
font-size: 15px;
}
.sideleft .name {
font-size: 17px;
}
/* Gemini */
.gemini .command_button {
padding: 6px;
padding-left: 8px;
@@ -1419,36 +1499,24 @@ switch:checked:active slider {
border-radius: 100%;
}
.gemini .chat_name {
font-size: 17px;
font-weight: 500;
}
.gemini .description {
font-size: 15px;
}
.gemini .name {
font-size: 17px;
}
@keyframes pulsate {
0% {
background-color: transparent;
background-color: transparent;
}
50% {
background-color: @outline;
}
100% {
background-color: transparent;
background-color: transparent;
}
}
}
/* -----------------------------------------------------
* Material
* ----------------------------------------------------- */
.material_icon {
.material_icon,
.material_icon * {
all: unset;
font-family: "Material Symbols Outlined", "Material Symbols Sharp";
}