diff --git a/users/configs/ags/default.nix b/users/configs/ags/default.nix index f81b847..022668a 100644 --- a/users/configs/ags/default.nix +++ b/users/configs/ags/default.nix @@ -1,6 +1,7 @@ { user ? throw "user argument is required" }: { config, lib, pkgs, ... }: let + hmConfig = config.home-manager.users."${user.name}"; agsConfig = (import ./src { inherit pkgs; }); in { @@ -11,5 +12,21 @@ in source = "${agsConfig}/share/config.js"; target = "ags/config.js"; }; + + programs.matugen.settings.templates.ags = { + input_path = ./theme.sass; + output_path = "${hmConfig.xdg.configHome}/ags/theme.sass"; + }; + + wayland.windowManager.hyprland.initExtraConfig = "${lib.meta.getExe (pkgs.writeShellApplication { + name = "init-ags"; + runtimeInputs = with pkgs; [ + ags + sassc + ]; + text = '' + ags &> /tmp/ags.log + ''; + })} &"; }; } diff --git a/users/configs/ags/src/.prettierrc.json b/users/configs/ags/src/.prettierrc.json new file mode 100644 index 0000000..24f8432 --- /dev/null +++ b/users/configs/ags/src/.prettierrc.json @@ -0,0 +1,7 @@ +{ + "arrowParens": "avoid", + "bracketSameLine": true, + "bracketSpacing": true, + "singleQuote": true, + "trailingComma": "all" +} diff --git a/users/configs/ags/src/eslint.config.js b/users/configs/ags/src/eslint.config.js new file mode 100644 index 0000000..eaac88f --- /dev/null +++ b/users/configs/ags/src/eslint.config.js @@ -0,0 +1,106 @@ +/* eslint no-use-before-define: 0 */ + +import globals from 'globals'; +import pluginJs from '@eslint/js'; +import tseslint from 'typescript-eslint'; +import typescriptEslint from '@typescript-eslint/eslint-plugin'; +import unicorn from 'eslint-plugin-unicorn'; +import prettier from 'eslint-plugin-prettier'; +import tsParser from '@typescript-eslint/parser'; + +export default [ + { files: ['**/*.{js,mjs,cjs,ts}'] }, + { languageOptions: { globals: globals.browser } }, + pluginJs.configs.recommended, + ...tseslint.configs.recommended, + { + plugins: { + '@typescript-eslint': typescriptEslint, + unicorn, + prettier, + }, + + languageOptions: { + globals: { + ...globals.browser, + }, + + parser: tsParser, + ecmaVersion: 5, + sourceType: 'script', + + parserOptions: { + project: ['./tsconfig.json'], + }, + }, + + settings: { + 'import/resolver': { + node: { + extensions: ['.js', '.jsx', '.ts', '.tsx'], + }, + }, + }, + + rules: { + curly: ['error', 'multi-line'], + 'eol-last': ['error', 'always'], + semi: ['error', 'always'], + quotes: ['error', 'single'], + 'no-await-in-loop': 'warn', + 'no-constructor-return': 'error', + 'no-duplicate-imports': 'error', + 'no-self-compare': 'error', + 'no-unreachable-loop': 'error', + 'no-trailing-spaces': 'error', + 'no-console': 'warn', + 'no-shadow': 'off', + '@typescript-eslint/no-shadow': ['error'], + 'no-unused-vars': 'off', + '@typescript-eslint/no-unused-vars': ['error'], + 'no-use-before-define': 'off', + '@typescript-eslint/no-use-before-define': ['error'], + '@typescript-eslint/require-await': 'warn', + + '@typescript-eslint/no-misused-promises': ['error', { + checksVoidReturn: false, + }], + + '@typescript-eslint/naming-convention': ['error', { + selector: 'default', + format: ['camelCase'], + }, { + selector: 'variableLike', + format: ['camelCase', 'PascalCase'], + }, { + selector: 'memberLike', + format: ['camelCase'], + }, { + selector: 'typeLike', + format: ['PascalCase'], + }, { + selector: 'property', + format: ['snake_case'], + }, { + selector: 'method', + format: ['camelCase'], + }, { + selector: ['enumMember', 'enum'], + format: ['UPPER_CASE'], + }], + + 'unicorn/empty-brace-spaces': 'off', + 'unicorn/expiring-todo-comments': 'off', + 'unicorn/no-array-for-each': 'off', + + 'unicorn/filename-case': ['error', { + case: 'camelCase', + }], + + 'unicorn/numeric-separators-style': 'off', + 'unicorn/prevent-abbreviations': 'off', + }, + + "ignores": ["*.config.js"] + } +]; diff --git a/users/configs/ags/src/index.ts b/users/configs/ags/src/index.ts index aef1989..467bab6 100644 --- a/users/configs/ags/src/index.ts +++ b/users/configs/ags/src/index.ts @@ -1,12 +1,17 @@ -import Gtk from "gi://Gtk?version=3.0" -import Gdk from "gi://Gdk" -import { range } from "./lib"; +import gtk from 'gi://Gtk?version=3.0'; +import gdk from 'gi://Gdk'; +import { range } from 'lib'; +import themeInit from 'theme'; +import bar from 'widgets/bar/bar'; -const forMonitors = (widget: (monitor: number) => Gtk.Window) => { - const n = Gdk.Display.get_default()?.get_n_monitors() || 1; - return range(n, 0).flatMap(widget) -} +const forMonitors = (widget: (monitor: number) => gtk.Window) => { + const n = gdk.Display.get_default()?.get_n_monitors() || 1; + return range(n, 0).flatMap(widget); +}; App.config({ - windows: [] -}) + style: themeInit(), + windows: [ + ...forMonitors(bar), + ] +}); diff --git a/users/configs/ags/src/lib.ts b/users/configs/ags/src/lib.ts index f952b55..82e7577 100644 --- a/users/configs/ags/src/lib.ts +++ b/users/configs/ags/src/lib.ts @@ -1,3 +1,3 @@ export const range = (length: number, start = 1) => { - return Array.from({ length }, (_, i) => i + start) -} + return Array.from({ length }, (n, i) => i + start); +}; diff --git a/users/configs/ags/src/package.json b/users/configs/ags/src/package.json index 3af9c41..824c179 100644 --- a/users/configs/ags/src/package.json +++ b/users/configs/ags/src/package.json @@ -2,8 +2,20 @@ "name": "ags", "module": "index.ts", "type": "module", + "scripts": { + "lint": "eslint ." + }, "devDependencies": { - "@types/bun": "latest" + "@eslint/eslintrc": "^3.1.0", + "@eslint/js": "^9.6.0", + "@types/bun": "^1.1.6", + "@typescript-eslint/eslint-plugin": "^7.14.1", + "@typescript-eslint/parser": "^7.14.1", + "eslint": "9.x", + "eslint-plugin-prettier": "^5.1.3", + "eslint-plugin-unicorn": "^54.0.0", + "globals": "^15.6.0", + "typescript-eslint": "^7.14.1" }, "peerDependencies": { "typescript": "^5.0.0" diff --git a/users/configs/ags/src/theme.ts b/users/configs/ags/src/theme.ts new file mode 100644 index 0000000..3cd2782 --- /dev/null +++ b/users/configs/ags/src/theme.ts @@ -0,0 +1,25 @@ +export default () => { + const css = `${App.configDir}/theme.css`; + const scss = `${App.configDir}/theme.sass`; + + let themeExists = true; + + try { + Utils.readFile(scss); + Utils.exec(`sassc ${scss} ${css}`); + } catch (error) { + console.error(error); + themeExists = false; + } + + Utils.monitorFile( + `${App.configDir}/theme.sass`, + function () { + Utils.exec(`sassc ${scss} ${css}`); + App.resetCss(); + App.applyCss(css); + }, + ); + + return themeExists ? css : undefined; +}; diff --git a/users/configs/ags/src/widgets/bar/bar.ts b/users/configs/ags/src/widgets/bar/bar.ts new file mode 100644 index 0000000..8bad26d --- /dev/null +++ b/users/configs/ags/src/widgets/bar/bar.ts @@ -0,0 +1,29 @@ +import date from './date/date'; + +export default (monitor: number) => Widget.Window({ + monitor, + class_name: 'bar', + name: `bar${monitor}`, + exclusivity: 'exclusive', + anchor: ['top', 'right', 'left'], + child: Widget.CenterBox({ + css: 'min-width: 2px; min-height: 2px; padding-top: 2px; padding-bottom: 2px;', + // eslint-disable-next-line @typescript-eslint/naming-convention + startWidget: Widget.Box({ + hexpand: true, + children: [], + }), + // eslint-disable-next-line @typescript-eslint/naming-convention + centerWidget: Widget.Box({ + hpack: 'center', + children: [ + date() + ], + }), + // eslint-disable-next-line @typescript-eslint/naming-convention + endWidget: Widget.Box({ + hexpand: true, + children: [], + }), + }), +}); diff --git a/users/configs/ags/src/widgets/bar/date/date.ts b/users/configs/ags/src/widgets/bar/date/date.ts new file mode 100644 index 0000000..728e09f --- /dev/null +++ b/users/configs/ags/src/widgets/bar/date/date.ts @@ -0,0 +1,13 @@ +import glib from 'gi://GLib'; + +const clock = Variable(glib.DateTime.new_now_local(), { + poll: [1000, () => glib.DateTime.new_now_local()] +}); + +const time = Utils.derive([clock], (c) => c.format('%H:%M - %A, %e %B %Y') || ''); + +export default () => Widget.Label({ + class_name: 'label', + justification: 'center', + label: time.bind(), +}); diff --git a/users/configs/ags/theme.sass b/users/configs/ags/theme.sass new file mode 100644 index 0000000..7bc30b3 --- /dev/null +++ b/users/configs/ags/theme.sass @@ -0,0 +1,5 @@ +.bar + background-color: {{colors.surface.default.hex}} + +.label + color: {{colors.on_surface.default.hex}}