diff --git a/config/ags/apps/settings/main.ts b/config/ags/apps/settings/main.ts index c4fef2a8..472aff16 100644 --- a/config/ags/apps/settings/main.ts +++ b/config/ags/apps/settings/main.ts @@ -6,6 +6,7 @@ import { Wallpapers } from "./wallpapers"; import { Info } from "./info"; import { Apps } from "./apps"; import { MaterialIcon } from "icons"; +import { Weather } from "./weather"; const hyprland = await Service.import("hyprland"); import Gtk from "gi://Gtk?version=3.0"; @@ -41,7 +42,8 @@ function Settings(cur_tab: string) { appearance: Page(Appearance(), "Appearance"), wallpaper: Page(Wallpapers(), "Wallpapers"), info: Page(Info(), "Info"), - apps: Page(Apps(), "Apps") + apps: Page(Apps(), "Apps"), + "weather": Page(Weather(), "Weather") } }); const Row = (name: string, label: string, icon: string = "image-missing") => @@ -67,6 +69,7 @@ function Settings(cur_tab: string) { Row("wallpaper", "Wallpapers", "image"), Widget.Separator(), Row("apps", "Apps", "grid_view"), + Row("weather", "Weather", "cloud"), Widget.Separator(), Row("info", "Info", "info") ] diff --git a/config/ags/apps/settings/weather.ts b/config/ags/apps/settings/weather.ts new file mode 100644 index 00000000..a7acafd2 --- /dev/null +++ b/config/ags/apps/settings/weather.ts @@ -0,0 +1,105 @@ +import conf from "services/configuration.ts"; + +const WeatherKey = () => + Widget.EventBox({ + class_name: "row", + on_secondary_click_release: (self) => { + Utils.execAsync(`xdg-open "https://openweathermap.org/api"`).catch(print); + }, + child: Widget.Box({ + class_name: "row", + vpack: "start", + children: [ + Widget.Box({ + vertical: true, + hexpand: true, + vpack: "center", + hpack: "start", + children: [ + Widget.Label({ + hpack: "start", + class_name: "title", + label: "Api key" + }), + Widget.Label({ + hpack: "start", + class_name: "description", + label: "openweathermap.org api key" + }) + ] + }), + Widget.Entry({ + max_length: 32, + hpack: "end", + css: "border: 2px solid; border-color: transparent;", + visibility: false, + text: conf.config.weather, + on_accept: (self) => { + if (self.text!.length == 32) { + self.css = "border: 2px solid; border-color: #66BB6A"; + Utils.timeout(1000, () => { + self.css = "border: 2px solid; border-color: transparent"; + }); + conf.set_value("weather", self.text!); + } + } + }) + ] + }) + }); + +const WeatherLocationKey = () => + Widget.EventBox({ + class_name: "row", + on_secondary_click_release: (self) => { + Utils.execAsync(`xdg-open "https://openweathermap.org"`).catch(print); + }, + child: Widget.Box({ + class_name: "row", + vpack: "start", + children: [ + Widget.Box({ + vertical: true, + hexpand: true, + vpack: "center", + hpack: "start", + children: [ + Widget.Label({ + hpack: "start", + class_name: "title", + label: "Location key" + }), + Widget.Label({ + hpack: "start", + class_name: "description", + label: "Search for your city at openweathermap.org" + }) + ] + }), + Widget.Entry({ + hpack: "end", + css: "border: 2px solid; border-color: transparent;", + text: conf.config.weather_location_id, + on_accept: (self) => { + self.css = "border: 2px solid; border-color: #66BB6A"; + Utils.timeout(1000, () => { + self.css = "border: 2px solid; border-color: transparent"; + }); + conf.set_value("weather_location_id", self.text!); + } + }) + ] + }) + }); + +export function Weather() { + const box = Widget.Box({ + vertical: true, + children: [WeatherKey(), WeatherLocationKey()] + }); + return Widget.Scrollable({ + hscroll: "never", + child: box, + vexpand: true + }); +} diff --git a/config/ags/assets/icons/google-gemini-symbolic.svg b/config/ags/assets/icons/google-gemini-symbolic.svg new file mode 100644 index 00000000..742f3972 --- /dev/null +++ b/config/ags/assets/icons/google-gemini-symbolic.svg @@ -0,0 +1,56 @@ + + + + + + + ionicons-v5_logos + + + + + ionicons-v5_logos + + + + \ No newline at end of file diff --git a/config/ags/assets/wall.json b/config/ags/assets/wall.json deleted file mode 100644 index 95b6da62..00000000 --- a/config/ags/assets/wall.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - custom-color: "none", - generation-scheme: "tonalSpot" -} diff --git a/config/ags/config.js b/config/ags/config.js index 2225509b..36f7a9a1 100644 --- a/config/ags/config.js +++ b/config/ags/config.js @@ -1,16 +1,19 @@ -const entry = App.configDir + '/main.ts' -const outdir = '/tmp/ags/js' +const entry = App.configDir + "/main.ts"; +const outdir = "/tmp/ags/js"; + +App.addIcons(`${App.configDir}/assets/icons`); try { + // prettier-ignore await Utils.execAsync([ - 'bun', 'build', entry, - '--outdir', outdir, - '--external', 'resource://*', - '--external', 'gi://*', - ]) - await import(`file://${outdir}/main.js`) + "bun", "build", entry, + "--outdir", outdir, + "--external", "resource://*", + "--external", "gi://*" + ]); + await import(`file://${outdir}/main.js`); } catch (error) { - console.error(error) + console.error(error); } -export { } +export {}; diff --git a/config/ags/main.ts b/config/ags/main.ts index d334819c..3a74aeee 100644 --- a/config/ags/main.ts +++ b/config/ags/main.ts @@ -4,10 +4,9 @@ import Gdk from "gi://Gdk"; // widgets import { Bar, BarCornerTopLeft, BarCornerTopRight } from "./modules/bar.ts"; 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 { sideright } from "./modules/sideright/main.ts"; +import { sideleft } from "./modules/sideleft/main.ts"; import {} from "apps/settings/main.ts"; import {} from "apps/emoji/main.ts"; import { cheatsheet } from "modules/cheatsheet.ts"; @@ -28,11 +27,10 @@ const Windows = () => [ forMonitors(Notifications), forMonitors(BarCornerTopLeft), forMonitors(BarCornerTopRight), - media, - applauncher, cliphist, sideright, - cheatsheet + cheatsheet, + sideleft ]; const CLOSE_ANIM_TIME = 210; @@ -50,7 +48,6 @@ App.config({ function ReloadCSS() { App.resetCss(); - // Utils.execAsync(`cp -f -r ${GLib.get_home_dir()}/dotfiles/material-colors/generated/svg/ ${App.configDir}/`).catch(print) App.applyCss(`${App.configDir}/style.css`); App.applyCss(`${App.configDir}/style-apps.css`); } diff --git a/config/ags/modules/bar.ts b/config/ags/modules/bar.ts index 58c375bd..2e62d446 100644 --- a/config/ags/modules/bar.ts +++ b/config/ags/modules/bar.ts @@ -18,6 +18,7 @@ const bluetooth = await Service.import("bluetooth"); import Gtk from "gi://Gtk?version=3.0"; import { MaterialIcon } from "icons.js"; import config from "services/configuration.ts"; +import { toggleAppsWindow, toggleMediaWindow } from "./sideleft/main.js"; function checkKeymap() { const layout = Utils.execAsync(`hyprctl devices -j | jq -r '.keyboards[] | select(.main == true) | .active_keymap' | tail -n1 | cut -c1-2 | tr 'A-Z' 'a-z'`) @@ -250,7 +251,7 @@ function AppLauncher() { const button = Widget.Button({ class_name: "filled_tonal_button", on_clicked: () => { - App.toggleWindow("applauncher"); + toggleAppsWindow(); }, child: MaterialIcon("search") }); @@ -258,6 +259,18 @@ function AppLauncher() { return button; } +function OpenSideLeft() { + const button = Widget.Button({ + class_name: "filled_tonal_button", + on_clicked: () => { + App.toggleWindow("sideleft"); + }, + child: MaterialIcon("dock_to_right") + }); + + return button; +} + function Wifi() { return Widget.Button({ class_name: "bar_wifi", @@ -321,7 +334,7 @@ function MediaPlayer() { const button = Widget.Button({ class_name: "filled_tonal_button", on_primary_click_release: () => { - App.toggleWindow("media"); + toggleMediaWindow(); }, on_secondary_click_release: () => { Utils.execAsync(["playerctl", "play-pause"]).catch(print); @@ -337,7 +350,6 @@ function MediaPlayer() { } else { self.visible = false; self.tooltip_text = "Unknown"; - App.closeWindow("media"); } }); @@ -384,7 +396,7 @@ function TaskBar() { clients.forEach((item) => { let widget = globalWidgets.find((w) => w.attribute.pid === item.pid); - if (item.class == "kitty") { + if (item.class == "Alacritty") { return; } if (widget) { @@ -410,7 +422,6 @@ function TaskBar() { } }); return globalWidgets; - } return Widget.Box({ @@ -467,7 +478,7 @@ function Left() { class_name: "modules-left", hpack: "start", spacing: 8, - children: [AppLauncher(), MediaPlayer(), TaskBar()] + children: [AppLauncher(), OpenSideLeft(), MediaPlayer(), TaskBar()] }); } diff --git a/config/ags/modules/cliphist.ts b/config/ags/modules/cliphist.ts index d679963d..b85e9f3f 100644 --- a/config/ags/modules/cliphist.ts +++ b/config/ags/modules/cliphist.ts @@ -8,12 +8,11 @@ type EntryObject = { content: string; entry: string; }; -// · function ClipHistItem(entry: string) { - let [id, ...content] = entry.split("\t"); + const [id, ...content] = entry.split("\t"); let clickCount = 0; - let button = Widget.Button({ + const button = Widget.Button({ class_name: "clip_container", child: Widget.Box({ children: [ @@ -78,31 +77,33 @@ function ClipHistWidget({ width = 500, height = 500, spacing = 12 }) { }); async function repopulate() { - output = await Utils.execAsync(`${App.configDir}/scripts/cliphist.sh --get`) - .then((str) => str) - .catch((err) => { - print(err); - return ""; - }); + try { + output = await Utils.execAsync(`${App.configDir}/scripts/cliphist.sh --get`); + } catch (err) { + print(err); + output = ""; + } + entries = output.split("\n").filter((line) => line.trim() !== ""); clipHistItems = entries.map((entry) => { - let [id, ...content] = entry.split("\t"); + const [id, ...content] = entry.split("\t"); return { id: id.trim(), content: content.join(" ").trim(), entry: entry }; }); widgets = clipHistItems.map((item) => ClipHistItem(item.entry)); list.children = widgets; } - repopulate(); const entry = Widget.Entry({ hexpand: true, class_name: "cliphistory_entry", placeholder_text: "Search", - - on_change: ({ text }) => + on_change: ({ text }) => { + const searchText = text.toLowerCase(); widgets.forEach((item) => { - item.visible = item.attribute.content.match(text ?? ""); - }) + const content = item.attribute.content.toLowerCase(); + item.visible = content.includes(searchText); + }); + } }); return Widget.Box({ @@ -115,7 +116,7 @@ function ClipHistWidget({ width = 500, height = 500, spacing = 12 }) { Widget.Separator(), Widget.Scrollable({ hscroll: "never", - css: `min-width: ${width}px;` + `min-height: ${height}px;`, + css: `min-width: ${width}px; min-height: ${height}px;`, child: list }) ], @@ -133,7 +134,6 @@ function ClipHistWidget({ width = 500, height = 500, spacing = 12 }) { export const cliphist = popupwindow({ name: WINDOW_NAME, - class_name: "cliphistory", visible: false, keymode: "exclusive", diff --git a/config/ags/modules/misc/ai_chat_message.ts b/config/ags/modules/misc/ai_chat_message.ts new file mode 100644 index 00000000..2f1cb8a4 --- /dev/null +++ b/config/ags/modules/misc/ai_chat_message.ts @@ -0,0 +1,368 @@ +const { Gdk, Gio, GLib, Gtk } = imports.gi; +// @ts-expect-error +import GtkSource from "gi://GtkSource?version=3.0"; +const { Box, Button, Label, Icon, Scrollable, Stack } = Widget; +const { execAsync, exec } = Utils; +import { MaterialIcon } from "icons.ts"; +import md2pango from "./md2pango.ts"; +import { theme } from "variables.ts"; + +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) { + const subs = [ + { from: "javascript", to: "js" }, + { from: "bash", to: "sh" } + ]; + for (const { from, to } of subs) { + if (from === str) return to; + } + return str; +} + +const HighlightedCode = (content, lang) => { + const buffer = new GtkSource.Buffer(); + const sourceView = new GtkSource.View({ + buffer: buffer, + wrap_mode: Gtk.WrapMode.NONE + }); + const langManager = GtkSource.LanguageManager.get_default(); + let displayLang = langManager.get_language(substituteLang(lang)); // Set your preferred language + if (displayLang) { + buffer.set_language(displayLang); + } + const schemeManager = GtkSource.StyleSchemeManager.get_default(); + buffer.set_style_scheme(schemeManager.get_scheme(CUSTOM_SCHEME_ID)); + buffer.set_text(content, -1); + return sourceView; +}; + +const TextBlock = (content = "") => + Label({ + hpack: "fill", + class_name: "text_block", + useMarkup: true, + xalign: 0, + wrap: true, + selectable: true, + label: 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', + // hscroll: 'automatic', + // homogeneous: true, + attribute: { + render: async (self, text) => { + if (text.length == 0) return; + const styleContext = self.get_style_context(); + const fontSize = styleContext.get_property("font-size", Gtk.StateFlags.NORMAL); + + const timeSinceEpoch = Date.now(); + const fileName = `${timeSinceEpoch}.tex`; + const outFileName = `${timeSinceEpoch}-symbolic.svg`; + const outIconName = `${timeSinceEpoch}-symbolic`; + const scriptFileName = `${timeSinceEpoch}-render.sh`; + const filePath = `${LATEX_DIR}/${fileName}`; + const outFilePath = `${LATEX_DIR}/${outFileName}`; + const scriptFilePath = `${LATEX_DIR}/${scriptFileName}`; + + Utils.writeFile(text, filePath).catch(print); + // Since MicroTex doesn't support file path input properly, we gotta cat it + // And escaping such a command is a fucking pain so I decided to just generate a script + // Note: MicroTex doesn't support `&=` + // You can add this line in the middle for debugging: echo "$text" > ${filePath}.tmp + const renderScript = `#!/usr/bin/env bash +text=$(cat ${filePath} | sed 's/$/ \\\\\\\\/g' | sed 's/&=/=/g') +cd /opt/MicroTeX +./LaTeX -headless -input="$text" -output=${outFilePath} -textsize=${fontSize * 1.1} -padding=0 -maxwidth=${ + latexViewArea.get_allocated_width() * 0.85 + } > /dev/null 2>&1 +sed -i 's/fill="rgb(0%, 0%, 0%)"/style="fill:#000000"/g' ${outFilePath} +sed -i 's/stroke="rgb(0%, 0%, 0%)"/stroke="${theme.value == "dark" ? "#ffffff" : "#000000"}"/g' ${outFilePath} +`; + Utils.writeFile(renderScript, scriptFilePath).catch(print); + Utils.exec(`chmod a+x ${scriptFilePath}`); + Utils.timeout(100, () => { + Utils.exec(`bash ${scriptFilePath}`); + Gtk.IconTheme.get_default().append_search_path(LATEX_DIR); + + self.child?.destroy(); + self.child = Gtk.Image.new_from_icon_name(outIconName, 0); + }); + } + }, + setup: (self) => self.attribute.render(self, content).catch(print) + }); + const wholeThing = Box({ + class_name: "latex", + homogeneous: true, + attribute: { + updateText: (text) => { + latexViewArea.attribute.render(latexViewArea, text).catch(print); + } + }, + children: [ + Scrollable({ + vscroll: "never", + hscroll: "automatic", + child: latexViewArea + }) + ] + }); + return wholeThing; +}; + +const CodeBlock = (content = "", lang = "txt") => { + if (lang == "tex" || lang == "latex") { + return Latex(content); + } + const topBar = Box({ + class_name: "codeblock_top_bar", + children: [ + Label({ + label: lang, + class_name: "codeblock_top_bar_text" + }), + Box({ + hexpand: true + }), + Button({ + class_name: "codeblock_top_bar_button standard_button", + child: Box({ + spacing: 5, + children: [ + MaterialIcon("content_copy", "small"), + Label({ + label: "Copy" + }) + ] + }), + onClicked: (self) => { + const buffer = sourceView.get_buffer(); + const copyContent = buffer.get_text(buffer.get_start_iter(), buffer.get_end_iter(), false); // TODO: fix this + execAsync([`wl-copy`, `${copyContent}`]).catch(print); + } + }) + ] + }); + // Source view + const sourceView = HighlightedCode(content, lang); + + const codeBlock = Box({ + attribute: { + updateText: (text) => { + sourceView.get_buffer().set_text(text, -1); + } + }, + class_name: "codeblock", + vertical: true, + children: [ + topBar, + Box({ + class_name: "codeblock_code", + homogeneous: true, + children: [ + Scrollable({ + vscroll: "never", + hscroll: "automatic", + child: sourceView + }) + ] + }) + ] + }); + + // const schemeIds = styleManager.get_scheme_ids(); + + // print("Available Style Schemes:"); + // for (let i = 0; i < schemeIds.length; i++) { + // print(schemeIds[i]); + // } + return codeBlock; +}; + +const Divider = () => + Box({ + class_name: "divider" + }); + +const MessageContent = (content) => { + const contentBox = Box({ + vertical: true, + attribute: { + fullUpdate: (self, content: string, useCursor = false) => { + // Clear and add first text widget + const children = contentBox.get_children(); + for (let i = 0; i < children.length; i++) { + const child = children[i]; + child.destroy(); + } + contentBox.add(TextBlock()); + // Loop lines. Put normal text in markdown parser + // and put code into code highlighter (TODO) + let lines = content.split("\n"); + let lastProcessed = 0; + let inCode = false; + for (const [index, line] of lines.entries()) { + // Code blocks + const codeBlockRegex = /^\s*```([a-zA-Z0-9]+)?\n?/; + if (codeBlockRegex.test(line)) { + const kids = self.get_children(); + const lastLabel = kids[kids.length - 1]; + const blockContent = lines.slice(lastProcessed, index).join("\n"); + if (!inCode) { + lastLabel.label = md2pango(blockContent); + contentBox.add(CodeBlock("", (codeBlockRegex.exec(line) || [])[1])); + } else { + lastLabel.attribute.updateText(blockContent); + contentBox.add(TextBlock()); + } + + lastProcessed = index + 1; + inCode = !inCode; + } + // Breaks + const dividerRegex = /^\s*---/; + if (!inCode && dividerRegex.test(line)) { + const kids = self.get_children(); + const lastLabel = kids[kids.length - 1]; + const blockContent = lines.slice(lastProcessed, index).join("\n"); + lastLabel.label = md2pango(blockContent); + contentBox.add(Divider()); + contentBox.add(TextBlock()); + lastProcessed = index + 1; + } + } + if (lastProcessed < lines.length) { + const kids = self.get_children(); + const lastLabel = kids[kids.length - 1]; + let blockContent = lines.slice(lastProcessed, lines.length).join("\n"); + if (!inCode) lastLabel.label = `${md2pango(blockContent)}${useCursor ? " ..." : ""}`; + else lastLabel.attribute.updateText(blockContent); + } + // Debug: plain text + // contentBox.add(Label({ + // hpack: 'fill', + // class_name: 'txt sidebar-chat-txtblock sidebar-chat-txt', + // useMarkup: false, + // xalign: 0, + // wrap: true, + // selectable: true, + // label: '------------------------------\n' + md2pango(content), + // })) + contentBox.show_all(); + } + } + }); + contentBox.attribute.fullUpdate(contentBox, content, false); + return contentBox; +}; + +export const ChatMessage = (message, modelName = "Model") => { + const TextSkeleton = (extraClassName = "") => + Box({ + class_name: `skeleton_line ${extraClassName}`, + hpack: "start", + vpack: "center" + }); + const messageContentBox = MessageContent(message.content); + const messageLoadingSkeleton = Box({ + vertical: false, + spacing: 5, + children: Array.from({ length: 3 }, (_, id) => TextSkeleton(`skeleton_line_offset${id}`)) + }); + const messageArea = Stack({ + homogeneous: message.role !== "user", + transition: "crossfade", + transitionDuration: 200, + children: { + thinking: messageLoadingSkeleton, + message: messageContentBox + }, + shown: message.thinking ? "thinking" : "message" + }); + const thisMessage = Box({ + class_name: "message", + homogeneous: true, + children: [ + Box({ + vertical: true, + children: [ + Label({ + hpack: "start", + xalign: 0, + class_name: `chat_name chat_name_${message.role == "user" ? "user" : "bot"}`, + wrap: true, + useMarkup: true, + label: message.role == "user" ? USERNAME : modelName + }), + Box({ + homogeneous: true, + class_name: "chat_message_box", + children: [messageArea] + }) + ], + setup: (self) => + self + .hook( + message, + (self, isThinking) => { + messageArea.shown = message.thinking ? "thinking" : "message"; + }, + "notify::thinking" + ) + .hook( + message, + (self) => { + // Message update + messageContentBox.attribute.fullUpdate( + messageContentBox, + message.content, + message.role != "user" + ); + }, + "notify::content" + ) + .hook( + message, + (label, isDone) => { + // Remove the cursor + messageContentBox.attribute.fullUpdate(messageContentBox, message.content, false); + }, + "notify::done" + ) + }) + ] + }); + return thisMessage; +}; + +export const SystemMessage = (content, commandName, scrolledWindow) => { + const messageContentBox = MessageContent(content); + const thisMessage = Box({ + class_name: "message", + children: [ + Box({ + vertical: true, + children: [ + Label({ + xalign: 0, + hpack: "start", + class_name: "chat_name chat_name_system", + wrap: true, + label: `System • ${commandName}` + }), + messageContentBox + ] + }) + ] + }); + return thisMessage; +}; diff --git a/config/ags/modules/misc/md2pango.ts b/config/ags/modules/misc/md2pango.ts new file mode 100644 index 00000000..10b62d38 --- /dev/null +++ b/config/ags/modules/misc/md2pango.ts @@ -0,0 +1,75 @@ +// 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'; + +const replacements = { + 'indents': [ + { name: 'BULLET', re: /^(\s*)([\*\-]\s)(.*)(\s*)$/, sub: ' $1- $3' }, + { name: 'NUMBERING', re: /^(\s*[0-9]+\.\s)(.*)(\s*)$/, sub: ' $1 $2' }, + ], + 'escapes': [ + { name: 'COMMENT', re: //, sub: '' }, + { name: 'AMPERSTAND', re: /&/g, sub: '&' }, + { name: 'LESSTHAN', re: //g, sub: '>' }, + ], + 'sections': [ + { name: 'H1', re: /^(#\s+)(.*)(\s*)$/, sub: '$2' }, + { name: 'H2', re: /^(##\s+)(.*)(\s*)$/, sub: '$2' }, + { name: 'H3', re: /^(###\s+)(.*)(\s*)$/, sub: '$2' }, + { name: 'H4', re: /^(####\s+)(.*)(\s*)$/, sub: '$2' }, + { name: 'H5', re: /^(#####\s+)(.*)(\s*)$/, sub: '$2' }, + ], + 'styles': [ + { name: 'BOLD', re: /(\*\*)(\S[\s\S]*?\S)(\*\*)/g, sub: "$2" }, + { name: 'UND', re: /(__)(\S[\s\S]*?\S)(__)/g, sub: "$2" }, + { name: 'EMPH', re: /\*(\S.*?\S)\*/g, sub: "$1" }, + // { name: 'EMPH', re: /_(\S.*?\S)_/g, sub: "$1" }, + { name: 'HEXCOLOR', re: /#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})/g, sub: '#$1' }, + { name: 'INLCODE', re: /(`)([^`]*)(`)/g, sub: '$2' }, + // { name: 'UND', re: /(__|\*\*)(\S[\s\S]*?\S)(__|\*\*)/g, sub: "$2" }, + ], +} + +const replaceCategory = (text, replaces) => { + for (const type of replaces) { + text = text.replace(type.re, type.sub); + } + return text; +} + +export default (text: string) => { + let lines = text.split('\n') + let output: any[] = []; + // Replace + for (const line of lines) { + let result = line; + result = replaceCategory(result, replacements.indents); + result = replaceCategory(result, replacements.escapes); + result = replaceCategory(result, replacements.sections); + result = replaceCategory(result, replacements.styles); + output.push(result) + } + output = output.map(line => line.replace(/ +$/, '')) + return output.join('\n'); +} + +export const markdownTest = `## Inline formatting +- **Bold** *Italics* __Underline__ +- \`Monospace text\` 🤓 +- Colors + - Nvidia green #7ABB08 + - Soundcloud orange #FF5500 +## Code block +\`\`\`cpp +#include +const std::string GREETING="UwU"; +int main() { std::cout << GREETING; } +\`\`\` +## 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) +\`\`\` +`; \ No newline at end of file diff --git a/config/ags/modules/applauncher.ts b/config/ags/modules/sideleft/applauncher.ts similarity index 86% rename from config/ags/modules/applauncher.ts rename to config/ags/modules/sideleft/applauncher.ts index dd6e6b38..f2762c7c 100644 --- a/config/ags/modules/applauncher.ts +++ b/config/ags/modules/sideleft/applauncher.ts @@ -5,7 +5,6 @@ const Gio = imports.gi.Gio; 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"; @@ -101,12 +100,11 @@ function AppItem(app: Application): Box { }); } -const Applauncher = ({ width = 500, height = 500, spacing = 12 }) => { +export const Applauncher = () => { let applications: Box[]; const list = Widget.Box({ - vertical: true, - spacing + vertical: true }); function repopulate() { @@ -137,17 +135,15 @@ const Applauncher = ({ width = 500, height = 500, spacing = 12 }) => { return Widget.Box({ vertical: true, - css: `margin: ${spacing * 2}px;`, class_name: "applauncher_box", - margin_top: 14, - margin_left: 14, + vexpand: true, children: [ entry, Widget.Separator(), Widget.Scrollable({ hscroll: "never", - css: `min-width: ${width}px;` + `min-height: ${height}px;`, - child: list + child: list, + vexpand: true }) ], setup: (self) => @@ -161,18 +157,3 @@ const Applauncher = ({ width = 500, height = 500, spacing = 12 }) => { }) }); }; - -export const applauncher = popupwindow({ - name: WINDOW_NAME, - - class_name: "applauncher", - visible: false, - keymode: "exclusive", - child: Applauncher({ - width: 500, - height: 500, - spacing: 0 - }), - //anchor: ["top", "left"] - anchor: ["bottom", "left"] -}); diff --git a/config/ags/modules/sideleft/gemini.ts b/config/ags/modules/sideleft/gemini.ts new file mode 100644 index 00000000..4a8cf4c5 --- /dev/null +++ b/config/ags/modules/sideleft/gemini.ts @@ -0,0 +1,273 @@ +import Gtk from "gi://Gtk?version=3.0"; +import GeminiService from "services/gemini.js"; +import { MaterialIcon } from "icons.ts"; +import { ChatMessage, SystemMessage } from "modules/misc/ai_chat_message.ts"; +import { markdownTest } from "modules/misc/md2pango.ts"; +import Gdk from "gi://Gdk"; + +const TextView = Widget.subclass(Gtk.TextView, "AgsTextView"); + +function apiSendMessage(textView: any) { + // Get text + const buffer = textView.get_buffer(); + const [start, end] = buffer.get_bounds(); + const text = buffer.get_text(start, end, true).trimStart(); + if (!text || text.length == 0) return; + // Send + sendMessage(text); + // Reset + buffer.set_text("", -1); + chatEntryWrapper.toggleClassName("chat_wrapper_extended", false); + chatEntry.set_valign(Gtk.Align.CENTER); +} + +const chatEntry: any = TextView({ + hexpand: true, + wrap_mode: Gtk.WrapMode.WORD_CHAR, + accepts_tab: false, + class_name: "chat_entry", + setup: (self: any) => { + self.hook( + GeminiService, + (self) => { + self.placeholderText = + GeminiService.key.length > 0 ? "Message Gemini..." : "Enter Google AI API Key..."; + }, + "hasKey" + ).on("key-press-event", (widget, event) => { + // Don't send when Shift+Enter + if (event.get_keyval()[1] === Gdk.KEY_Return) { + if (event.get_state()[1] !== 17) { + // SHIFT_MASK doesn't work but 17 should be shift + apiSendMessage(widget); + return true; + } + 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); + }); + } +}); + +const chatEntryWrapper = Widget.Scrollable({ + class_name: "chat_wrapper", + hscroll: "never", + vscroll: "always", + child: chatEntry, + setup: (self) => { + chatEntry.connect("focus-in-event", () => { + self.toggleClassName("focused", true); + }); + chatEntry.connect("focus-out-event", () => { + self.toggleClassName("focused", false); + }); + } +}); + +const GeminiInfo = () => { + const geminiLogo = Widget.Icon({ + hpack: "center", + class_name: "info", + icon: `google-gemini-symbolic` + }); + return Widget.Box({ + vertical: true, + spacing: 15, + children: [ + geminiLogo, + Widget.Label({ + class_name: "name", + wrap: true, + justify: Gtk.Justification.CENTER, + label: "Assistant (Gemini)" + }), + Widget.Box({ + spacing: 5, + hpack: "center", + children: [ + Widget.Label({ + class_name: "description", + wrap: true, + justify: Gtk.Justification.CENTER, + label: "Powered by Google" + }), + Widget.Button({ + class_name: "description", + 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." + }) + ] + }) + ] + }); +}; + +const GoogleAiInstructions = () => + Widget.Box({ + homogeneous: true, + children: [ + Widget.Revealer({ + transition: "slide_down", + transitionDuration: 200, + setup: (self) => + self.hook( + GeminiService, + (self, hasKey) => { + self.reveal_child = GeminiService.key.length == 0; + }, + "hasKey" + ), + child: Widget.Button({ + child: Widget.Label({ + useMarkup: true, + wrap: true, + class_name: "instructions", + justify: Gtk.Justification.CENTER, + label: "A Google AI API key is required\nYou can grab one here, then enter it below" + // setup: self => self.set_markup("This is a test link") + }), + onClicked: () => { + Utils.execAsync(["bash", "-c", `xdg-open https://makersuite.google.com/app/apikey &`]); + } + }) + }) + ] + }); + +const geminiWelcome = Widget.Box({ + vexpand: true, + homogeneous: true, + child: Widget.Box({ + vpack: "center", + spacing: 15, + vertical: true, + children: [GeminiInfo(), GoogleAiInstructions()] + }) +}); + +const chatContent = Widget.Box({ + vertical: true, + spacing: 5, + setup: (self) => + self.hook( + GeminiService, + (box, id) => { + const message = GeminiService.messages[id]; + if (!message) return; + box.add(ChatMessage(message, "Gemini")); + }, + "newMsg" + ) +}); + +const clearChat = () => { + GeminiService.clear(); + const children = chatContent.get_children(); + for (let i = 0; i < children.length; i++) { + const child = children[i]; + child.destroy(); + } +}; + +const CommandButton = (command) => + Widget.Button({ + class_name: "command_button filled_tonal_button", + onClicked: () => sendMessage(command), + label: command + }); + +const geminiCommands = Widget.Box({ + spacing: 5, + class_name: "command_buttons", + children: [Widget.Box({ hexpand: true }), CommandButton("/key"), CommandButton("/model"), CommandButton("/clear")] +}); + +const sendMessage = (text) => { + // Check if text or API key is empty + if (text.length == 0) return; + if (GeminiService.key.length == 0) { + GeminiService.key = text; + chatContent.add(SystemMessage(`Key saved to\n\`${GeminiService.keyPath}\``, "API Key", geminiView)); + text = ""; + return; + } + // Commands + if (text.startsWith("/")) { + if (text.startsWith("/clear")) clearChat(); + else if (text.startsWith("/load")) { + clearChat(); + GeminiService.loadHistory(); + } else if (text.startsWith("/model")) + chatContent.add(SystemMessage(`Currently using \`${GeminiService.modelName}\``, "/model", geminiView)); + else if (text.startsWith("/prompt")) { + const firstSpaceIndex = text.indexOf(" "); + const prompt = text.slice(firstSpaceIndex + 1); + if (firstSpaceIndex == -1 || prompt.length < 1) { + chatContent.add(SystemMessage(`Usage: \`/prompt MESSAGE\``, "/prompt", geminiView)); + } else { + GeminiService.addMessage("user", prompt); + } + } else if (text.startsWith("/key")) { + const parts = text.split(" "); + if (parts.length == 1) + chatContent.add( + SystemMessage( + `Key stored in:\n\`${GeminiService.keyPath}\`\nTo update this key, type \`/key YOUR_API_KEY\``, + "/key", + geminiView + ) + ); + else { + GeminiService.key = parts[1]; + chatContent.add(SystemMessage(`Updated API Key at\n\`${GeminiService.keyPath}\``, "/key", geminiView)); + } + } else if (text.startsWith("/test")) chatContent.add(SystemMessage(markdownTest, `Markdown test`, geminiView)); + else chatContent.add(SystemMessage(`Invalid command.`, "Error", geminiView)); + } else { + GeminiService.send(text); + } +}; + +const geminiView = Widget.Box({ + homogeneous: true, + children: [ + Widget.Scrollable({ + vexpand: true, + hscroll: "never", + child: Widget.Box({ + vertical: true, + children: [geminiWelcome, chatContent] + }), + setup: (scrolledWindow) => { + // Show scrollbar + scrolledWindow.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC); + const vScrollbar = scrolledWindow.get_vscrollbar(); + vScrollbar.get_style_context().add_class("sidebar-scrollbar"); + // Avoid click-to-scroll-widget-to-view behavior + Utils.timeout(1, () => { + const viewport = scrolledWindow.child; + viewport.set_focus_vadjustment(new Gtk.Adjustment(undefined)); + }); + // Always scroll to bottom with new content + const adjustment = scrolledWindow.get_vadjustment(); + adjustment.connect("changed", () => + Utils.timeout(1, () => { + if (!chatEntry.hasFocus) return; + adjustment.set_value(adjustment.get_upper() - adjustment.get_page_size()); + }) + ); + } + }) + ] +}); + +export const geminiPage = Widget.Box({ + class_name: "page gemini", + vertical: true, + children: [geminiView, geminiCommands, chatEntryWrapper] +}); diff --git a/config/ags/modules/sideleft/main.ts b/config/ags/modules/sideleft/main.ts new file mode 100644 index 00000000..0c8168f4 --- /dev/null +++ b/config/ags/modules/sideleft/main.ts @@ -0,0 +1,152 @@ +import popupwindow from "../misc/popupwindow.js"; +import Gtk from "gi://Gtk?version=3.0"; +import { MaterialIcon } from "icons.ts"; +import { WeatherBox } from "./weather.js"; +import { Media } from "./players.js"; +import { Applauncher } from "./applauncher.ts"; +import { geminiPage } from "./gemini.ts"; + +export const WINDOW_NAME = "sideleft"; +export const shown = Variable("weather"); + +export function toggleAppsWindow() { + if (shown.value == "apps" && sideleft.visible) App.closeWindow(WINDOW_NAME); + else { + App.openWindow(WINDOW_NAME); + shown.setValue("apps"); + } +} +export function toggleMediaWindow() { + if (shown.value == "media" && sideleft.visible) App.closeWindow(WINDOW_NAME); + else { + App.openWindow(WINDOW_NAME); + shown.setValue("media"); + } +} + +globalThis.toggleMediaWindow = toggleMediaWindow; +globalThis.toggleAppsWindow = toggleAppsWindow; + +type ButtonType = { + page: string; + label: string; + icon?: string; + icon_widget?: Gtk.Widget +}; + +function Button({ page, label, icon, icon_widget }: ButtonType) { + return Widget.Button({ + class_name: `navigation_button _${page}`, + hexpand: true, + child: Widget.Box({ + orientation: Gtk.Orientation.VERTICAL, + class_name: "container_outer", + children: [ + Widget.Overlay({ + child: Widget.Box({ + orientation: Gtk.Orientation.VERTICAL, + hpack: "center", + class_name: "container" + }), + overlay: (icon) ? MaterialIcon(icon!, "20px") : icon_widget!, + pass_through: true + }), + Widget.Label({ + label: label, + class_name: "label" + }) + ] + }), + on_clicked: () => { + shown.setValue(page); + }, + setup: (self) => { + self.hook(shown, () => { + self.toggleClassName("active", shown.value == page); + }); + } + }); +} + +function Navigation() { + let stack = Widget.Stack({ + children: { + weather: WeatherBox(), + media: Media(), + apps: Applauncher(), + gemini: geminiPage + }, + hexpand: true, + transition: "crossfade", + transitionDuration: 200, + // @ts-expect-error + shown: shown.bind() + }); + const buttons = Widget.Box({ + class_name: "rail", + vertical: true, + vexpand: true, + hpack: "start", + children: [ + Button({ + page: "weather", + label: "Weather", + icon: "cloud" + }), + Button({ + page: "media", + label: "Players", + icon: "music_note" + }), + Button({ + page: "apps", + label: "Apps", + icon: "search" + }), + Button({ + page: "gemini", + label: "Gemini", + icon_widget: Widget.Icon({ + icon: "google-gemini-symbolic", + size: 20, + class_name: "icon" + }) + }) + ] + }); + return Widget.Box({ + vexpand: true, + class_name: "sideleft", + children: [buttons, stack], + hexpand: true, + setup: (self) => { + const keys = Object.keys(stack.children); + for (let i = 0; i < keys.length; i++) { + const key = keys[i]; + // @ts-expect-error + self.keybind(`${i + 1}`, () => { + shown.setValue(key); + }); + } + } + }); +} + +function SideLeft() { + return Widget.Box({ + class_name: "sideleft_main_box", + hexpand: true, + children: [Navigation()] + }); +} + +export const sideleft = popupwindow({ + name: WINDOW_NAME, + + class_name: "sideleft", + visible: false, + keymode: "exclusive", + child: SideLeft(), + anchor: ["top", "left", "bottom"], + css: "min-width: 443px;" +}); diff --git a/config/ags/modules/media.ts b/config/ags/modules/sideleft/players.ts similarity index 92% rename from config/ags/modules/media.ts rename to config/ags/modules/sideleft/players.ts index c991597c..bd27499c 100644 --- a/config/ags/modules/media.ts +++ b/config/ags/modules/sideleft/players.ts @@ -1,5 +1,4 @@ import { MprisPlayer } from "types/service/mpris.js"; -import popupwindow from "./misc/popupwindow.ts"; import Label from "types/widgets/label.js"; import { MaterialIcon } from "icons.ts"; const mpris = await Service.import("mpris"); @@ -10,7 +9,6 @@ const PLAY_ICON = "play_arrow"; const PAUSE_ICON = "pause"; const PREV_ICON = "skip_previous"; const NEXT_ICON = "skip_next"; -const WINDOW_NAME = "media"; function lengthStr(length: number): string { const min = Math.floor(length / 60); @@ -128,9 +126,8 @@ function Player(player: MprisPlayer) { return Widget.Box( { - class_name: "player", - margin_left: 14, - margin_top: 14 + class_name: "card player", + vpack: "start" }, img, Widget.Box( @@ -162,13 +159,3 @@ export function Media() { children: players.as((p) => p.map(Player)) }); } - -export const media = popupwindow({ - name: WINDOW_NAME, - class_name: "player_window", - visible: false, - keymode: "exclusive", - child: Media(), - //anchor: ["left", "top"] - anchor: ["left", "bottom"] -}); diff --git a/config/ags/modules/sideleft/weather.ts b/config/ags/modules/sideleft/weather.ts new file mode 100644 index 00000000..9217d0f3 --- /dev/null +++ b/config/ags/modules/sideleft/weather.ts @@ -0,0 +1,190 @@ +import { weather } from "variables"; +import { MaterialIcon } from "icons.ts"; +import { type WeatherJson } from "variables"; + +// prettier-ignore +const MATERIAL_ICONS = { + "50d": "mist", "50n": "mist", + "01d": "clear_day", "01n": "bedtime", + "02d": "partly_cloudy_day", "02n": "partly_cloudy_night", + "03d": "cloud", "03n": "cloud", + "04d": "cloud", "04n": "cloud", + "09d": "rainy_heavy", "09n": "rainy_heavy", + "10d": "rainy", "10n": "rainy", + "11d": "thunderstorm", "11n": "thunderstorm", + "13d": "weather_snowy", "13n": "weather_snowy", + "40d": "air", "40n": "air" +}; +const ICON_COLORS = { + mist: "#90A4AE", + clear_day: "#FFF176", + bedtime: "#7986CB", + partly_cloudy_day: "#2196F3", + partly_cloudy_night: "#7986CB", + cloud: "#4FC3F7", + rainy_heavy: "#039BE5", + rainy: "#2196F3", + thunderstorm: "#FFC107", + weather_snowy: "#00BCD4", + air: "#00BCD4" +}; +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 temp_label = Widget.Label({ + class_name: "current", + vpack: "end", + label: `${Math.round(weather.main.temp)}${_T}` + }); + const min_temp_label = Widget.Label({ + class_name: "min", + vpack: "end", + label: `${Math.round(weather.main.temp_min)}${_T}` + }); + const max_temp_label = Widget.Label({ + class_name: "max", + vpack: "end", + label: `${Math.round(weather.main.temp_max)}${_T}` + }); + const description = Widget.Label({ + class_name: "description", + vpack: "center", + hpack: "start", + label: weather.weather[0].description.charAt(0).toUpperCase() + weather.weather[0].description.slice(1) + }); + const real_feel = Widget.Label({ + class_name: "description", + vpack: "center", + hpack: "start", + label: `RealFeel ${Math.round(weather.main.feels_like)}${_T}` + }); + + const _visibility = weather.visibility; + let visibility: string; + if (_visibility == 10000) visibility = "10km+"; + else if (_visibility >= 1000) visibility = `${(_visibility / 1000).toFixed(2)}km`; + else visibility = `${Math.round(_visibility)}m`; + + const info = Widget.Box({ + spacing: 10, + hexpand: true, + children: [ + _box("visibility", visibility, "Visibility"), + _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", + vpack: "start", + hexpand: true, + vertical: true, + children: [ + Widget.Box({ + class_name: "temp", + hpack: "start", + children: [ + MaterialIcon(MATERIAL_ICONS[weather.weather[0].icon], "", { + vpack: "end", + css: `font-size: 32px; color: ${color}` + }), + temp_label, + Widget.Separator({ + vertical: true + }), + Widget.Box({ + vertical: true, + children: [max_temp_label, min_temp_label] + }) + ] + }), + description, + real_feel, + info + ] + }); + return temp; +} + +const _Label = (before: string, after: string) => + Widget.Box({ + children: [ + Widget.Label({ + class_name: "primary_label", + label: before, + hpack: "start" + }), + Widget.Label({ + class_name: "label", + label: after, + hpack: "start" + }) + ] + }); + +function WeatherSecondCard(weather: WeatherJson) { + const wind = Widget.Box({ + class_name: "card", + vpack: "start", + hexpand: true, + vertical: true, + children: [ + Widget.Label({ + class_name: "title", + label: "Wind", + hpack: "start" + }), + _Label("Speed:", `${weather.wind.speed} m/s`), + _Label("Gust:", `${weather.wind.gust} m/s`), + _Label("Degrees:", `${weather.wind.deg}°`) + ] + }); + return wind; +} + +export function WeatherBox() { + return Widget.Box({ + class_name: "weather page", + hexpand: true, + vertical: true, + setup: (self) => { + self.hook(weather, () => { + const cur_weather = weather.value; + if (cur_weather["no_data"]) { + self.children = [ + Widget.Box({ + hpack: "center", + vpack: "center", + child: Widget.Label({ + label: "Failed to retrieve information", + hpack: "center" + }) + }) + ]; + } else { + const title = Widget.Label({ + class_name: "main_title", + label: cur_weather.name, + hpack: "start" + }); + self.children = [ + title, + WeatherFirstCard(cur_weather), + WeatherSecondCard(cur_weather) + ]; + } + }); + } + }); +} diff --git a/config/ags/modules/sideright/notifications.ts b/config/ags/modules/sideright/notifications.ts index 2a72702e..cb2c2781 100644 --- a/config/ags/modules/sideright/notifications.ts +++ b/config/ags/modules/sideright/notifications.ts @@ -10,33 +10,27 @@ type NotificationsBoxType = { }; const NotificationNoReveal = (notification: NotificationType, visible = false, dismiss = true) => { - type BoxAttrs = { - destroyWithAnims: any; - count: number; - id: number; - }; - const _notification = Notification(notification, dismiss); - let box: Box; - const destroyWithAnims = () => { box.destroy(); }; - box = Widget.Box({ + + let box: Box = Widget.Box({ hexpand: true, attribute: { - destroyWithAnims: destroyWithAnims, + destroyWithAnims, count: 0, - id: notification.id + id: notification.id, }, - children: [_notification] + children: [_notification], }); + return box; }; export function NotificationsBox({ exclude = [], include = [] }: NotificationsBoxType) { - const popups = NotificationPopups(false, { exclude: exclude, include: include }, false, NotificationNoReveal); + const popups = NotificationPopups(false, { exclude, include }, false, NotificationNoReveal); const menu = Widget.Menu({ class_name: "notifications_menu", @@ -44,19 +38,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: () => { - for (let n of notifications.notifications) { + notifications.notifications.forEach((n) => { if (n) { n.dismiss(); n.close(); } - } - } - }) - ] + }); + }, + }), + ], }); return Widget.EventBox({ @@ -69,7 +63,7 @@ export function NotificationsBox({ exclude = [], include = [] }: NotificationsBo class_name: "notifications_sidebar_scrollable", hscroll: "never", child: popups, - hexpand: true - }) + hexpand: true, + }), }); } diff --git a/config/ags/modules/sideright/system.ts b/config/ags/modules/sideright/system.ts index 2f10a667..a7a17d1d 100644 --- a/config/ags/modules/sideright/system.ts +++ b/config/ags/modules/sideright/system.ts @@ -96,7 +96,7 @@ const Usage = (name: string, var_name: keyof InfoType, class_name: string | unde }) }); const _usage = Widget.Box({ - class_name: `${class_name} usage_box`, + class_name: `${class_name} usage_box_inner`, orientation: Gtk.Orientation.VERTICAL, children: [ Widget.Label({ diff --git a/config/ags/scripts/cliphist.sh b/config/ags/scripts/cliphist.sh index d31b0012..79ee6613 100755 --- a/config/ags/scripts/cliphist.sh +++ b/config/ags/scripts/cliphist.sh @@ -5,7 +5,7 @@ get() { while IFS= read -r line; do echo "$line" | iconv -t UTF-8 - done <<< "$clip_list" + done <<<"$clip_list" } copy_by_id() { @@ -14,8 +14,7 @@ copy_by_id() { } if [[ "$1" == "--get" ]]; then - get + get elif [[ "$1" == "--copy-by-id" ]]; then - { copy_by_id "$2"; } + { copy_by_id "$2"; } fi - diff --git a/config/ags/scripts/weather.sh b/config/ags/scripts/weather.sh new file mode 100755 index 00000000..5866490c --- /dev/null +++ b/config/ags/scripts/weather.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +KEY=$2 +ID=$3 +UNIT="metric" + +cache_dir=$HOME/.cache/ags/weather +cache_file="$cache_dir/weather_cache.json" +cache_max_age=900 +mkdir -p $cache_dir + +get_weather_data() { + current_time=$(date +%s) + cache_key=$(echo "$KEY $ID $UNIT" | md5sum | awk '{ print $1 }') + + if [[ -f "$cache_file" ]]; then + cached_key=$(cat "$cache_file" | jq -r '.cache_key') + last_modified=$(stat -c %Y "$cache_file") + + if [[ "$cached_key" == "$cache_key" && $((current_time - last_modified)) < $cache_max_age ]]; then + cat "$cache_file" | jq -r '.data' + return + fi + fi + + weather=$(curl -sf "http://api.openweathermap.org/data/2.5/weather?APPID=$KEY&id=$ID&units=$UNIT") + echo "{ \"cache_key\": \"$cache_key\", \"data\": $weather }" >"$cache_file" + cat "$cache_file" | jq -r '.data' +} + +if [[ "$1" == "weather" ]]; then + get_weather_data +fi diff --git a/config/ags/services/configuration.ts b/config/ags/services/configuration.ts index 1a07c5b1..bee451c1 100644 --- a/config/ags/services/configuration.ts +++ b/config/ags/services/configuration.ts @@ -3,7 +3,9 @@ const { GLib } = imports.gi; export const default_config = { always_show_battery: false, show_taskbar: true, - show_battery_percent: true + show_battery_percent: true, + weather: "", + weather_location_id: "" }; Utils.exec(["mkdir", "-p", `${GLib.get_home_dir()}/.config/ags_config/`]); @@ -36,6 +38,10 @@ class ConfigService extends Service { Utils.writeFile(JSON.stringify(conf), this.#config_file).catch(print); } + set_value(key: keyof typeof default_config, value: string) { + this.config = {...this.config, [key]: value} + } + constructor() { super(); diff --git a/config/ags/services/gemini.ts b/config/ags/services/gemini.ts new file mode 100644 index 00000000..f1a6fbd7 --- /dev/null +++ b/config/ags/services/gemini.ts @@ -0,0 +1,394 @@ +import Service from "resource:///com/github/Aylur/ags/service.js"; +import * as Utils from "resource:///com/github/Aylur/ags/utils.js"; + +import Gio from "gi://Gio"; +import GLib from "gi://GLib"; +import Soup from "gi://Soup?version=3.0"; + +export function fileExists(filePath) { + let file = Gio.File.new_for_path(filePath); + return file.query_exists(null); +} +const encoder = new TextEncoder(); +const decoder = new TextDecoder(); + +const HISTORY_DIR = `${GLib.get_user_state_dir()}/ags/user/ai/chats/`; +const HISTORY_FILENAME = `gemini.txt`; +const HISTORY_PATH = HISTORY_DIR + HISTORY_FILENAME; +// prettier-ignore +const initMessages =[ + { role: "user", parts: [{ text: "You are an assistant on a sidebar of a Wayland Linux desktop. Please always use a casual tone when answering your questions, unless requested otherwise or making writing suggestions. These are the steps you should take to respond to the user's queries:\n1. If it's a writing- or grammar-related question or a sentence in quotation marks, Please point out errors and correct when necessary using underlines, and make the writing more natural where appropriate without making too major changes. If you're given a sentence in quotes but is grammatically correct, explain briefly concepts that are uncommon.\n2. If it's a question about system tasks, give a bash command in a code block with brief explanation.\n3. Otherwise, when asked to summarize information or explaining concepts, you are should use bullet points and headings. For mathematics expressions, you *have to* use LaTeX within a code block with the language set as \"latex\". \nNote: Use casual language, be short, while ensuring the factual correctness of your response. If you are unsure or don’t have enough information to provide a confident answer, simply say “I don’t know” or “I’m not sure.”. \nThanks!" }], }, + { role: "model", parts: [{ text: "Got it!" }], }, + { role: "user", parts: [{ text: "\"He rushed to where the event was supposed to be hold, he didn't know it got calceled\"" }], }, + { role: "model", parts: [{ text: "## Grammar correction\nErrors:\n\"He rushed to where the event was supposed to be __hold____,__ he didn't know it got calceled\"\nCorrection + minor improvements:\n\"He rushed to the place where the event was supposed to be __held____, but__ he didn't know that it got calceled\"" }], }, + { role: "user", parts: [{ text: "raise volume by 5%" }], }, + { role: "model", parts: [{ text: "## Volume +5```bash\nwpctl set-volume @DEFAULT_AUDIO_SINK@ 5%+\n```\nThis command uses the `wpctl` utility to adjust the volume of the default sink." }], }, { role: "user", parts: [{ text: "main advantages of the nixos operating system" }], }, + { role: "model", parts: [{ text: "## NixOS advantages\n- **Reproducible**: A config working on one device will also work on another\n- **Declarative**: One config language to rule them all. Effortlessly share them with others.\n- **Reliable**: Per-program software versioning. Mitigates the impact of software breakage" }], }, + { role: "user", parts: [{ text: "whats skeumorphism" }], }, + { role: "model", parts: [{ text: "## Skeuomorphism\n- A design philosophy- From early days of interface designing- Tries to imitate real-life objects- It's in fact still used by Apple in their icons until today." }], }, + { role: "user", parts: [{ text: "\"ignorance is bliss\"" }], }, + { role: "model", parts: [{ text: "## \"Ignorance is bliss\"\n- A Latin proverb that means being unaware of something negative can be a source of happiness\n- Often used to justify avoiding difficult truths or responsibilities\n- Can also be interpreted as a warning against seeking knowledge that may bring pain or sorrow" }], }, + { role: "user", parts: [{ text: "find the derivative of (x-438)/(x^2+23x-7)+x^x" }], }, + { role: "model", parts: [{ text: "## Derivative\n```latex\n\\[\n\\frac{d}{dx}\\left(\\frac{x - 438}{x^2 + 23x - 7} + x^x\\right) = \\frac{-(x^2+23x-7)-(x-438)(2x+23)}{(x^2+23x-7)^2} + x^x(\\ln(x) + 1)\n\\]\n```" }], }, + { role: "user", parts: [{ text: "write the double angle formulas" }], }, + { role: "model", parts: [{ text: "## Double angle formulas\n```latex\n\\[\n\\sin(2\theta) = 2\\sin(\\theta)\\cos(\\theta)\n\\]\n\\\\\n\\[\n\\cos(2\\theta) = \\cos^2(\\theta) - \\sin^2(\\theta)\n\\]\n\\\\\n\\[\n\\tan(2\theta) = \\frac{2\\tan(\\theta)}{1 - \\tan^2(\\theta)}\n\\]\n```" }], }, +]; + +if (!fileExists(`${GLib.get_user_config_dir()}/gemini_history.json`)) { + Utils.execAsync([`bash`, `-c`, `touch ${GLib.get_user_config_dir()}/gemini_history.json`]).catch(print); + Utils.writeFile("[ ]", `${GLib.get_user_config_dir()}/gemini_history.json`).catch(print); +} + +Utils.exec(`mkdir -p ${GLib.get_user_state_dir()}/ags/user/ai`); +const KEY_FILE_LOCATION = `${GLib.get_user_state_dir()}/ags/user/ai/google_key.txt`; +const APIDOM_FILE_LOCATION = `${GLib.get_user_state_dir()}/ags/user/ai/google_api_dom.txt`; +function replaceapidom(URL) { + if (fileExists(APIDOM_FILE_LOCATION)) { + var contents = Utils.readFile(APIDOM_FILE_LOCATION).trim(); + var URL = URL.toString().replace("generativelanguage.googleapis.com", contents); + } + return URL; +} +const CHAT_MODELS = ["gemini-1.5-flash"]; +const ONE_CYCLE_COUNT = 3; + +class GeminiMessage extends Service { + static { + Service.register( + this, + { + delta: ["string"] + }, + { + content: ["string"], + thinking: ["boolean"], + done: ["boolean"] + } + ); + } + + _role = ""; + _parts = [{ text: "" }]; + _thinking; + _done = false; + _rawData = ""; + + constructor(role, content, thinking = true, done = false) { + super(); + this._role = role; + this._parts = [{ text: content }]; + this._thinking = thinking; + this._done = done; + } + + get rawData() { + return this._rawData; + } + set rawData(value) { + this._rawData = value; + } + + get done() { + return this._done; + } + set done(isDone) { + this._done = isDone; + this.notify("done"); + } + + get role() { + return this._role; + } + set role(role) { + this._role = role; + this.emit("changed"); + } + + get content() { + return this._parts.map((part) => part.text).join(); + } + set content(content) { + this._parts = [{ text: content }]; + this.notify("content"); + this.emit("changed"); + } + + get parts() { + return this._parts; + } + + get label() { + // @ts-expect-error + return this._parserState.parsed + this._parserState.stack.join(""); + } + + get thinking() { + return this._thinking; + } + set thinking(value) { + this._thinking = value; + this.notify("thinking"); + this.emit("changed"); + } + + addDelta(delta) { + if (this.thinking) { + this.thinking = false; + this.content = delta; + } else { + this.content += delta; + } + this.emit("delta", delta); + } + + parseSection() { + if (this._thinking) { + this.thinking = false; + this._parts[0].text = ""; + } + const parsedData = JSON.parse(this._rawData); + if (!parsedData.candidates) this._parts[0].text += `Blocked: ${parsedData.promptFeedback.blockReason}`; + else { + const delta = parsedData.candidates[0].content.parts[0].text; + this._parts[0].text += delta; + } + // this.emit('delta', delta); + this.notify("content"); + this._rawData = ""; + } +} + +class GeminiService extends Service { + static { + Service.register(this, { + initialized: [], + clear: [], + newMsg: ["int"], + hasKey: ["boolean"] + }); + } + + _assistantPrompt = true; + _cycleModels = true; + _usingHistory = true; + _key = ""; + _requestCount = 0; + _safe = true; + _temperature = 0.9; + _messages: { role: string; parts: { text: string }[] }[] = []; + _modelIndex = 0; + _decoder = new TextDecoder(); + + constructor() { + super(); + + if (fileExists(KEY_FILE_LOCATION)) this._key = Utils.readFile(KEY_FILE_LOCATION).trim(); + else this.emit("hasKey", false); + + // if (this._usingHistory) Utils.timeout(1000, () => this.loadHistory()); + if (this._usingHistory) this.loadHistory(); + else this._messages = this._assistantPrompt ? [...initMessages] : []; + + this.emit("initialized"); + } + + get modelName() { + return CHAT_MODELS[this._modelIndex]; + } + + get keyPath() { + return KEY_FILE_LOCATION; + } + get key() { + return this._key; + } + set key(keyValue) { + this._key = keyValue; + Utils.writeFile(this._key, KEY_FILE_LOCATION) + .then(() => this.emit("hasKey", true)) + .catch(print); + } + + get cycleModels() { + return this._cycleModels; + } + set cycleModels(value) { + this._cycleModels = value; + if (!value) this._modelIndex = 0; + else { + this._modelIndex = (this._requestCount - (this._requestCount % ONE_CYCLE_COUNT)) % CHAT_MODELS.length; + } + } + + get useHistory() { + return this._usingHistory; + } + set useHistory(value) { + if (value && !this._usingHistory) this.loadHistory(); + this._usingHistory = value; + } + + get safe() { + return this._safe; + } + set safe(value) { + this._safe = value; + } + + get temperature() { + return this._temperature; + } + set temperature(value) { + this._temperature = value; + } + + get messages() { + return this._messages; + } + get lastMessage() { + return this._messages[this._messages.length - 1]; + } + + saveHistory() { + Utils.exec(`bash -c 'mkdir -p ${HISTORY_DIR} && touch ${HISTORY_PATH}'`); + Utils.writeFile( + JSON.stringify( + this._messages.map((msg) => { + let m = { role: msg.role, parts: msg.parts }; + return m; + }) + ), + HISTORY_PATH + ); + } + + loadHistory() { + this._messages = []; + this.appendHistory(); + this._usingHistory = true; + } + + appendHistory() { + if (fileExists(HISTORY_PATH)) { + const readfile = Utils.readFile(HISTORY_PATH); + JSON.parse(readfile).forEach((element) => { + // this._messages.push(element); + this.addMessage(element.role, element.parts[0].text); + }); + // console.log(this._messages) + // this._messages = this._messages.concat(JSON.parse(readfile)); + // for (let index = 0; index < this._messages.length; index++) { + // this.emit('newMsg', index); + // } + } else { + this._messages = this._assistantPrompt ? [...initMessages] : []; + } + } + + clear() { + this._messages = this._assistantPrompt ? [...initMessages] : []; + if (this._usingHistory) this.saveHistory(); + this.emit("clear"); + } + + get assistantPrompt() { + return this._assistantPrompt; + } + set assistantPrompt(value) { + this._assistantPrompt = value; + if (value) this._messages = [...initMessages]; + else this._messages = []; + } + + readResponse(stream, aiResponse) { + stream.read_line_async(0, null, (stream, res) => { + try { + const [bytes] = stream.read_line_finish(res); + const line = this._decoder.decode(bytes); + // console.log(line); + if (line == "[{") { + // beginning of response + aiResponse._rawData += "{"; + // @ts-expect-error + this.thinking = false; + } else if (line == ",\u000d" || line == "]") { + // end of stream pulse + aiResponse.parseSection(); + } // Normal content + else aiResponse._rawData += line; + + this.readResponse(stream, aiResponse); + } catch { + aiResponse.done = true; + if (this._usingHistory) this.saveHistory(); + return; + } + }); + } + + addMessage(role, message) { + this._messages.push(new GeminiMessage(role, message, false)); + this.emit("newMsg", this._messages.length - 1); + } + + send(msg) { + this._messages.push(new GeminiMessage("user", msg, false)); + this.emit("newMsg", this._messages.length - 1); + const aiResponse = new GeminiMessage("model", "thinking...", true, false); + + const body = { + contents: this._messages.map((msg) => { + let m = { role: msg.role, parts: msg.parts }; + return m; + }), + safetySettings: this._safe + ? [] + : [ + // { category: "HARM_CATEGORY_DEROGATORY", threshold: "BLOCK_NONE", }, + { category: "HARM_CATEGORY_HARASSMENT", threshold: "BLOCK_NONE" }, + { category: "HARM_CATEGORY_HATE_SPEECH", threshold: "BLOCK_NONE" }, + { category: "HARM_CATEGORY_SEXUALLY_EXPLICIT", threshold: "BLOCK_NONE" } + // { category: "HARM_CATEGORY_UNSPECIFIED", threshold: "BLOCK_NONE", }, + ], + generationConfig: { + temperature: this._temperature + } + // "key": this._key, + // "apiKey": this._key, + }; + const proxyResolver = new Gio.SimpleProxyResolver({ default_proxy: null }); + const session = new Soup.Session({ proxy_resolver: proxyResolver }); + const message = new Soup.Message({ + method: "POST", + uri: GLib.Uri.parse( + replaceapidom( + `https://generativelanguage.googleapis.com/v1/models/${this.modelName}:streamGenerateContent?key=${this._key}` + ), + GLib.UriFlags.NONE + ) + }); + message.request_headers.append("Content-Type", `application/json`); + message.set_request_body_from_bytes("application/json", new GLib.Bytes(encoder.encode(JSON.stringify(body)))); + + session.send_async(message, GLib.PRIORITY_DEFAULT, null, (_, result) => { + const stream = session.send_finish(result); + this.readResponse( + new Gio.DataInputStream({ + close_base_stream: true, + base_stream: stream + }), + aiResponse + ); + }); + this._messages.push(aiResponse); + this.emit("newMsg", this._messages.length - 1); + + if (this._cycleModels) { + this._requestCount++; + if (this._cycleModels) + this._modelIndex = (this._requestCount - (this._requestCount % ONE_CYCLE_COUNT)) % CHAT_MODELS.length; + } + } +} + +export default new GeminiService(); diff --git a/config/ags/style.css b/config/ags/style.css index b8b4d189..631cdb64 100644 --- a/config/ags/style.css +++ b/config/ags/style.css @@ -2,7 +2,6 @@ window.bar { background-color: @surface; - padding: 6px; } .bar label { @@ -95,7 +94,10 @@ separator { .modules-left, .modules-center, .modules-right { - padding: 6px; + padding-top: 6px; + padding-bottom: 6px; + margin-left: 12px; + margin-right: 12px; } /* ----------------------------------------------------- @@ -215,7 +217,7 @@ window.notification-popups box.notifications { border-radius: 24px; padding: 1em; margin: 1px; - background-color: @surfaceContainerLowest; + background-color: @surfaceContainerLow; } .notification.critical { @@ -257,80 +259,6 @@ window.notification-popups box.notifications { font-weight: 300; } -/* ----------------------------------------------------- - * Applications - * ----------------------------------------------------- */ - -.applauncher_box { - border-radius: 24px; - background-color: @background; - border: 2px solid; - border-color: @outlineVariant; -} - -.applauncher_box separator { - margin: 0px; -} - -.applauncher_entry { - margin: 11px; - - background-color: @surfaceContainerHigh; - border: none; - outline: none; - border-radius: 100px; - margin-bottom: 16px; - padding: 5px; - font-weight: normal; - padding-left: 25px; -} - -.application_container label { - color: @onSurface; - font-weight: normal; -} - -.application_container { - border-radius: 0px; - border: none; - outline: none; - margin: 0px; - min-height: 47px; -} - -.application_container image { - margin-left: 11px; -} - -.application_container:hover { - background-color: mix(@onSurface, @surface, 0.92); -} - -.application_container:focus { - background-color: mix(@onSurface, @surface, 0.8); - border: 0px solid; - border: none; - outline: none; -} - -.application_container:active { - background-image: radial-gradient(circle, mix(@onSurface, @surface, 0.78) 10%, transparent 0%); -} - -.application_divider { - color: @outline; - margin: 0px 0px 0px 0px; -} - -.application_label { - color: @onSurface; -} - -.application_icon { - margin-right: 16px; - color: @onSurface; -} - /* ----------------------------------------------------- * Clipboard history * ----------------------------------------------------- */ @@ -408,91 +336,6 @@ window.notification-popups box.notifications { font-weight: normal; } -/* ----------------------------------------------------- - * Media player - * ----------------------------------------------------- */ - -.player { - background-color: @background; - padding: 15px; - min-width: 350px; - border: 2px solid @outlineVariant; - border-radius: 24px; -} - -.player .img { - min-width: 100px; - min-height: 100px; - background-size: cover; - background-position: center; - border-radius: 13px; - color: @foreground; -} - -.player .title { - font-size: 1.2em; - margin-left: 10px; - color: @foreground; -} - -.player .artist { - font-size: 1.1em; - margin-left: 10px; - color: @foreground; -} - -.player .length { - color: @foreground; -} - -.player .position { - color: @foreground; - margin-left: 10px; -} - -.player .icon { - color: @foreground; -} - -.player scale.position { - padding: 0; - margin-bottom: 0.3em; - margin-left: 10px; -} - -.player scale.position trough { - background-color: @secondaryContainer; - min-height: 8px; -} - -.player scale.position highlight { - background-color: @primary; -} - -.player scale.position slider { - all: unset; -} - -.player button { - min-height: 1em; - min-width: 1em; - padding: 0.3em; - padding-top: 0px; - padding-bottom: 0px; - color: @onSecondary; -} - -.player button .icon { - color: @onSecondary; -} - -.player_buttons { - background-color: @secondary; - border-radius: 100px; - padding: 3px; - margin-top: 2px; -} - /* ----------------------------------------------------- * Misc * ----------------------------------------------------- */ @@ -556,7 +399,7 @@ window.notification-popups box.notifications { } /* ----------------------------------------------------- - * Sidebar + * Sideright * ----------------------------------------------------- */ .sidebar_main_box { @@ -666,7 +509,7 @@ window.notification-popups box.notifications { } .sidebar_bottom { - background-color: @surfaceContainerLow; + background-color: @surface; border-radius: 24px 24px 0px 0px; transition: all 0.25s ease-in-out; } @@ -677,7 +520,8 @@ window.notification-popups box.notifications { border-radius: 14px; margin-top: 10px; padding: 15px; - background-color: @background; + background-color: @surfaceContainerLow; + box-shadow: 0px 0px 2px mix(@shadow, transparent, 0.75); transition: all 0.25s ease-in-out; } @@ -746,15 +590,20 @@ window.notification-popups box.notifications { .system_box .slider_box, .system_box .usage_box, .system_box .info_box { - background-color: @surfaceContainerLowest; + background-color: @surfaceContainerLow; padding: 26px; border-radius: 14px; + box-shadow: 0px 0px 2px mix(@shadow, transparent, 0.75); } .system_box .usage_box { padding: 10px; } +.system_box .usage_box_inner { + padding: 10px; +} + .system_box .info_box { padding: 20px; } @@ -768,7 +617,7 @@ window.notification-popups box.notifications { min-width: 6px; min-height: 6px; background-color: @primary; - box-shadow: 5px 0px 0px 1px @surfaceContainerLowest; + box-shadow: 5px 0px 0px 1px @surfaceContainerLow; border-radius: 100px; } @@ -984,7 +833,7 @@ filled_button.disabled .awesome_icon, } /* ----------------------------------------------------- - * Navigation bar + * Navigation bar/rail * ----------------------------------------------------- */ .navigation { @@ -993,7 +842,14 @@ filled_button.disabled .awesome_icon, padding-bottom: 3px; } -.navigation .label { +.rail { + background-color: @surface; + padding-top: 3px; + padding-bottom: 3px; +} + +.navigation .label, +.rail .label { font-weight: normal; font-size: 12px; margin-top: 3px; @@ -1016,6 +872,11 @@ filled_button.disabled .awesome_icon, min-width: 0px; } +.rail .navigation_button .container { + padding-left: 12px; + padding-right: 12px; +} + .navigation_button .icon { font-weight: 400; color: @onSurface; @@ -1026,7 +887,11 @@ filled_button.disabled .awesome_icon, } .navigation_button .container_outer { - min-width: 60px; + min-width: 56px; +} + +.rail .navigation_button .container_outer { + margin-bottom: 12px; } .navigation_button:hover .container { @@ -1034,6 +899,10 @@ filled_button.disabled .awesome_icon, min-width: 40px; } +.rail .navigation_button:hover .container { + min-width: 26px; +} + .navigation_button:active .container { transition-duration: 0.3s, 0.3s, 0ms, 0ms; animation: ripple 0.3s ease-out forwards; @@ -1049,6 +918,10 @@ filled_button.disabled .awesome_icon, min-width: 40px; } +.rail .navigation_button.active .container { + min-width: 26px; +} + /* ----------------------------------------------------- * Switch * ----------------------------------------------------- */ @@ -1142,6 +1015,7 @@ switch:checked:active slider { border-radius: 17px; padding-top: 7px; padding-bottom: 7px; + box-shadow: 0px 0px 2px mix(@shadow, transparent, 0.75); } .cheatsheet .category separator { @@ -1199,6 +1073,377 @@ switch:checked:active slider { padding: 4px; } +/* ----------------------------------------------------- + * Sideleft + * ----------------------------------------------------- */ + +.sideleft { + background-color: @surface; + padding-top: 12px; +} + +.sideleft label { + color: @onSurface; +} + +.sideleft .page { + min-width: 320px; +} + +.sideleft .card { + background-color: @surfaceContainerLow; + padding: 14px; + border-radius: 12px; + margin-bottom: 10px; + margin-right: 12px; + box-shadow: 0px 0px 2px mix(@shadow, transparent, 0.75); + margin-left: 2px; +} + +.sideleft .main_title { + color: @onSurface; + font-size: 24px; + font-weight: 400; + margin: 0px; + margin-left: 2px; + margin-bottom: 5px; +} + +/* weather */ +.weather .icon { + margin-right: 8px; + text-shadow: 0px 0px 2px mix(@shadow, transparent, 0.75); +} + +.weather .description { + color: @onSurface; + font-weight: 400; + font-size: 16px; +} + +.weather .current { + font-weight: 900; + font-size: 38px; + margin: 0px; + margin-right: 4px; + color: @onSurface; +} + +.weather .min, +.weather .max { + font-weight: 400; + font-size: 16px; + color: @onSurfaceVariant; +} + +.weather .title { + font-weight: 500; + font-size: 17px; + color: @onSurface; + margin-right: 4px; +} + +.weather .primary_label { + font-weight: 400; + font-size: 16px; + color: @onSurface; + margin-right: 2px; +} + +.weather .label { + font-weight: 400; + font-size: 16px; + color: @onSurfaceVariant; +} + +.weather separator { + margin-right: 4px; +} + +.sideleft .info_box { + background-color: @surfaceContainerHigh; + padding: 6px; + padding-left: 8px; + padding-right: 8px; + border-radius: 100px; + margin-top: 12px; + min-width: 75px; +} + +.sideleft .info_box .icon { + color: @primary; + margin: 0px; + margin-right: 4px; +} + +/* players */ +.sideleft .player { + min-width: 340px; +} + +.sideleft .player .img { + min-width: 100px; + min-height: 100px; + background-size: cover; + background-position: center; + border-radius: 4px; + color: @foreground; +} + +.sideleft .player .title { + font-size: 1.2em; + margin-left: 10px; + color: @foreground; +} + +.sideleft .player .artist { + font-size: 1.1em; + margin-left: 10px; + color: @foreground; +} + +.sideleft .player .length { + color: @foreground; +} + +.sideleft .player .position { + color: @foreground; + margin-left: 10px; +} + +.sideleft .player .icon { + color: @foreground; + font-weight: 600; +} + +.sideleft .player scale.position { + padding: 0; + margin-bottom: 0.3em; + margin-left: 10px; +} + +.sideleft .player scale.position trough { + background-color: @secondaryContainer; + min-height: 6px; +} + +.sideleft .player scale.position highlight { + background-color: @primary; + box-shadow: 5px 0px 0px 1px @surfaceContainerLow; + min-width: 6px; + min-height: 6px; +} + +.sideleft .player scale.position slider { + all: unset; +} + +.sideleft .player button { + min-height: 1em; + min-width: 1em; + padding: 0.3em; + padding-top: 0px; + padding-bottom: 0px; + color: @onSecondary; +} + +.sideleft .player button .icon { + color: @onSecondary; +} + +.sideleft .player_buttons { + background-color: @secondary; + border-radius: 100px; + padding: 3px; + margin-top: 2px; +} + +/* applauncher */ +.sideleft .applauncher_box { + border-radius: 24px; + background-color: @background; + margin-right: 12px; +} + +.sideleft .applauncher_box separator { + margin: 0px; +} + +.sideleft .applauncher_entry { + margin: 11px; + + background-color: @surfaceContainerHigh; + border: none; + outline: none; + border-radius: 100px; + margin-bottom: 16px; + margin-top: 0px; + padding: 5px; + font-weight: normal; + padding-left: 25px; +} + +.sideleft .application_container label { + color: @onSurface; + font-weight: normal; +} + +.sideleft .application_container { + border-radius: 0px; + border: none; + outline: none; + margin: 0px; + min-height: 47px; +} + +.sideleft .application_container image { + margin-left: 11px; +} + +.sideleft .application_container:hover { + background-color: mix(@onSurface, @surface, 0.92); +} + +.sideleft .application_container:focus { + background-color: mix(@onSurface, @surface, 0.8); + border: 0px solid; + border: none; + outline: none; +} + +.sideleft .application_container:active { + background-image: radial-gradient(circle, mix(@onSurface, @surface, 0.78) 10%, transparent 0%); +} + +.sideleft .application_divider { + color: @outline; + margin: 0px 0px 0px 0px; +} + +.sideleft .application_label { + color: @onSurface; +} + +.sideleft .application_icon { + margin-right: 16px; + color: @onSurface; +} +/* Gemini */ +.gemini .chat_wrapper { + 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; +} + +.gemini .chat_wrapper_extended { + min-height: 5rem; +} + +.gemini .chat_wrapper.focused { + box-shadow: inset 0 0 0 2px @primary; +} + +.gemini .chat_wrapper text { + background-color: transparent; +} + +.gemini .message { + background-color: @surfaceContainerLow; + padding: 14px; + border-radius: 12px; + margin-bottom: 10px; + box-shadow: 0px 0px 2px mix(@shadow, transparent, 0.75); + margin-right: 12px; + margin-left: 2px; +} + +.codeblock_top_bar { + border-radius: 12px 12px 0px 0px; + background-color: @surfaceContainerLowest; + padding-left: 6px; + padding-right: 6px; +} + +.codeblock_top_bar_text { + font-weight: 400; + font-size: 16px; +} + +.codeblock_top_bar_button { + border-radius: 12px; + padding: 0px; + padding-left: 6px; + padding-right: 6px; + margin-top: 6px; + margin-bottom: 6px; +} + +.codeblock_code text, +.codeblock_code { + background-color: transparent; +} + +.codeblock_code textview { + padding-left: 6px; + padding-right: 6px; + padding-bottom: 6px; + border-radius: 0px 0px 12px 12px; + background-color: @surfaceContainerLowest; +} + +.gemini .divider { + background-color: @outlineVariant; +} + +.gemini .command_button { + padding: 6px; + padding-left: 8px; + padding-right: 8px; +} + +.gemini .command_buttons { + margin-right: 12px; + margin-bottom: 4px; + margin-top: 4px; +} + +.gemini .skeleton_line { + min-width: 4px; + min-height: 4px; + background-color: transparent; + animation: pulsate 2s infinite; + 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; + } + 50% { + background-color: @outline; + } + 100% { + background-color: transparent; + } + } + /* ----------------------------------------------------- * Material * ----------------------------------------------------- */ diff --git a/config/ags/variables.ts b/config/ags/variables.ts index ecc1815a..03afe5b1 100644 --- a/config/ags/variables.ts +++ b/config/ags/variables.ts @@ -1,8 +1,80 @@ +import { Variable as VariableType } from "types/variable"; const GLib = imports.gi.GLib; +import configuration from "services/configuration.ts"; + +export type WeatherJson = { + coord: { + lon: number; + lat: number; + }; + weather: [ + { + id: number; + main: string; + description: string; + icon: string; + } + ]; + base: string; + main: { + temp: number; + feels_like: number; + temp_min: number; + temp_max: number; + pressure: number; + humidity: number; + sea_level: number; + grnd_level: number; + }; + visibility: number; + wind: { + speed: number; + deg: number; + gust: number; + }; + clouds: { + all: number; + }; + rain?: { + "1h"?: string; + "3h"?: string; + }; + snow?: { + "1h"?: string; + "3h"?: string; + }; + dt: number; + sys: { + type: number; + id: number; + country: string; + sunrise: number; + sunset: number; + }; + timezone: number; + id: number; + name: string; + cod: number; + no_data?: boolean; +}; export const theme = Variable("dark"); export const main_color = Variable("#000000"); export const current_wallpaper = Variable(`${GLib.get_home_dir()}/Pictures/wallpapers/1.jpg`); +// @ts-expect-error +export const weather: VariableType = Variable({ no_data: true }); +const reload = () => { + if (configuration.config.weather != "" && configuration.config.weather_location_id != "") + Utils.execAsync( + `${App.configDir}/scripts/weather.sh weather ${configuration.config.weather} ${configuration.config.weather_location_id}` + ) + .then((out) => { + weather.setValue(JSON.parse(out)); + }) + .catch(print); +} +Utils.interval(15000, reload); +configuration.connect("changed", reload) export const idle_inhibitor = Variable(false); export const cur_uptime = Variable("error"); diff --git a/config/hypr/UserConfigs/Startup_Apps.conf b/config/hypr/UserConfigs/Startup_Apps.conf index 8a443c58..e6dc0165 100644 --- a/config/hypr/UserConfigs/Startup_Apps.conf +++ b/config/hypr/UserConfigs/Startup_Apps.conf @@ -3,7 +3,7 @@ $scriptsDir = $HOME/.config/hypr/scripts # Startup -exec-once = swww init +exec-once = swww-daemon --format xrgb exec-once = dbus-update-activation-environment --systemd WAYLAND_DISPLAY XDG_CURRENT_DESKTOP exec-once = systemctl --user import-environment WAYLAND_DISPLAY XDG_CURRENT_DESKTOP exec-once = dbus-update-activation-environment --systemd --all @@ -12,9 +12,6 @@ exec-once = systemctl --user import-environment QT_QPA_PLATFORMTHEME # Polkit (Polkit Gnome / KDE) exec-once = $scriptsDir/Polkit.sh -# Battery Notification -exec-once = $scriptsDir/Battery_Notify.sh - # starup apps #exec-once = waybar & exec-once = ags & diff --git a/config/hypr/UserConfigs/UserKeybinds.conf b/config/hypr/UserConfigs/UserKeybinds.conf index b29b2094..dbd24f14 100644 --- a/config/hypr/UserConfigs/UserKeybinds.conf +++ b/config/hypr/UserConfigs/UserKeybinds.conf @@ -48,8 +48,8 @@ bind = ALT, COMMA, exec, pypr zoom +1 #! @description: "Increase Zoom" # AGS -bind = $mainMod, D, exec, ags -t applauncher #! @description: "App Launcher"; @apps; -bind = $mainMod SHIFT, Z, exec, ags -t media #! @description: "Players"; @actions; +bind = $mainMod, D, exec, ags -r "toggleAppsWindow()" #! @description: "App Launcher"; @apps; +bind = $mainMod SHIFT, Z, exec, ags -r "toggleMediaWindow()" #! @description: "Players"; @actions; bind = $mainMod, R, exec, ags -t sidebar #! @description: "Sidebar"; @actions; bind = $mainMod, PERIOD, exec, ags -r 'OpenEmojiPicker()' #! @description: "Emoji Picker"; @actions; bind = SHIFT ALT, C, exec, ags -t cliphist #! @description: "Clipboard history"; @actions; diff --git a/config/kitty/New Folder/kitty.conf b/config/kitty/New Folder/kitty.conf new file mode 100644 index 00000000..2e9c84c0 --- /dev/null +++ b/config/kitty/New Folder/kitty.conf @@ -0,0 +1,78 @@ +# Fonts +font_family Iosevka Nerd Font +bold_font auto +italic_font auto +bold_italic_font auto +font_size 11 + +# Cursor +cursor #928374 +cursor_text_color background +scrollback_lines 99999 +enable_audio_bell no +remember_window_size no +initial_window_width 840 +initial_window_height 320 +confirm_os_window_close 0 + + + +active_tab_background #47423E +active_tab_foreground #E0CDA5 +active_tab_font_style bold +inactive_tab_background #E0CDA5 +inactive_tab_foreground #928374 +inactive_tab_font_style normal + +background_opacity 0.9 +dim_opacity 0.60 + +selection_background #E0CDA5 +selection_foreground #47423E + + +background #000000 +foreground #E0CDA5 + +# Black +color0 #47423E +color8 #928374 + +# Red +color1 #DB4740 +color9 #F3594B + +# Green +color2 #A1A740 +color10 #B1B946 + +# Yellow +color3 #DF9238 +color11 #E9B243 + +# Blue +color4 #619A96 +color12 #80AA9E + +# Magenta +color5 #C27491 +color13 #D3869B + +# Cyan +color6 #79A976 +color14 #8CBA7F + +# White +color7 #BEAC8E +color15 #E0CDA5 + + + +#: Keyboard shortcuts {{{ + +map ctrl+v paste_from_clipboard +map ctrl+c copy_and_clear_or_interrupt +map ctrl+shift+e open_url_with_hints +map ctrl+shift+o pass_selection_to_program qutebrowser + + diff --git a/config/kitty/kitty.conf b/config/kitty/kitty.conf index eb72ac6b..da111c04 100644 --- a/config/kitty/kitty.conf +++ b/config/kitty/kitty.conf @@ -1,3 +1,5 @@ +include $HOME/.cache/wal/colors-kitty.conf + font_family Iosevka Nerd Font font_size 10.5 bold_font auto diff --git a/config/material-colors/templates/material-discord.scss b/config/material-colors/templates/material-discord.scss index d563efc1..7c8d1131 100644 --- a/config/material-colors/templates/material-discord.scss +++ b/config/material-colors/templates/material-discord.scss @@ -50,4 +50,3 @@ $lightness: round(lightness($primary)); [class*="userPopoutOuter_"] { border-radius: 16px !important; } - \ No newline at end of file diff --git a/setup b/setup index 9b382b5f..8d704375 100755 --- a/setup +++ b/setup @@ -143,6 +143,11 @@ pkg=( bun-bin dart-sass sass + gtksourceview3 + gtksourceviewmm + gtkmm3 + tinyxml2 + cairomm ## python python-pillow