Convert all remaining files to typescript.

This commit is contained in:
Jas Singh
2024-07-26 23:11:33 -07:00
parent ca5dcc629b
commit b511d76e11
84 changed files with 2075 additions and 1987 deletions

View File

@@ -1,67 +0,0 @@
const media = await Service.import("mpris");
const Bar = (getPlayerInfo) => {
return Widget.Box({
class_name: "media-indicator-current-progress-bar",
hexpand: true,
children: [
Widget.Box({
hexpand: true,
child: Widget.Slider({
hexpand: true,
tooltip_text: "--",
class_name: "menu-slider media progress",
draw_value: false,
on_change: ({ value }) => {
const foundPlayer = getPlayerInfo(media);
if (foundPlayer === undefined) {
return;
}
return (foundPlayer.position = value * foundPlayer.length);
},
setup: (self) => {
const update = () => {
const foundPlayer = getPlayerInfo(media);
if (foundPlayer !== undefined) {
const value = foundPlayer.position / foundPlayer.length;
self.value = value > 0 ? value : 0;
} else {
self.value = 0;
}
};
self.hook(media, update);
self.poll(1000, update);
function updateTooltip() {
const foundPlayer = getPlayerInfo(media);
if (foundPlayer === undefined) {
return self.tooltip_text = '00:00'
}
const curHour = Math.floor(foundPlayer.position / 3600);
const curMin = Math.floor((foundPlayer.position % 3600) / 60);
const curSec = Math.floor(foundPlayer.position % 60);
if (
typeof foundPlayer.position === "number" &&
foundPlayer.position >= 0
) {
// WARN: These nested ternaries are absolutely disgusting lol
self.tooltip_text = `${
curHour > 0
? (curHour < 10 ? "0" + curHour : curHour) + ":"
: ""
}${curMin < 10 ? "0" + curMin : curMin}:${curSec < 10 ? "0" + curSec : curSec}`;
} else {
self.tooltip_text = `00:00`;
}
}
self.poll(1000, updateTooltip);
self.hook(media, updateTooltip);
},
}),
}),
],
});
};
export { Bar };

View File

@@ -0,0 +1,66 @@
const media = await Service.import("mpris");
const Bar = (getPlayerInfo: Function) => {
return Widget.Box({
class_name: "media-indicator-current-progress-bar",
hexpand: true,
children: [
Widget.Box({
hexpand: true,
child: Widget.Slider({
hexpand: true,
tooltip_text: "--",
class_name: "menu-slider media progress",
draw_value: false,
on_change: ({ value }) => {
const foundPlayer = getPlayerInfo(media);
if (foundPlayer === undefined) {
return;
}
return (foundPlayer.position = value * foundPlayer.length);
},
setup: (self) => {
const update = () => {
const foundPlayer = getPlayerInfo(media);
if (foundPlayer !== undefined) {
const value = foundPlayer.position / foundPlayer.length;
self.value = value > 0 ? value : 0;
} else {
self.value = 0;
}
};
self.hook(media, update);
self.poll(1000, update);
function updateTooltip() {
const foundPlayer = getPlayerInfo(media);
if (foundPlayer === undefined) {
return self.tooltip_text = '00:00'
}
const curHour = Math.floor(foundPlayer.position / 3600);
const curMin = Math.floor((foundPlayer.position % 3600) / 60);
const curSec = Math.floor(foundPlayer.position % 60);
if (
typeof foundPlayer.position === "number" &&
foundPlayer.position >= 0
) {
// WARN: These nested ternaries are absolutely disgusting lol
self.tooltip_text = `${curHour > 0
? (curHour < 10 ? "0" + curHour : curHour) + ":"
: ""
}${curMin < 10 ? "0" + curMin : curMin}:${curSec < 10 ? "0" + curSec : curSec}`;
} else {
self.tooltip_text = `00:00`;
}
}
self.poll(1000, updateTooltip);
self.hook(media, updateTooltip);
},
}),
}),
],
});
};
export { Bar };

View File

@@ -1,187 +0,0 @@
import icons from "../../../icons/index.js";
const media = await Service.import("mpris");
const Controls = (getPlayerInfo) => {
const isLoopActive = (player) => {
return player["loop-status"] !== null &&
["track", "playlist"].includes(player["loop-status"].toLowerCase())
? "active"
: "";
};
const isShuffleActive = (player) => {
return player["shuffle-status"] !== null && player["shuffle-status"]
? "active"
: "";
};
return Widget.Box({
class_name: "media-indicator-current-player-controls",
vertical: true,
children: [
Widget.Box({
class_name: "media-indicator-current-controls",
hpack: "center",
children: [
Widget.Box({
class_name: "media-indicator-control shuffle",
children: [
Widget.Button({
hpack: "center",
hasTooltip: true,
setup: (self) => {
self.hook(media, () => {
const foundPlayer = getPlayerInfo();
if (foundPlayer === undefined) {
self.tooltip_text = "Unavailable";
self.class_name =
"media-indicator-control-button shuffle disabled";
return;
}
self.tooltip_text =
foundPlayer.shuffle_status !== null
? foundPlayer.shuffle_status
? "Shuffling"
: "Not Shuffling"
: null;
self.on_primary_click = () => foundPlayer.shuffle();
self.class_name = `media-indicator-control-button shuffle ${isShuffleActive(foundPlayer)} ${foundPlayer.shuffle_status !== null ? "enabled" : "disabled"}`;
});
},
child: Widget.Icon(icons.mpris.shuffle["enabled"]),
}),
],
}),
Widget.Box({
children: [
Widget.Button({
hpack: "center",
child: Widget.Icon(icons.mpris.prev),
setup: (self) => {
self.hook(media, () => {
const foundPlayer = getPlayerInfo();
if (foundPlayer === undefined) {
self.class_name =
"media-indicator-control-button prev disabled";
return;
}
self.on_primary_click = () => foundPlayer.previous();
self.class_name = `media-indicator-control-button prev ${foundPlayer.can_go_prev !== null && foundPlayer.can_go_prev ? "enabled" : "disabled"}`;
});
},
}),
],
}),
Widget.Box({
children: [
Widget.Button({
hpack: "center",
setup: (self) => {
self.hook(media, () => {
const foundPlayer = getPlayerInfo();
if (foundPlayer === undefined) {
self.class_name =
"media-indicator-control-button play disabled";
return;
}
self.on_primary_click = () => foundPlayer.playPause();
self.class_name = `media-indicator-control-button play ${foundPlayer.can_play !== null ? "enabled" : "disabled"}`;
});
},
child: Widget.Icon({
icon: Utils.watch(
icons.mpris.paused,
media,
"changed",
() => {
const foundPlayer = getPlayerInfo();
if (foundPlayer === undefined) {
return icons.mpris["paused"];
}
return icons.mpris[
foundPlayer.play_back_status.toLowerCase()
];
},
),
}),
}),
],
}),
Widget.Box({
class_name: `media-indicator-control next`,
children: [
Widget.Button({
hpack: "center",
child: Widget.Icon(icons.mpris.next),
setup: (self) => {
self.hook(media, () => {
const foundPlayer = getPlayerInfo();
if (foundPlayer === undefined) {
self.class_name =
"media-indicator-control-button next disabled";
return;
}
self.on_primary_click = () => foundPlayer.next();
self.class_name = `media-indicator-control-button next ${foundPlayer.can_go_next !== null && foundPlayer.can_go_next ? "enabled" : "disabled"}`;
});
},
}),
],
}),
Widget.Box({
class_name: "media-indicator-control loop",
children: [
Widget.Button({
hpack: "center",
setup: (self) => {
self.hook(media, () => {
const foundPlayer = getPlayerInfo();
if (foundPlayer === undefined) {
self.tooltip_text = "Unavailable";
self.class_name =
"media-indicator-control-button shuffle disabled";
return;
}
self.tooltip_text =
foundPlayer.loop_status !== null
? foundPlayer.loop_status
? "Shuffling"
: "Not Shuffling"
: null;
self.on_primary_click = () => foundPlayer.loop();
self.class_name = `media-indicator-control-button loop ${isLoopActive(foundPlayer)} ${foundPlayer.loop_status !== null ? "enabled" : "disabled"}`;
});
},
child: Widget.Icon({
setup: (self) => {
self.hook(media, () => {
const foundPlayer = getPlayerInfo();
if (foundPlayer === undefined) {
self.icon = icons.mpris.loop["none"];
return;
}
self.icon =
foundPlayer.loop_status === null
? icons.mpris.loop["none"]
: icons.mpris.loop[
foundPlayer.loop_status?.toLowerCase()
];
});
},
}),
}),
],
}),
],
}),
],
});
};
export { Controls };

View File

@@ -0,0 +1,188 @@
import { MprisPlayer } from "types/service/mpris.js";
import icons from "../../../icons/index.js";
const media = await Service.import("mpris");
const Controls = (getPlayerInfo: Function) => {
const isLoopActive = (player: MprisPlayer) => {
return player["loop-status"] !== null &&
["track", "playlist"].includes(player["loop-status"].toLowerCase())
? "active"
: "";
};
const isShuffleActive = (player: MprisPlayer) => {
return player["shuffle-status"] !== null && player["shuffle-status"]
? "active"
: "";
};
return Widget.Box({
class_name: "media-indicator-current-player-controls",
vertical: true,
children: [
Widget.Box({
class_name: "media-indicator-current-controls",
hpack: "center",
children: [
Widget.Box({
class_name: "media-indicator-control shuffle",
children: [
Widget.Button({
hpack: "center",
hasTooltip: true,
setup: (self) => {
self.hook(media, () => {
const foundPlayer = getPlayerInfo();
if (foundPlayer === undefined) {
self.tooltip_text = "Unavailable";
self.class_name =
"media-indicator-control-button shuffle disabled";
return;
}
self.tooltip_text =
foundPlayer.shuffle_status !== null
? foundPlayer.shuffle_status
? "Shuffling"
: "Not Shuffling"
: null;
self.on_primary_click = () => foundPlayer.shuffle();
self.class_name = `media-indicator-control-button shuffle ${isShuffleActive(foundPlayer)} ${foundPlayer.shuffle_status !== null ? "enabled" : "disabled"}`;
});
},
child: Widget.Icon(icons.mpris.shuffle["enabled"]),
}),
],
}),
Widget.Box({
children: [
Widget.Button({
hpack: "center",
child: Widget.Icon(icons.mpris.prev),
setup: (self) => {
self.hook(media, () => {
const foundPlayer = getPlayerInfo();
if (foundPlayer === undefined) {
self.class_name =
"media-indicator-control-button prev disabled";
return;
}
self.on_primary_click = () => foundPlayer.previous();
self.class_name = `media-indicator-control-button prev ${foundPlayer.can_go_prev !== null && foundPlayer.can_go_prev ? "enabled" : "disabled"}`;
});
},
}),
],
}),
Widget.Box({
children: [
Widget.Button({
hpack: "center",
setup: (self) => {
self.hook(media, () => {
const foundPlayer = getPlayerInfo();
if (foundPlayer === undefined) {
self.class_name =
"media-indicator-control-button play disabled";
return;
}
self.on_primary_click = () => foundPlayer.playPause();
self.class_name = `media-indicator-control-button play ${foundPlayer.can_play !== null ? "enabled" : "disabled"}`;
});
},
child: Widget.Icon({
icon: Utils.watch(
icons.mpris.paused,
media,
"changed",
() => {
const foundPlayer = getPlayerInfo();
if (foundPlayer === undefined) {
return icons.mpris["paused"];
}
return icons.mpris[
foundPlayer.play_back_status.toLowerCase()
];
},
),
}),
}),
],
}),
Widget.Box({
class_name: `media-indicator-control next`,
children: [
Widget.Button({
hpack: "center",
child: Widget.Icon(icons.mpris.next),
setup: (self) => {
self.hook(media, () => {
const foundPlayer = getPlayerInfo();
if (foundPlayer === undefined) {
self.class_name =
"media-indicator-control-button next disabled";
return;
}
self.on_primary_click = () => foundPlayer.next();
self.class_name = `media-indicator-control-button next ${foundPlayer.can_go_next !== null && foundPlayer.can_go_next ? "enabled" : "disabled"}`;
});
},
}),
],
}),
Widget.Box({
class_name: "media-indicator-control loop",
children: [
Widget.Button({
hpack: "center",
setup: (self) => {
self.hook(media, () => {
const foundPlayer = getPlayerInfo();
if (foundPlayer === undefined) {
self.tooltip_text = "Unavailable";
self.class_name =
"media-indicator-control-button shuffle disabled";
return;
}
self.tooltip_text =
foundPlayer.loop_status !== null
? foundPlayer.loop_status
? "Shuffling"
: "Not Shuffling"
: null;
self.on_primary_click = () => foundPlayer.loop();
self.class_name = `media-indicator-control-button loop ${isLoopActive(foundPlayer)} ${foundPlayer.loop_status !== null ? "enabled" : "disabled"}`;
});
},
child: Widget.Icon({
setup: (self) => {
self.hook(media, () => {
const foundPlayer = getPlayerInfo();
if (foundPlayer === undefined) {
self.icon = icons.mpris.loop["none"];
return;
}
self.icon =
foundPlayer.loop_status === null
? icons.mpris.loop["none"]
: icons.mpris.loop[
foundPlayer.loop_status?.toLowerCase()
];
});
},
}),
}),
],
}),
],
}),
],
});
};
export { Controls };

View File

@@ -1,85 +0,0 @@
const media = await Service.import("mpris");
const MediaInfo = (getPlayerInfo) => {
return Widget.Box({
class_name: "media-indicator-current-media-info",
hpack: "center",
hexpand: true,
vertical: true,
children: [
Widget.Box({
class_name: "media-indicator-current-song-name",
hpack: "center",
children: [
Widget.Label({
truncate: "end",
max_width_chars: 31,
wrap: true,
class_name: "media-indicator-current-song-name-label",
setup: (self) => {
self.hook(media, () => {
const curPlayer = getPlayerInfo();
return (self.label =
curPlayer !== undefined && curPlayer["track-title"].length
? curPlayer["track-title"]
: "No Media Currently Playing");
});
},
}),
],
}),
Widget.Box({
class_name: "media-indicator-current-song-author",
hpack: "center",
children: [
Widget.Label({
truncate: "end",
wrap: true,
max_width_chars: 35,
class_name: "media-indicator-current-song-author-label",
setup: (self) => {
self.hook(media, () => {
const curPlayer = getPlayerInfo();
const makeArtistList = (trackArtists) => {
if (trackArtists.length === 1 && !trackArtists[0].length) {
return "-----";
}
return trackArtists.join(", ");
};
return (self.label =
curPlayer !== undefined && curPlayer["track-artists"].length
? makeArtistList(curPlayer["track-artists"])
: "-----");
});
},
}),
],
}),
Widget.Box({
class_name: "media-indicator-current-song-album",
hpack: "center",
children: [
Widget.Label({
truncate: "end",
wrap: true,
max_width_chars: 40,
class_name: "media-indicator-current-song-album-label",
setup: (self) => {
self.hook(media, () => {
const curPlayer = getPlayerInfo();
return (self.label =
curPlayer !== undefined && curPlayer["track-album"].length
? curPlayer["track-album"]
: "---");
});
},
}),
],
}),
],
});
};
export { MediaInfo };

View File

@@ -0,0 +1,85 @@
const media = await Service.import("mpris");
const MediaInfo = (getPlayerInfo: Function) => {
return Widget.Box({
class_name: "media-indicator-current-media-info",
hpack: "center",
hexpand: true,
vertical: true,
children: [
Widget.Box({
class_name: "media-indicator-current-song-name",
hpack: "center",
children: [
Widget.Label({
truncate: "end",
max_width_chars: 31,
wrap: true,
class_name: "media-indicator-current-song-name-label",
setup: (self) => {
self.hook(media, () => {
const curPlayer = getPlayerInfo();
return (self.label =
curPlayer !== undefined && curPlayer["track-title"].length
? curPlayer["track-title"]
: "No Media Currently Playing");
});
},
}),
],
}),
Widget.Box({
class_name: "media-indicator-current-song-author",
hpack: "center",
children: [
Widget.Label({
truncate: "end",
wrap: true,
max_width_chars: 35,
class_name: "media-indicator-current-song-author-label",
setup: (self) => {
self.hook(media, () => {
const curPlayer = getPlayerInfo();
const makeArtistList = (trackArtists: string[]) => {
if (trackArtists.length === 1 && !trackArtists[0].length) {
return "-----";
}
return trackArtists.join(", ");
};
return (self.label =
curPlayer !== undefined && curPlayer["track-artists"].length
? makeArtistList(curPlayer["track-artists"])
: "-----");
});
},
}),
],
}),
Widget.Box({
class_name: "media-indicator-current-song-album",
hpack: "center",
children: [
Widget.Label({
truncate: "end",
wrap: true,
max_width_chars: 40,
class_name: "media-indicator-current-song-album-label",
setup: (self) => {
self.hook(media, () => {
const curPlayer = getPlayerInfo();
return (self.label =
curPlayer !== undefined && curPlayer["track-album"].length
? curPlayer["track-album"]
: "---");
});
},
}),
],
}),
],
});
};
export { MediaInfo };

View File

@@ -1,75 +0,0 @@
const media = await Service.import("mpris");
import { MediaInfo } from "./components/mediainfo.js";
import { Controls } from "./components/controls.js";
import { Bar } from "./components/bar.js";
const Media = () => {
const curPlayer = Variable("");
media.connect("changed", () => {
const statusOrder = {
Playing: 1,
Paused: 2,
Stopped: 3,
};
const isPlaying = media.players.find(
(p) => p["play-back-status"] === "Playing",
);
if (isPlaying) {
curPlayer.value = media.players.sort(
(a, b) =>
statusOrder[a["play-back-status"]] -
statusOrder[b["play-back-status"]],
)[0].name;
}
});
const getPlayerInfo = () => {
return media.players.find((p) => p.name === curPlayer.value);
};
return Widget.Box({
class_name: "menu-section-container",
children: [
Widget.Box({
class_name: "menu-items-section",
vertical: false,
child: Widget.Box({
class_name: "menu-content",
children: [
Widget.Box({
class_name: "media-content",
child: Widget.Box({
class_name: "media-indicator-right-section",
hpack: "fill",
hexpand: true,
vertical: true,
children: [
MediaInfo(getPlayerInfo),
Controls(getPlayerInfo),
Bar(getPlayerInfo),
],
}),
}),
],
setup: (self) => {
self.hook(media, () => {
const curPlayer = getPlayerInfo();
if (curPlayer !== undefined) {
self.css = `background-image: linear-gradient(
rgba(30, 30, 46, 0.85),
rgba(30, 30, 46, 0.9),
#1e1e2e 40em), url("${curPlayer.track_cover_url}");
`;
}
});
},
}),
}),
],
});
};
export { Media };

View File

@@ -0,0 +1,76 @@
const media = await Service.import("mpris");
import { MediaInfo } from "./components/mediainfo.js";
import { Controls } from "./components/controls.js";
import { Bar } from "./components/bar.js";
import { MprisPlayer } from "types/service/mpris.js";
const Media = () => {
const curPlayer = Variable("");
media.connect("changed", () => {
const statusOrder = {
Playing: 1,
Paused: 2,
Stopped: 3,
};
const isPlaying = media.players.find(
(p) => p["play-back-status"] === "Playing",
);
if (isPlaying) {
curPlayer.value = media.players.sort(
(a, b) =>
statusOrder[a["play-back-status"]] -
statusOrder[b["play-back-status"]],
)[0].name;
}
});
const getPlayerInfo = (): MprisPlayer => {
return media.players.find((p) => p.name === curPlayer.value) || media.players[0];
};
return Widget.Box({
class_name: "menu-section-container",
children: [
Widget.Box({
class_name: "menu-items-section",
vertical: false,
child: Widget.Box({
class_name: "menu-content",
children: [
Widget.Box({
class_name: "media-content",
child: Widget.Box({
class_name: "media-indicator-right-section",
hpack: "fill",
hexpand: true,
vertical: true,
children: [
MediaInfo(getPlayerInfo),
Controls(getPlayerInfo),
Bar(getPlayerInfo),
],
}),
}),
],
setup: (self) => {
self.hook(media, () => {
const curPlayer = getPlayerInfo();
if (curPlayer !== undefined) {
self.css = `background-image: linear-gradient(
rgba(30, 30, 46, 0.85),
rgba(30, 30, 46, 0.9),
#1e1e2e 40em), url("${curPlayer.track_cover_url}");
`;
}
});
},
}),
}),
],
});
};
export { Media };