user config round 2 (#271)

This commit is contained in:
end-4 2024-03-01 23:49:18 +07:00
parent 29fdbd376f
commit 8ec23c9966
15 changed files with 71 additions and 56 deletions

View file

@ -0,0 +1,14 @@
const { Gio, GLib, Gtk } = imports.gi;
export function fileExists(filePath) {
let file = Gio.File.new_for_path(filePath);
return file.query_exists(null);
}
export function expandTilde(path) {
if (path.startsWith('~')) {
return GLib.get_home_dir() + path.slice(1);
} else {
return path;
}
}

View file

@ -1,16 +1,16 @@
const { Gdk, GdkPixbuf, Gio, GLib, Gtk } = imports.gi;
const { Gdk, GdkPixbuf, GLib, Gtk } = imports.gi;
import App from 'resource:///com/github/Aylur/ags/app.js';
import Widget from 'resource:///com/github/Aylur/ags/widget.js';
import * as Utils from 'resource:///com/github/Aylur/ags/utils.js';
const { exec, execAsync } = Utils;
import Mpris from 'resource:///com/github/Aylur/ags/service/mpris.js';
const { exec, execAsync } = Utils;
const { Box, EventBox, Icon, Scrollable, Label, Button, Revealer } = Widget;
import { fileExists } from '../.miscutils/files.js';
import { AnimatedCircProg } from "../.commonwidgets/cairo_circularprogress.js";
import { showMusicControls } from '../../variables.js';
const COMPILED_STYLE_DIR = `${GLib.get_user_cache_dir()}/ags/user/generated`
const LIGHTDARK_FILE_LOCATION = `${GLib.get_user_cache_dir()}/ags/user/colormode.txt`;
const lightDark = Utils.readFile(LIGHTDARK_FILE_LOCATION).trim();
const COVER_COLORSCHEME_SUFFIX = '_colorscheme.css';
@ -31,10 +31,6 @@ function lengthStr(length) {
const sec0 = sec < 10 ? '0' : '';
return `${min}:${sec0}${sec}`;
}
function fileExists(filePath) {
let file = Gio.File.new_for_path(filePath);
return file.query_exists(null);
}
function detectMediaSource(link) {
if (link.startsWith("file://")) {

View file

@ -12,7 +12,6 @@ const LATEX_DIR = `${GLib.get_user_cache_dir()}/ags/media/latex`;
const CUSTOM_SOURCEVIEW_SCHEME_PATH = `${App.configDir}/assets/themes/sourceviewtheme.xml`;
const CUSTOM_SCHEME_ID = 'custom';
const USERNAME = GLib.get_user_name();
const AI_MESSAGE_CURSOR = ' ...';
/////////////////////// Custom source view colorscheme /////////////////////////
@ -258,7 +257,7 @@ const MessageContent = (content) => {
const lastLabel = kids[kids.length - 1];
let blockContent = lines.slice(lastProcessed, lines.length).join('\n');
if (!inCode)
lastLabel.label = `${md2pango(blockContent)}${useCursor ? AI_MESSAGE_CURSOR : ''}`;
lastLabel.label = `${md2pango(blockContent)}${useCursor ? userOptions.ai.writingCursor : ''}`;
else
lastLabel.attribute.updateText(blockContent);
}

View file

@ -6,6 +6,7 @@ import Widget from 'resource:///com/github/Aylur/ags/widget.js';
import * as Utils from 'resource:///com/github/Aylur/ags/utils.js';
const { Box, Button, Label, Overlay, Revealer, Scrollable, Stack } = Widget;
const { execAsync, exec } = Utils;
import { fileExists } from '../../.miscutils/files.js';
import { MaterialIcon } from '../../.commonwidgets/materialicon.js';
import { MarginRevealer } from '../../.widgethacks/advancedrevealers.js';
import { setupCursorHover, setupCursorHoverInfo } from '../../.widgetutils/cursorhover.js';
@ -20,18 +21,13 @@ async function getImageViewerApp(preferredApp) {
}
const IMAGE_REVEAL_DELAY = 13; // Some wait for inits n other weird stuff
const IMAGE_VIEWER_APP = getImageViewerApp('loupe'); // Gnome's image viewer cuz very comfortable zooming
const IMAGE_VIEWER_APP = getImageViewerApp(userOptions.apps.imageViewer); // Gnome's image viewer cuz very comfortable zooming
const USER_CACHE_DIR = GLib.get_user_cache_dir();
// Create cache folder and clear pics from previous session
Utils.exec(`bash -c 'mkdir -p ${USER_CACHE_DIR}/ags/media/waifus'`);
Utils.exec(`bash -c 'rm ${USER_CACHE_DIR}/ags/media/waifus/*'`);
export function fileExists(filePath) {
let file = Gio.File.new_for_path(filePath);
return file.query_exists(null);
}
const CommandButton = (command) => Button({
className: 'sidebar-chat-chip sidebar-chat-chip-action txt txt-small',
onClicked: () => sendMessage(command),

View file

@ -14,7 +14,6 @@ import { waifuView, waifuCommands, sendMessage as waifuSendMessage, waifuTabIcon
import { enableClickthrough } from "../.widgetutils/clickthrough.js";
const TextView = Widget.subclass(Gtk.TextView, "AgsTextView");
const EXPAND_INPUT_THRESHOLD = 30;
const APIS = [
{

View file

@ -9,7 +9,7 @@ import { setupCursorHover } from '../.widgetutils/cursorhover.js';
import { NavigationIndicator } from '../.commonwidgets/cairo_navigationindicator.js';
import toolBox from './toolbox.js';
import apiWidgets from './apiwidgets.js';
import apiwidgets, { chatEntry } from './apiwidgets.js';
import { chatEntry } from './apiwidgets.js';
const contents = [
{

View file

@ -1,7 +1,5 @@
import Widget from 'resource:///com/github/Aylur/ags/widget.js';
import * as Utils from 'resource:///com/github/Aylur/ags/utils.js';
const { Box, Button, EventBox, Label, Revealer, Scrollable, Stack } = Widget;
const { execAsync, exec } = Utils;
const { Box, Scrollable } = Widget;
import QuickScripts from './tools/quickscripts.js';
import ColorPicker from './tools/colorpicker.js';

View file

@ -11,7 +11,6 @@ import { setupCursorHover } from '../../.widgetutils/cursorhover.js';
Gtk.IconTheme.get_default().append_search_path(`${App.configDir}/assets/icons`);
import { distroID, isArchDistro, isDebianDistro, hasFlatpak } from '../../.miscutils/system.js';
const scripts = [
{
icon: 'nixos-symbolic',

View file

@ -11,11 +11,6 @@ import { getCalendarLayout } from "./calendar_layout.js";
let calendarJson = getCalendarLayout(undefined, true);
let monthshift = 0;
function fileExists(filePath) {
let file = Gio.File.new_for_path(filePath);
return file.query_exists(null);
}
function getDateInXMonthsTime(x) {
var currentDate = new Date(); // Get the current date
var targetMonth = currentDate.getMonth() + x; // Calculate the target month

View file

@ -10,14 +10,6 @@ import { BluetoothIndicator, NetworkIndicator } from '../.commonwidgets/statusic
import { setupCursorHover } from '../.widgetutils/cursorhover.js';
import { MaterialIcon } from '../.commonwidgets/materialicon.js';
function expandTilde(path) {
if (path.startsWith('~')) {
return GLib.get_home_dir() + path.slice(1);
} else {
return path;
}
}
export const ToggleIconWifi = (props = {}) => Widget.Button({
className: 'txt-small sidebar-iconbutton',
tooltipText: 'Wifi | Right-click to configure',
@ -123,7 +115,7 @@ export const ModuleInvertColors = async (props = {}) => {
button.toggleClassName('sidebar-button-active', false);
}
else {
Hyprland.messageAsync(`j/keyword decoration:screen_shader ${expandTilde('~/.config/hypr/shaders/invert.frag')}`)
Hyprland.messageAsync(`j/keyword decoration:screen_shader ${GLib.get_home_dir()}/.config/hypr/shaders/invert.frag`)
.catch(print);
button.toggleClassName('sidebar-button-active', true);
}

View file

@ -1 +1,29 @@
$darkmode: true;
$primary: #8ccdff;
$onPrimary: #003350;
$primaryContainer: #004b73;
$onPrimaryContainer: #cae6ff;
$secondary: #b7c8d9;
$onSecondary: #22323f;
$secondaryContainer: #394856;
$onSecondaryContainer: #d3e4f6;
$tertiary: #d0bfe8;
$onTertiary: #362b4a;
$tertiaryContainer: #4e4162;
$onTertiaryContainer: #eddcff;
$error: #ffb4a9;
$onError: #680003;
$errorContainer: #930006;
$onErrorContainer: #ffb4a9;
$colorbarbg: #0F1012;
$background: #0F1012;
$onBackground: #e2e2e5;
$surface: #1a1c1e;
$onSurface: #e2e2e5;
$surfaceVariant: #41474d;
$onSurfaceVariant: #c2c7ce;
$outline: #8b9198;
$shadow: #000000;
$inverseSurface: #e2e2e5;
$inverseOnSurface: #2f3032;
$inversePrimary: #006497;

View file

@ -4,7 +4,7 @@ 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';
import { fileExists } from './messages.js';
import { fileExists } from '../modules/.miscutils/files.js';
const initMessages =
[
@ -25,20 +25,12 @@ const initMessages =
{ 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```" }], },
];
function expandTilde(path) {
if (path.startsWith('~')) {
return GLib.get_home_dir() + path.slice(1);
} else {
return path;
}
}
Utils.exec(`mkdir -p ${GLib.get_user_cache_dir()}/ags/user/ai`);
const KEY_FILE_LOCATION = `${GLib.get_user_cache_dir()}/ags/user/ai/google_key.txt`;
const APIDOM_FILE_LOCATION = `${GLib.get_user_cache_dir()}/ags/user/ai/google_api_dom.txt`;
function replaceapidom(URL) {
if (fileExists(expandTilde(APIDOM_FILE_LOCATION))) {
var contents = Utils.readFile(expandTilde(APIDOM_FILE_LOCATION)).trim();
if (fileExists(APIDOM_FILE_LOCATION)) {
var contents = Utils.readFile(APIDOM_FILE_LOCATION).trim();
var URL = URL.toString().replace("generativelanguage.googleapis.com", contents);
}
return URL;
@ -141,7 +133,7 @@ class GeminiService extends Service {
_messages = [];
_cycleModels = true;
_requestCount = 0;
_temperature = 0.9;
_temperature = userOptions.ai.defaultTemperature;
_modelIndex = 0;
_key = '';
_decoder = new TextDecoder();
@ -149,7 +141,7 @@ class GeminiService extends Service {
constructor() {
super();
if (fileExists(expandTilde(KEY_FILE_LOCATION))) this._key = Utils.readFile(expandTilde(KEY_FILE_LOCATION)).trim();
if (fileExists(KEY_FILE_LOCATION)) this._key = Utils.readFile(KEY_FILE_LOCATION).trim();
else this.emit('hasKey', false);
if (this._assistantPrompt) this._messages = [...initMessages];
@ -164,7 +156,7 @@ class GeminiService extends Service {
get key() { return this._key }
set key(keyValue) {
this._key = keyValue;
Utils.writeFile(this._key, expandTilde(KEY_FILE_LOCATION))
Utils.writeFile(this._key, KEY_FILE_LOCATION)
.then(this.emit('hasKey', true))
.catch(err => print(err));
}

View file

@ -4,7 +4,7 @@ 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';
import { fileExists } from './messages.js';
import { fileExists } from '../modules/.miscutils/files.js';
const PROVIDERS = { // There's this list hmm https://github.com/zukixa/cool-ai-stuff/
'openai': {
@ -134,10 +134,10 @@ class GPTService extends Service {
}
_assistantPrompt = true;
_currentProvider = 'openai';
_currentProvider = userOptions.ai.defaultGPTProvider;
_cycleModels = false;
_requestCount = 0;
_temperature = 0.9;
_temperature = userOptions.ai.defaultTemperature;
_messages = [];
_modelIndex = 0;
_key = '';

View file

@ -2,7 +2,6 @@ const { Notify, GLib, Gio } = imports.gi;
import * as Utils from 'resource:///com/github/Aylur/ags/utils.js';
import Battery from 'resource:///com/github/Aylur/ags/service/battery.js';
export function fileExists(filePath) {
let file = Gio.File.new_for_path(filePath);
return file.query_exists(null);

View file

@ -1,5 +1,13 @@
let userConfigOptions = {
'ai': {
'defaultGPTProvider': 'openai',
'defaultTemperature': 0.9,
'writingCursor': ' ...', // Warning: Using weird characters can mess up Markdown rendering
},
'apps': {
'imageViewer': 'loupe',
},
'battery': {
'low': 20,
'critical': 10,
@ -18,7 +26,7 @@ let userConfigOptions = {
'wsNumMarginScale': 0.07,
},
'search': {
'excludedSites': ['quora.com'], // Exclude bullshit
'excludedSites': ['quora.com'],
},
'weather': {
'city': '',