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,43 +0,0 @@
const Action = (notif, notifs) => {
if (notif.actions !== undefined && notif.actions.length > 0) {
return Widget.Box({
class_name: "notification-card-actions",
hexpand: true,
vpack: "end",
children: notif.actions.map((action) => {
return Widget.Button({
hexpand: true,
class_name: "notification-action-buttons",
on_primary_click: () => {
if (action.id.includes("scriptAction:-")) {
Utils.execAsync(
`${action.id.replace("scriptAction:-", "")}`,
).catch((err) => console.error(err));
notifs.CloseNotification(notif.id);
} else {
notif.invoke(action.id);
}
},
child: Widget.Box({
hpack: "center",
hexpand: true,
children: [
Widget.Label({
class_name: "notification-action-buttons-label",
hexpand: true,
label: action.label,
max_width_chars: 15,
truncate: "end",
wrap: true,
}),
],
}),
});
}),
});
}
return Widget.Box();
};
export { Action };

View File

@@ -0,0 +1,45 @@
import { Notification, Notifications } from "types/service/notifications";
const Action = (notif: Notification, notifs: Notifications) => {
if (notif.actions !== undefined && notif.actions.length > 0) {
return Widget.Box({
class_name: "notification-card-actions",
hexpand: true,
vpack: "end",
children: notif.actions.map((action) => {
return Widget.Button({
hexpand: true,
class_name: "notification-action-buttons",
on_primary_click: () => {
if (action.id.includes("scriptAction:-")) {
Utils.execAsync(
`${action.id.replace("scriptAction:-", "")}`,
).catch((err) => console.error(err));
notifs.CloseNotification(notif.id);
} else {
notif.invoke(action.id);
}
},
child: Widget.Box({
hpack: "center",
hexpand: true,
children: [
Widget.Label({
class_name: "notification-action-buttons-label",
hexpand: true,
label: action.label,
max_width_chars: 15,
truncate: "end",
wrap: true,
}),
],
}),
});
}),
});
}
return Widget.Box();
};
export { Action };

View File

@@ -1,23 +0,0 @@
import { notifHasImg } from "../../menus/notifications/utils.js";
export const Body = (notif) => {
return Widget.Box({
vpack: "start",
hexpand: true,
class_name: "notification-card-body",
children: [
Widget.Label({
hexpand: true,
use_markup: true,
xalign: 0,
justification: "left",
truncate: "end",
lines: 2,
max_width_chars: !notifHasImg(notif) ? 35 : 28,
wrap: true,
class_name: "notification-card-body-label",
label: notif["body"],
}),
],
});
};

View File

@@ -0,0 +1,24 @@
import { Notification } from "types/service/notifications";
import { notifHasImg } from "../../menus/notifications/utils.js";
export const Body = (notif: Notification) => {
return Widget.Box({
vpack: "start",
hexpand: true,
class_name: "notification-card-body",
children: [
Widget.Label({
hexpand: true,
use_markup: true,
xalign: 0,
justification: "left",
truncate: "end",
lines: 2,
max_width_chars: !notifHasImg(notif) ? 35 : 28,
wrap: true,
class_name: "notification-card-body-label",
label: notif["body"],
}),
],
});
};

View File

@@ -1,12 +0,0 @@
export const CloseButton = (notif, notifs) => {
return Widget.Button({
class_name: "close-notification-button",
on_primary_click: () => {
notifs.CloseNotification(notif.id);
},
child: Widget.Label({
label: "󰅜",
hpack: "center",
}),
});
};

View File

@@ -0,0 +1,14 @@
import { Notification, Notifications } from "types/service/notifications";
export const CloseButton = (notif: Notification, notifs: Notifications) => {
return Widget.Button({
class_name: "close-notification-button",
on_primary_click: () => {
notifs.CloseNotification(notif.id);
},
child: Widget.Label({
label: "󰅜",
hpack: "center",
}),
});
};

View File

@@ -1,49 +0,0 @@
import GLib from "gi://GLib";
import { notifHasImg } from "../../menus/notifications/utils.js";
import { NotificationIcon } from "./icon.js";
const time = (time, format = "%I:%M %p") =>
GLib.DateTime.new_from_unix_local(time).format(format);
export const Header = (notif) => {
return Widget.Box({
vertical: false,
hexpand: true,
children: [
Widget.Box({
class_name: "notification-card-header",
hpack: "start",
children: [NotificationIcon(notif)],
}),
Widget.Box({
class_name: "notification-card-header",
hexpand: true,
hpack: "start",
vpack: "start",
children: [
Widget.Label({
class_name: "notification-card-header-label",
hpack: "start",
hexpand: true,
vexpand: true,
max_width_chars: !notifHasImg(notif) ? 30 : 19,
truncate: "end",
wrap: true,
label: notif["summary"],
}),
],
}),
Widget.Box({
class_name: "notification-card-header menu",
hpack: "end",
vpack: "start",
hexpand: true,
child: Widget.Label({
vexpand: true,
class_name: "notification-time",
label: time(notif.time),
}),
}),
],
});
};

View File

@@ -0,0 +1,50 @@
import GLib from "gi://GLib";
import { notifHasImg } from "../../menus/notifications/utils.js";
import { NotificationIcon } from "./icon.js";
import { Notification } from "types/service/notifications";
const time = (time: number, format = "%I:%M %p") =>
GLib.DateTime.new_from_unix_local(time).format(format);
export const Header = (notif: Notification) => {
return Widget.Box({
vertical: false,
hexpand: true,
children: [
Widget.Box({
class_name: "notification-card-header",
hpack: "start",
children: [NotificationIcon(notif)],
}),
Widget.Box({
class_name: "notification-card-header",
hexpand: true,
hpack: "start",
vpack: "start",
children: [
Widget.Label({
class_name: "notification-card-header-label",
hpack: "start",
hexpand: true,
vexpand: true,
max_width_chars: !notifHasImg(notif) ? 30 : 19,
truncate: "end",
wrap: true,
label: notif["summary"],
}),
],
}),
Widget.Box({
class_name: "notification-card-header menu",
hpack: "end",
vpack: "start",
hexpand: true,
child: Widget.Label({
vexpand: true,
class_name: "notification-time",
label: time(notif.time),
}),
}),
],
});
};

View File

@@ -1,22 +0,0 @@
import { notifHasImg } from "../../menus/notifications/utils.js";
const Image = (notif) => {
if (notifHasImg(notif)) {
return Widget.Box({
class_name: "notification-card-image-container",
hpack: "center",
vpack: "center",
vexpand: false,
child: Widget.Box({
hpack: "center",
vexpand: false,
class_name: "notification-card-image",
css: `background-image: url("${notif.image}")`,
}),
});
}
return Widget.Box();
};
export { Image };

View File

@@ -0,0 +1,23 @@
import { Notification } from "types/service/notifications";
import { notifHasImg } from "../../menus/notifications/utils.js";
const Image = (notif: Notification) => {
if (notifHasImg(notif)) {
return Widget.Box({
class_name: "notification-card-image-container",
hpack: "center",
vpack: "center",
vexpand: false,
child: Widget.Box({
hpack: "center",
vexpand: false,
class_name: "notification-card-image",
css: `background-image: url("${notif.image}")`,
}),
});
}
return Widget.Box();
};
export { Image };

View File

@@ -1,53 +0,0 @@
const notifs = await Service.import("notifications");
import options from "options";
import { notifHasImg } from "../menus/notifications/utils.js";
import { Image } from "./image/index.js";
import { Action } from "./actions/index.js";
import { Header } from "./header/index.js";
import { Body } from "./body/index.js";
import { CloseButton } from "./close/index.js";
const { position } = options.notifications;
export default () => {
notifs.popupTimeout = 7000;
const getPosition = (pos) => {
return pos.split(" ");
}
return Widget.Window({
name: "notifications-window",
class_name: "notifications-window",
monitor: 2,
layer: "top",
anchor: position.bind("value").as(v => getPosition(v)),
exclusivity: "ignore",
child: Widget.Box({
class_name: "notification-card-container",
vertical: true,
hexpand: true,
setup: (self) => {
self.hook(notifs, () => {
return (self.children = notifs.popups.map((notif) => {
return Widget.Box({
class_name: "notification-card",
vpack: "start",
hexpand: true,
children: [
Image(notif),
Widget.Box({
vpack: "start",
vertical: true,
hexpand: true,
class_name: `notification-card-content ${!notifHasImg(notif) ? "noimg" : ""}`,
children: [Header(notif), Body(notif), Action(notif, notifs)],
}),
CloseButton(notif, notifs),
],
});
}));
});
},
}),
});
};

View File

@@ -0,0 +1,63 @@
const notifs = await Service.import("notifications");
import options from "options";
import { notifHasImg } from "../menus/notifications/utils.js";
import { Image } from "./image/index.js";
import { Action } from "./actions/index.js";
import { Header } from "./header/index.js";
import { Body } from "./body/index.js";
import { CloseButton } from "./close/index.js";
import { NotificationAnchor } from "lib/types/options";
const { position } = options.notifications;
export default () => {
notifs.popupTimeout = 7000;
const getPosition = (pos: NotificationAnchor): ("top" | "bottom" | "left" | "right")[] => {
const positionMap: { [key: string]: ("top" | "bottom" | "left" | "right")[] } = {
"top": ["top"],
"top right": ["top", "right"],
"top left": ["top", "left"],
"bottom": ["bottom"],
"bottom right": ["bottom", "right"],
"bottom left": ["bottom", "left"]
};
return positionMap[pos] || ["top"];
}
return Widget.Window({
name: "notifications-window",
class_name: "notifications-window",
monitor: 2,
layer: "top",
anchor: position.bind("value").as(v => getPosition(v)),
exclusivity: "ignore",
child: Widget.Box({
class_name: "notification-card-container",
vertical: true,
hexpand: true,
setup: (self) => {
self.hook(notifs, () => {
return (self.children = notifs.popups.map((notif) => {
return Widget.Box({
class_name: "notification-card",
vpack: "start",
hexpand: true,
children: [
Image(notif),
Widget.Box({
vpack: "start",
vertical: true,
hexpand: true,
class_name: `notification-card-content ${!notifHasImg(notif) ? "noimg" : ""}`,
children: [Header(notif), Body(notif), Action(notif, notifs)],
}),
CloseButton(notif, notifs),
],
});
}));
});
},
}),
});
};