Skip to content

Commit

Permalink
feat(ags): show error disk usage when > 80
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed May 28, 2024
1 parent f66baf9 commit b6ab27f
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 10 deletions.
5 changes: 3 additions & 2 deletions config/ags/lib/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ export const substitutes = {
Caprine: "facebook-messenger",
"com.raggesilver.BlackBox-symbolic": "terminal-symbolic",
"org.wezfurlong.wezterm-symbolic": "terminal-symbolic",
quake: "org.wezfurlong.wezterm",
"audio-headset-bluetooth": "audio-headphones-symbolic",
"audio-card-analog-usb": "audio-speakers-symbolic",
"audio-card-analog-pci": "audio-card-symbolic",
"preferences-system": "emblem-system-symbolic",
"com.github.Aylur.ags-symbolic": "controls-symbolic",
"com.github.Aylur.ags": "controls-symbolic",
};
}

export default {
missing: "image-missing-symbolic",
Expand Down Expand Up @@ -143,4 +144,4 @@ export default {
dark: "dark-mode-symbolic",
light: "light-mode-symbolic",
},
};
}
22 changes: 16 additions & 6 deletions config/ags/lib/variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,30 @@ import GLib from "gi://GLib"
// const tempPath = options.system.temperature.value

export const clock = Variable(GLib.DateTime.new_now_local(), {
poll: [1000, () => GLib.DateTime.new_now_local()],
poll: [1000, () => GLib.DateTime.new_now_local()],
})

export const uptime = Variable(0, {
poll: [60_000, "cat /proc/uptime", line =>
Number.parseInt(line.split(".")[0]) / 60,
],
poll: [60_000, "cat /proc/uptime", (line) => Number.parseInt(line.split(".")[0]) / 60],
})

export const distro = {
id: GLib.get_os_info("ID"),
logo: GLib.get_os_info("LOGO"),
id: GLib.get_os_info("ID"),
logo: GLib.get_os_info("LOGO"),
}

export const df = Variable(0, {
poll: [
1000,
"/bin/df / --output=size,used",
(out) => {
out = out.trim().split("\n")[1]
const [total, used] = out.match(/\d+/g).map(Number)
return (used * 100.0) / total
},
],
})

// const divide = ([total, free]: string[]) => Number.parseInt(free) / Number.parseInt(total)
//
// export const cpu = Variable(0, {
Expand Down
1 change: 1 addition & 0 deletions config/ags/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const options = mkOptions(OPTIONS, {
"colorpicker",
"screenrecord",
"hyprshade",
"system-info",
"system",
"battery",
"powermenu",
Expand Down
18 changes: 18 additions & 0 deletions config/ags/style/widgets/bar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ $button-radius: $radius;
}
}

@keyframes error {
to {
background-color: $error-bg;
color: $error-fg;
}
}

.bar {
transition: $transition;
background-color: transparentize($bg, 0.5);
Expand Down Expand Up @@ -104,6 +111,17 @@ $button-radius: $radius;
margin: 0 ($spacing * 0.5);
}

.system-info > * {
animation-name: error;
animation-duration: 0.8s;
animation-timing-function: linear;
animation-iteration-count: infinite;
animation-direction: alternate;
label {
margin: 0 ($spacing * 0.5);
}
}

.taskbar .indicator.active {
background-color: $primary-bg;
border-radius: $radius;
Expand Down
2 changes: 2 additions & 0 deletions config/ags/widget/bar/Bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Workspaces from "./buttons/Workspaces"
import ScreenRecord from "./buttons/ScreenRecord"
import Messages from "./buttons/Messages"
import Hyprshade from "./buttons/Hyprshade"
import SystemInfo from "./buttons/SystemInfo"
import options from "options"

const { start, center, end } = options.bar.layout
Expand All @@ -32,6 +33,7 @@ const widget = {
screenrecord: ScreenRecord,
hyprshade: Hyprshade,
messages: Messages,
["system-info"]: SystemInfo,
expander: () => Widget.Box({ expand: true }),
}

Expand Down
16 changes: 16 additions & 0 deletions config/ags/widget/bar/buttons/SystemInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import PanelButton from "../PanelButton"
import { df } from "lib/variables"
import { icon } from "lib/utils"

export default () => {
return PanelButton({
class_name: "system-info",
visible: df.bind().as((c) => c > 80),
child: Widget.Box([
Widget.Icon({ icon: icon("drive-harddisk") }),
Widget.Label({
label: df.bind().as((c) => Math.round(c) + "%"),
}),
]),
})
}
3 changes: 1 addition & 2 deletions config/ags/widget/bar/buttons/Taskbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ const AppItem = (address: string) => {

const title = Utils.watch(client.title, hyprland, () => hyprland.getClient(address)?.title || "")

let icon_name = app?.icon_name ?? client.class
icon_name = icon_name === "quake" ? "org.wezfurlong.wezterm" : icon_name
const icon_name = app?.icon_name ?? client.class

const btn = PanelButton({
class_name: "panel-button",
Expand Down

0 comments on commit b6ab27f

Please sign in to comment.