Skip to content

Commit

Permalink
fixing async errors take 1
Browse files Browse the repository at this point in the history
  • Loading branch information
fufexan committed Dec 27, 2023
1 parent 09bd0c9 commit 34e1a8e
Show file tree
Hide file tree
Showing 21 changed files with 298 additions and 258 deletions.
23 changes: 16 additions & 7 deletions home/services/ags/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,9 @@ const css = App.configDir + "/style.css";

Utils.exec(`sass ${scss} ${css}`);

App.connect("config-parsed", () => print("config parsed"));
export default {
style: css,
windows: [
SystemMenu,
Music,
Osd,
Bar,
],

closeWindowDelay: {
"system-menu": 200,
},
Expand All @@ -31,3 +25,18 @@ function reloadCss() {
}

Utils.monitorFile(`${App.configDir}/style`, reloadCss, "directory");

function addWindows(windows) {
windows.forEach((win) => App.addWindow(win));
}

Utils.idle(() =>
addWindows(
[
Bar(),
Music(),
Osd(),
SystemMenu(),
],
)
);
55 changes: 33 additions & 22 deletions home/services/ags/imports.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
// Helpers
export const resource = (file) => `resource:///com/github/Aylur/ags/${file}.js`;
export const require = async (file) => (await import(resource(file))).default;
export const requireCustom = async (path) => (await import(path)).default;
export const service = async (file) => await require(`service/${file}`);

// Required components
export const App = await require("app");
export const GLib = await requireCustom("gi://GLib");
export const Service = await require("service");
export const Utils = await import(resource("utils"));
export const Variable = await require("variable");
export const Widget = await require("widget");
import App from "resource:///com/github/Aylur/ags/app.js";
import GLib from "gi://GLib";
import * as Utils from "resource:///com/github/Aylur/ags/utils.js";
import Service from "resource:///com/github/Aylur/ags/service.js";
import Variable from "resource:///com/github/Aylur/ags/variable.js";
import Widget from "resource:///com/github/Aylur/ags/widget.js";

// Services
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 PowerProfiles = await service("powerprofiles");
export const SystemTray = await service("systemtray");
import Audio from "resource:///com/github/Aylur/ags/service/audio.js";
import Battery from "resource:///com/github/Aylur/ags/service/battery.js";
import Bluetooth from "resource:///com/github/Aylur/ags/service/bluetooth.js";
import Hyprland from "resource:///com/github/Aylur/ags/service/hyprland.js";
import Mpris from "resource:///com/github/Aylur/ags/service/mpris.js";
import Network from "resource:///com/github/Aylur/ags/service/network.js";
import PowerProfiles from "resource:///com/github/Aylur/ags/service/powerprofiles.js";
import SystemTray from "resource:///com/github/Aylur/ags/service/systemtray.js";

import Icons from "./utils/icons.js";

// My definitions
export const Icons = await requireCustom("./utils/icons.js");
export {
App,
Audio,
Battery,
Bluetooth,
GLib,
Hyprland,
Icons,
Mpris,
Network,
PowerProfiles,
Service,
SystemTray,
Utils,
Variable,
Widget,
};
3 changes: 0 additions & 3 deletions home/services/ags/services/brightness.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,4 @@ class BrightnessService extends Service {

const service = new BrightnessService();

// make it global for easy use with cli
globalThis.brightness = service;

export default service;
3 changes: 2 additions & 1 deletion home/services/ags/utils/mpris.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { GLib, Icons, Utils } from "../imports.js";
import { Icons, Utils } from "../imports.js";
import GLib from "gi://GLib";

export const mprisStateIcon = (status) => {
const state = status == "Playing" ? "pause" : "play";
Expand Down
3 changes: 2 additions & 1 deletion home/services/ags/utils/popup_window.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { App, Widget } from "../imports.js";
import App from "resource:///com/github/Aylur/ags/app.js";
import { Widget } from "../imports.js";
const { Box, Revealer, Window } = Widget;

export default (
Expand Down
76 changes: 39 additions & 37 deletions home/services/ags/windows/bar/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,40 @@ import CpuRam from "./modules/cpu_ram.js";
import Tray from "./modules/tray.js";
import Workspaces from "./modules/workspaces.js";

const SystemInfo = Widget.EventBox({
className: "system-menu-toggler",
onPrimaryClick: () => App.toggleWindow("system-menu"),
const SystemInfo = () =>
Widget.EventBox({
className: "system-menu-toggler",
onPrimaryClick: () => App.toggleWindow("system-menu"),

child: Widget.Box({
children: [
Net,
Bluetooth,
Battery,
],
}),
})
.hook(
App,
(self, window, visible) => {
if (window === "system-menu") {
self.toggleClassName("active", visible);
}
},
);
child: Widget.Box({
children: [
Net(),
Bluetooth(),
Battery(),
],
}),
})
.hook(
App,
(self, window, visible) => {
if (window === "system-menu") {
self.toggleClassName("active", visible);
}
},
);

const Start = Widget.Box({
hexpand: true,
hpack: "start",
children: [
Workspaces,
Workspaces(),
// Indicators
],
});

const Center = Widget.Box({
children: [
Music,
Music(),
],
});

Expand All @@ -49,24 +50,25 @@ const End = Widget.Box({
hpack: "end",

children: [
Tray,
CpuRam,
SystemInfo,
Date,
Tray(),
CpuRam(),
SystemInfo(),
Date(),
],
});

export default Widget.Window({
monitor: 0,
name: `bar`,
anchor: ["top", "left", "right"],
exclusivity: "exclusive",
export default () =>
Widget.Window({
monitor: 0,
name: `bar`,
anchor: ["top", "left", "right"],
exclusivity: "exclusive",

child: Widget.CenterBox({
className: "bar",
child: Widget.CenterBox({
className: "bar",

startWidget: Start,
centerWidget: Center,
endWidget: End,
}),
});
startWidget: Start,
centerWidget: Center,
endWidget: End,
}),
});
7 changes: 4 additions & 3 deletions home/services/ags/windows/bar/modules/battery.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Battery, Widget } from "../../../imports.js";

export default Widget.Icon({ className: "battery module" })
.bind("icon", Battery, "icon-name")
.bind("tooltip-text", Battery, "percent", (p) => `Battery on ${p}%`);
export default () =>
Widget.Icon({ className: "battery module" })
.bind("icon", Battery, "icon-name")
.bind("tooltip-text", Battery, "percent", (p) => `Battery on ${p}%`);
7 changes: 4 additions & 3 deletions home/services/ags/windows/bar/modules/bluetooth.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
getBluetoothText,
} from "../../../utils/bluetooth.js";

export default Widget.Icon({ className: "bluetooth module" })
.bind("icon", Bluetooth, "connected-devices", getBluetoothIcon)
.bind("tooltip-text", Bluetooth, "connected-devices", getBluetoothText);
export default () =>
Widget.Icon({ className: "bluetooth module" })
.bind("icon", Bluetooth, "connected-devices", getBluetoothIcon)
.bind("tooltip-text", Bluetooth, "connected-devices", getBluetoothText);
15 changes: 8 additions & 7 deletions home/services/ags/windows/bar/modules/cpu_ram.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ const ram = {
.catch((err) => print(err)),
};

export default Widget.Box({
className: "system-info module",
export default () =>
Widget.Box({
className: "system-info module",

children: [
Indicator(cpu),
Indicator(ram),
],
});
children: [
Indicator(cpu),
Indicator(ram),
],
});
21 changes: 11 additions & 10 deletions home/services/ags/windows/bar/modules/date.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { Utils, Widget } from "../../../imports.js";

export default Widget.EventBox({
child: Widget.Label({ className: "date module" })
.poll(
1000,
(self) =>
Utils.execAsync(["date", "+%a %b %d %H:%M"]).then((r) =>
self.label = r
),
),
});
export default () =>
Widget.EventBox({
child: Widget.Label({ className: "date module" })
.poll(
1000,
(self) =>
Utils.execAsync(["date", "+%a %b %d %H:%M"]).then((r) =>
self.label = r
),
),
});
38 changes: 20 additions & 18 deletions home/services/ags/windows/bar/modules/music.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { App, Mpris, Widget } from "../../../imports.js";
import { Mpris, Widget } from "../../../imports.js";
import App from "resource:///com/github/Aylur/ags/app.js";

const Cover = (player) =>
Widget.Box({ className: "cover" })
Expand Down Expand Up @@ -26,20 +27,21 @@ export const MusicBox = (player) =>
],
});

export default Widget.EventBox({
className: "music",
onPrimaryClick: () => App.toggleWindow("music"),
})
.hook(
App,
(self, window, visible) => {
if (window === "music") {
self.toggleClassName("active", visible);
}
},
)
.bind("visible", Mpris, "players", (p) => p.length > 0)
.bind("child", Mpris, "players", (players) => {
if (players.length == 0) return Widget.Box();
return MusicBox(players[0]);
});
export default () =>
Widget.EventBox({
className: "music",
onPrimaryClick: () => App.toggleWindow("music"),
})
.hook(
App,
(self, window, visible) => {
if (window === "music") {
self.toggleClassName("active", visible);
}
},
)
.bind("visible", Mpris, "players", (p) => p.length > 0)
.bind("child", Mpris, "players", (players) => {
if (players.length == 0) return Widget.Box();
return MusicBox(players[0]);
});
27 changes: 14 additions & 13 deletions home/services/ags/windows/bar/modules/net.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { Network, Widget } from "../../../imports.js";
import { getNetIcon, getNetText } from "../../../utils/net.js";

export default Widget.Icon({ className: "net module" })
.bind(
"icon",
Network,
"connectivity",
getNetIcon,
)
.bind(
"tooltip-text",
Network,
"connectivity",
getNetText,
);
export default () =>
Widget.Icon({ className: "net module" })
.bind(
"icon",
Network,
"connectivity",
getNetIcon,
)
.bind(
"tooltip-text",
Network,
"connectivity",
getNetText,
);
5 changes: 3 additions & 2 deletions home/services/ags/windows/bar/modules/tray.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@ const Item = (item) =>
),
});

export default Widget.Box({ className: "tray module" })
.bind("children", SystemTray, "items", (items) => items.map(Item));
export default () =>
Widget.Box({ className: "tray module" })
.bind("children", SystemTray, "items", (items) => items.map(Item));
Loading

0 comments on commit 34e1a8e

Please sign in to comment.