update ags
This commit is contained in:
1 parent
88822cb8e8
commit
a9c19bd2e1
134 files changed
+4732
-5813
No files matched your search
@@ -1,71 +0,0 @@
|
||||
import { bash, sh } from "../functions/utils.js";
|
||||
|
||||
const get = (args) => Number(Utils.exec(`brightnessctl ${args}`));
|
||||
const screen = await bash`ls -w1 /sys/class/backlight | head -1`;
|
||||
const kbd = await bash`ls -w1 /sys/class/leds | head -1`;
|
||||
|
||||
class Brightness extends Service {
|
||||
static {
|
||||
Service.register(
|
||||
this,
|
||||
{},
|
||||
{
|
||||
screen: ["float", "rw"],
|
||||
kbd: ["int", "rw"],
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
#kbdMax = get(`--device ${kbd} max`);
|
||||
#kbd = get(`--device ${kbd} get`);
|
||||
#screenMax = get("max");
|
||||
#screen = get("get") / get("max");
|
||||
|
||||
get kbd() {
|
||||
return this.#kbd;
|
||||
}
|
||||
get screen() {
|
||||
return this.#screen;
|
||||
}
|
||||
|
||||
set kbd(value) {
|
||||
if (value < 0 || value > this.#kbdMax) return;
|
||||
|
||||
sh(`brightnessctl -d ${kbd} s ${value} -q`).then(() => {
|
||||
this.#kbd = value;
|
||||
this.changed("kbd");
|
||||
});
|
||||
}
|
||||
|
||||
set screen(percent) {
|
||||
if (percent < 0) percent = 0;
|
||||
|
||||
if (percent > 1) percent = 1;
|
||||
|
||||
sh(`brightnessctl set ${Math.floor(percent * 100)}% -q`).then(() => {
|
||||
this.#screen = percent;
|
||||
this.changed("screen");
|
||||
});
|
||||
}
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
const screenPath = `/sys/class/backlight/${screen}/brightness`;
|
||||
const kbdPath = `/sys/class/leds/${kbd}/brightness`;
|
||||
|
||||
Utils.monitorFile(screenPath, async (f) => {
|
||||
const v = await Utils.readFileAsync(f);
|
||||
this.#screen = Number(v) / this.#screenMax;
|
||||
this.changed("screen");
|
||||
});
|
||||
|
||||
Utils.monitorFile(kbdPath, async (f) => {
|
||||
const v = await Utils.readFileAsync(f);
|
||||
this.#kbd = Number(v) / this.#kbdMax;
|
||||
this.changed("kbd");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default new Brightness();
|
||||
@@ -1,79 +0,0 @@
|
||||
// @ts-nocheck
|
||||
import { Variable as Var } from "resource:///com/github/Aylur/ags/variable.js";
|
||||
import { deepMerge } from "../functions/utils.js";
|
||||
import { replacePlaceholders, reverseReplace } from "../functions/utils.js";
|
||||
export const configPath = App.configDir + "/config.json";
|
||||
|
||||
class Conf extends Var {
|
||||
static {
|
||||
Service.register(this);
|
||||
}
|
||||
|
||||
constructor(key, callback = () => null, replaceData = {}) {
|
||||
super("");
|
||||
const config = JSON.parse(Utils.readFile(configPath) || "{}");
|
||||
this.key = key;
|
||||
this.replaceData = replaceData;
|
||||
this.setValue(
|
||||
replacePlaceholders(
|
||||
this.key.includes(".")
|
||||
? this.#accessNestedJson(config, this.key)
|
||||
: config[this.key],
|
||||
this.replaceData,
|
||||
),
|
||||
);
|
||||
this.connect("changed", callback);
|
||||
}
|
||||
|
||||
key = "";
|
||||
replaceData = {};
|
||||
|
||||
#accessNestedJson(data, keys) {
|
||||
const keysArray = keys.split(".");
|
||||
let result = data;
|
||||
for (const key of keysArray) {
|
||||
if (key in result) {
|
||||
result = result[key];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#createNestedJson(key, newvalue) {
|
||||
const keysarray = key.split(".");
|
||||
let result = {};
|
||||
let temp = result;
|
||||
for (let i = 0; i < keysarray.length - 1; i++) {
|
||||
temp[keysarray[i]] = {};
|
||||
temp = temp[keysarray[i]];
|
||||
}
|
||||
temp[keysarray[keysarray.length - 1]] = newvalue;
|
||||
return result;
|
||||
}
|
||||
|
||||
updateValue(value) {
|
||||
super.setValue(value);
|
||||
let json = {};
|
||||
if (!this.key.includes(".")) {
|
||||
json[this.key] = value;
|
||||
} else {
|
||||
json = this.#createNestedJson(
|
||||
this.key,
|
||||
reverseReplace(value, this.replaceData),
|
||||
);
|
||||
}
|
||||
this.#setConfig(json);
|
||||
}
|
||||
|
||||
#setConfig(value) {
|
||||
const configs = JSON.parse(Utils.readFile(configPath) || "{}");
|
||||
|
||||
const updatedConfig = deepMerge(configs, value);
|
||||
const configString = JSON.stringify(updatedConfig, null, 2); // this.#betterStringify(updatedConfig);
|
||||
Utils.writeFile(configString, configPath);
|
||||
}
|
||||
}
|
||||
|
||||
export default (keyz, call, replace) => new Conf(keyz, call, replace);
|
||||
@@ -1,108 +0,0 @@
|
||||
class NetworkSpeedService extends Service {
|
||||
static {
|
||||
Service.register(
|
||||
this,
|
||||
{
|
||||
"upload-updated": ["float"],
|
||||
"download-updated": ["float"],
|
||||
},
|
||||
{
|
||||
"upload-speed": ["float", "r"],
|
||||
"download-speed": ["float", "r"],
|
||||
interval: ["float", "rw"],
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
#interval = 1000;
|
||||
#lastTotalDownBytes = 0;
|
||||
#lastTotalUpBytes = 0;
|
||||
#downloadSpeed = 0;
|
||||
#uploadSpeed = 0;
|
||||
|
||||
get interval() {
|
||||
return this.#interval;
|
||||
}
|
||||
|
||||
set interval(value) {
|
||||
this.#interval = value;
|
||||
}
|
||||
|
||||
get download_speed() {
|
||||
return this.#downloadSpeed;
|
||||
}
|
||||
|
||||
get upload_speed() {
|
||||
return this.#uploadSpeed;
|
||||
}
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.#onChange();
|
||||
}
|
||||
|
||||
#onChange() {
|
||||
Utils.interval(this.#interval, () => {
|
||||
const content = Utils.exec("cat /proc/net/dev");
|
||||
const lines = content.split("\n");
|
||||
|
||||
// Caculate the sum of all interfaces' traffic line by line.
|
||||
let totalDownBytes = 0;
|
||||
let totalUpBytes = 0;
|
||||
|
||||
for (let i = 0; i < lines.length; ++i) {
|
||||
const fields = lines[i].trim().split(/\W+/);
|
||||
if (fields.length <= 2) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip virtual interfaces.
|
||||
const interfce = fields[0];
|
||||
const currentInterfaceDownBytes = Number.parseInt(fields[1]);
|
||||
const currentInterfaceUpBytes = Number.parseInt(fields[9]);
|
||||
if (
|
||||
interfce === "lo" ||
|
||||
// Created by python-based bandwidth manager "traffictoll".
|
||||
interfce.match(/^ifb[0-9]+/) ||
|
||||
// Created by lxd container manager.
|
||||
interfce.match(/^lxdbr[0-9]+/) ||
|
||||
interfce.match(/^virbr[0-9]+/) ||
|
||||
interfce.match(/^br[0-9]+/) ||
|
||||
interfce.match(/^vnet[0-9]+/) ||
|
||||
interfce.match(/^tun[0-9]+/) ||
|
||||
interfce.match(/^tap[0-9]+/) ||
|
||||
isNaN(currentInterfaceDownBytes) ||
|
||||
isNaN(currentInterfaceUpBytes)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
totalDownBytes += currentInterfaceDownBytes;
|
||||
totalUpBytes += currentInterfaceUpBytes;
|
||||
}
|
||||
|
||||
if (this.#lastTotalDownBytes === 0) {
|
||||
this.#lastTotalDownBytes = totalDownBytes;
|
||||
}
|
||||
if (this.#lastTotalUpBytes === 0) {
|
||||
this.#lastTotalUpBytes = totalUpBytes;
|
||||
}
|
||||
this.#downloadSpeed =
|
||||
(totalDownBytes - this.#lastTotalDownBytes) / this.#interval;
|
||||
this.#uploadSpeed =
|
||||
(totalUpBytes - this.#lastTotalUpBytes) / this.#interval;
|
||||
this.emit("changed");
|
||||
this.notify("download-speed");
|
||||
this.notify("upload-speed");
|
||||
this.emit("upload-updated", this.#uploadSpeed);
|
||||
this.emit("download-updated", this.#downloadSpeed);
|
||||
|
||||
this.#lastTotalDownBytes = totalDownBytes;
|
||||
this.#lastTotalUpBytes = totalUpBytes;
|
||||
});
|
||||
}
|
||||
}
|
||||
const service = new NetworkSpeedService();
|
||||
|
||||
export default service;
|
||||
@@ -1,54 +0,0 @@
|
||||
const options = {
|
||||
lock: "hyprlock",
|
||||
sleep: "systemctl suspend",
|
||||
reboot: "systemctl reboot",
|
||||
logout: "pkill -u user",
|
||||
shutdown: "shutdown now",
|
||||
};
|
||||
|
||||
class PowerMenu extends Service {
|
||||
static {
|
||||
Service.register(
|
||||
this,
|
||||
{},
|
||||
{
|
||||
title: ["string"],
|
||||
cmd: ["string"],
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
#title = "";
|
||||
#cmd = "";
|
||||
|
||||
get title() {
|
||||
return this.#title;
|
||||
}
|
||||
|
||||
get cmd() {
|
||||
return this.#cmd;
|
||||
}
|
||||
|
||||
action(action) {
|
||||
[this.#cmd, this.#title] = {
|
||||
lock: [options.lock, "Lock"],
|
||||
sleep: [options.sleep, "Sleep"],
|
||||
reboot: [options.reboot, "Reboot"],
|
||||
logout: [options.logout, "Log Out"],
|
||||
shutdown: [options.shutdown, "Shutdown"],
|
||||
}[action];
|
||||
|
||||
this.notify("cmd");
|
||||
this.notify("title");
|
||||
this.emit("changed");
|
||||
App.closeWindow("powermenu__window");
|
||||
App.openWindow("verification__window");
|
||||
}
|
||||
|
||||
// readonly shutdown = () => {
|
||||
// this.action("shutdown")
|
||||
// }
|
||||
}
|
||||
|
||||
const powermenu = new PowerMenu();
|
||||
export default powermenu;
|
||||
@@ -1,94 +0,0 @@
|
||||
import GLib from "gi://GLib";
|
||||
import { sh, bash } from "../functions/utils.js";
|
||||
|
||||
const now = () => GLib.DateTime.new_now_local().format("%Y-%m-%d_%H-%M-%S");
|
||||
|
||||
class Recorder extends Service {
|
||||
static {
|
||||
Service.register(
|
||||
this,
|
||||
{},
|
||||
{
|
||||
timer: ["int"],
|
||||
recording: ["boolean"],
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
#recordings = Utils.HOME + "/Videos/Screencasting";
|
||||
#screenshots = Utils.HOME + "/Pictures/Screenshots";
|
||||
#file = "";
|
||||
#interval = 0;
|
||||
|
||||
recording = false;
|
||||
timer = 0;
|
||||
|
||||
async start() {
|
||||
if (this.recording) return;
|
||||
|
||||
Utils.ensureDirectory(this.#recordings);
|
||||
this.#file = `${this.#recordings}/${now()}.mp4`;
|
||||
sh(
|
||||
`wf-recorder -g "${await sh("slurp")}" -f ${this.#file} --pixel-format yuv420p`,
|
||||
);
|
||||
|
||||
this.recording = true;
|
||||
this.changed("recording");
|
||||
|
||||
this.timer = 0;
|
||||
this.#interval = Utils.interval(1000, () => {
|
||||
this.changed("timer");
|
||||
this.timer++;
|
||||
});
|
||||
}
|
||||
|
||||
async stop() {
|
||||
if (!this.recording) return;
|
||||
|
||||
await bash("killall -INT wf-recorder");
|
||||
this.recording = false;
|
||||
this.changed("recording");
|
||||
GLib.source_remove(this.#interval);
|
||||
|
||||
Utils.notify({
|
||||
iconName: "video-x-generic-symbolic",
|
||||
summary: "Screenrecord",
|
||||
body: this.#file,
|
||||
actions: {
|
||||
"Show in Files": () => sh(`xdg-open ${this.#recordings}`),
|
||||
View: () => sh(`xdg-open ${this.#file}`),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async screenshot(full = false) {
|
||||
const file = `${this.#screenshots}/${now()}.png`;
|
||||
Utils.ensureDirectory(this.#screenshots);
|
||||
|
||||
if (full) {
|
||||
await sh(`grim ${file}`);
|
||||
} else {
|
||||
const size = await sh("slurp -b#00000066 -w 0");
|
||||
if (!size) return;
|
||||
|
||||
await sh(`grim -g "${size}" ${file}`);
|
||||
}
|
||||
|
||||
bash(`wl-copy < ${file}`);
|
||||
|
||||
Utils.notify({
|
||||
image: file,
|
||||
summary: "Screenshot",
|
||||
body: file,
|
||||
actions: {
|
||||
"Show in Files": () => sh(`xdg-open ${this.#screenshots}`),
|
||||
View: () => sh(`xdg-open ${file}`),
|
||||
Edit: () => sh(`swappy -f ${file}`),
|
||||
},
|
||||
timeout: 5000,
|
||||
});
|
||||
}
|
||||
}
|
||||
const service = new Recorder();
|
||||
|
||||
export default service;
|
||||
Reference in new issue
Block a user