dotfiles icon indicating copy to clipboard operation
dotfiles copied to clipboard

Suggestion for your own ags config

Open cafetestrest opened this issue 1 year ago • 6 comments

Hi @Aylur , I know that we can implement a custom widgets that suit us, have you ever tough about creating a weather widget for your own setup?

Also, there is a weather_key in ags/.gitignore file, which might hint into weather widget. Anyhow, I would appreciate a great looking weather widget for ags :smiley:

cafetestrest avatar Dec 28 '23 14:12 cafetestrest

that is a left over from my eww setup. I might do it just to fill some space though

Aylur avatar Dec 31 '23 16:12 Aylur

Hi @Aylur , I know that we can implement a custom widgets that suit us, have you ever tough about creating a weather widget for your own setup?

i have a close thing to what he might have done: image image

https://github.com/Aylur/dotfiles/assets/84800625/66833382-bbae-446a-9d9e-e90cb1f65763

this is the code: main Weather.js to be put in ~/.config/ags/js/bar/buttons/Weather.js

import { Widget, Variable } from '../../imports.js';
import App from 'resource:///com/github/Aylur/ags/app.js';
import PanelButton from '../PanelButton.js';
import Gdk from 'gi://Gdk';

const weather = Variable(
    {},
    {
        poll: [
            30000,
            `python ${App.configDir}/assets/weather`,
            out => JSON.parse(out),
        ],
    }
);

export const Weather = () =>
    PanelButton({
        class_name: 'weather',
        content: Widget.Label({
            binds: [['label', weather, 'value', value => value.text || '󰇘']],
        }),
        window: 'weather-tooltip',
        connections: [
            [
                weather,
                (self, value) => {
                    if (value) {
                        self.set_tooltip_text(value.tooltip || 'Weather Data');
                    }
                },
            ],
        ],
        on_primary_click: btn => {
            let menu = Widget.Menu({
                children: [
                    Widget.MenuItem({
                        child: Widget.Label({
                            label: weather.value.tooltip || '󰇘',
                            use_markup: true, // Enable Pango markup
                        }),
                    }),
                ],
            });

            menu.popup_at_widget(
                btn,
                Gdk.Gravity.SOUTH,
                Gdk.Gravity.NORTH,
                null
            );
        },
    });

imports.js to be put in ~/.config/ags/js/

const resource = file => `resource:///com/github/Aylur/ags/${file}.js`;
const require = async file => (await import(resource(file))).default;
const service = async file => await require(`service/${file}`);

export const App = await require('app');
export const Widget = await require('widget');
export const Service = await require('service');
export const Variable = await require('variable');
export const Utils = await import(resource('utils'));

export const Applications = await service('applications');
export const Audio = await service('audio');
export const Battery = await service('battery');
export const Bluetooth = await service('bluetooth');
export const Hyprland = await service('hyprland');
export const Mpris = await service('mpris');
export const Network = await service('network');
export const Notifications = await service('notifications');
export const SystemTray = await service('systemtray');

see the code was copied from @PoSayDone's dotfiles and then refactored and edited a little bit for a better view.

daUnknownCoder avatar Jan 30 '24 14:01 daUnknownCoder

Perhaps a suggestion of what I did while back, but I just over-complicated the logic :) Screenshot_2024-02-01_18-19-48

cafetestrest avatar Feb 01 '24 17:02 cafetestrest

Perhaps a suggestion of what I did while back, but I just over-complicated the logic :) Screenshot_2024-02-01_18-19-48

omg thats way better than mine can i get the code?

daUnknownCoder avatar Feb 01 '24 18:02 daUnknownCoder

Perhaps a suggestion of what I did while back, but I just over-complicated the logic :) Screenshot_2024-02-01_18-19-48

mine looks like this: image

daUnknownCoder avatar Feb 02 '24 07:02 daUnknownCoder

omg thats way better than mine can i get the code?

They are already public just a mess in the files, I think this is all of the required files, but could be more.

ags:

  • weather service: https://github.com/cafetestrest/nixos/blob/main/config/ags/js/services/weather.js
  • weather popup window: https://github.com/cafetestrest/nixos/blob/main/config/ags/js/dashboard/Weather.js
  • weather widget logic: https://github.com/cafetestrest/nixos/blob/main/config/ags/js/bar/buttons/Weather.js
  • add it in topbar: https://github.com/cafetestrest/nixos/blob/main/config/ags/js/bar/TopBar.js
  • add it in QS: https://github.com/cafetestrest/nixos/blob/main/config/ags/js/quicksettings/QuickSettings.js
  • add service in globals.js: https://github.com/cafetestrest/nixos/blob/main/config/ags/js/settings/globals.js
  • weather scss: https://github.com/cafetestrest/nixos/blob/main/config/ags/scss/widgets/dashboard.scss

weather bash script:

  • https://github.com/cafetestrest/nixos/blob/main/config/scripts/openweathermap.sh
  • you need to create your own file for providing location and api key or update the code to hard-code it (ConfigFile variable in openweathermap.sh)

cafetestrest avatar Feb 02 '24 14:02 cafetestrest