home/natto/ags: init
Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
This commit is contained in:
42
home/natto/ags/utils/music.js
Normal file
42
home/natto/ags/utils/music.js
Normal file
@@ -0,0 +1,42 @@
|
||||
import GLib from "gi://GLib";
|
||||
|
||||
export const lengthStr = (length) => {
|
||||
if (length < 0) return "0:00";
|
||||
|
||||
const min = Math.floor(length / 60);
|
||||
const sec = Math.floor(length % 60);
|
||||
const sec0 = sec < 10 ? "0" : "";
|
||||
return `${min}:${sec0}${sec}`;
|
||||
};
|
||||
|
||||
export const blurBg = (cover) => {
|
||||
if (!cover) return "";
|
||||
|
||||
const cachePath = Utils.CACHE_DIR + "/media";
|
||||
const blurPath = cachePath + "/blur";
|
||||
const bgPath = blurPath + cover.substring(cachePath.length);
|
||||
|
||||
if (!GLib.file_test(bgPath, GLib.FileTest.EXISTS)) {
|
||||
Utils.ensureDirectory(blurPath);
|
||||
Utils.exec(
|
||||
`convert ${cover} -scale 10% -blur 0x2 -resize 1000% ${bgPath}`,
|
||||
);
|
||||
}
|
||||
|
||||
return `
|
||||
background-image: url('${bgPath}');
|
||||
background-repeat: no-repeat;
|
||||
background-position: center;
|
||||
background-size: cover;
|
||||
`;
|
||||
};
|
||||
|
||||
export const findPlayer = (players) => {
|
||||
const active = players.find((p) => p.playBackStatus === "Playing");
|
||||
|
||||
if (active) return active;
|
||||
|
||||
for (const p of players) if (p) return p;
|
||||
|
||||
return undefined;
|
||||
};
|
||||
41
home/natto/ags/utils/popup.js
Normal file
41
home/natto/ags/utils/popup.js
Normal file
@@ -0,0 +1,41 @@
|
||||
export const Padding = (name, { hexpand = true, vexpand = true } = {}) =>
|
||||
Widget.EventBox({
|
||||
hexpand,
|
||||
vexpand,
|
||||
can_focus: false,
|
||||
setup: (w) => w.on("button-press-event", () => App.closeWindow(name)),
|
||||
});
|
||||
|
||||
export const Revealer = ({
|
||||
name,
|
||||
child,
|
||||
transition = "slide_down",
|
||||
transitionDuration = 200,
|
||||
}) =>
|
||||
Widget.Box({
|
||||
css: "padding: 1px;",
|
||||
child: Widget.Revealer({
|
||||
transition,
|
||||
transitionDuration,
|
||||
child: Widget.Box({
|
||||
child,
|
||||
}),
|
||||
setup: (self) =>
|
||||
self.hook(App, (_, window, visible) => {
|
||||
if (window === name) self.reveal_child = visible;
|
||||
}),
|
||||
}),
|
||||
});
|
||||
|
||||
export default ({ name, layout, ...props }) =>
|
||||
Widget.Window({
|
||||
name,
|
||||
setup: (w) => w.keybind("Escape", () => App.closeWindow(name)),
|
||||
visible: false,
|
||||
keymode: "on-demand",
|
||||
exclusivity: "normal",
|
||||
layer: "top",
|
||||
anchor: ["top", "bottom", "right", "left"],
|
||||
child: layout,
|
||||
...props,
|
||||
});
|
||||
5
home/natto/ags/utils/text.js
Normal file
5
home/natto/ags/utils/text.js
Normal file
@@ -0,0 +1,5 @@
|
||||
export const shrinkText = (str, n) => {
|
||||
let newStr = str.substring(0, n);
|
||||
if (str.length > n) newStr = newStr + "...";
|
||||
return newStr;
|
||||
};
|
||||
Reference in New Issue
Block a user