mirror of
https://github.com/Theaninova/TheaninovOS.git
synced 2025-12-12 19:46:20 +00:00
feat: update ags
This commit is contained in:
70
home/desktops/hyprland/ags/js/services/asusctl.js
Normal file
70
home/desktops/hyprland/ags/js/services/asusctl.js
Normal file
@@ -0,0 +1,70 @@
|
||||
import * as Utils from "resource:///com/github/Aylur/ags/utils.js";
|
||||
import Service from "resource:///com/github/Aylur/ags/service.js";
|
||||
|
||||
class Asusctl extends Service {
|
||||
static {
|
||||
Service.register(
|
||||
this,
|
||||
{},
|
||||
{
|
||||
profile: ["string", "r"],
|
||||
mode: ["string", "r"],
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
profiles = Object.freeze(["Performance", "Balanced", "Quiet"]);
|
||||
#profile = "Balanced";
|
||||
#mode = "Hyprid";
|
||||
|
||||
nextProfile() {
|
||||
Utils.execAsync("asusctl profile -n")
|
||||
.then(() => {
|
||||
this.#profile = Utils.exec("asusctl profile -p").split(" ")[3];
|
||||
this.changed("profile");
|
||||
})
|
||||
.catch(console.error);
|
||||
}
|
||||
|
||||
/** @param {'Performance' | 'Balanced' | 'Quiet'} prof */
|
||||
setProfile(prof) {
|
||||
Utils.execAsync(`asusctl profile --profile-set ${prof}`)
|
||||
.then(() => {
|
||||
this.#profile = prof;
|
||||
this.changed("profile");
|
||||
})
|
||||
.catch(console.error);
|
||||
}
|
||||
|
||||
nextMode() {
|
||||
Utils.execAsync(
|
||||
`supergfxctl -m ${this.#mode === "Hybrid" ? "Integrated" : "Hybrid"}`,
|
||||
)
|
||||
.then(() => {
|
||||
this.#mode = Utils.exec("supergfxctl -g");
|
||||
this.changed("profile");
|
||||
})
|
||||
.catch(console.error);
|
||||
}
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
if (Utils.exec("which asusctl")) {
|
||||
this.available = true;
|
||||
this.#profile = Utils.exec("asusctl profile -p").split(" ")[3];
|
||||
Utils.execAsync("supergfxctl -g").then((mode) => (this.#mode = mode));
|
||||
} else {
|
||||
this.available = false;
|
||||
}
|
||||
}
|
||||
|
||||
get profile() {
|
||||
return this.#profile;
|
||||
}
|
||||
get mode() {
|
||||
return this.#mode;
|
||||
}
|
||||
}
|
||||
|
||||
export default new Asusctl();
|
||||
72
home/desktops/hyprland/ags/js/services/brightness.js
Normal file
72
home/desktops/hyprland/ags/js/services/brightness.js
Normal file
@@ -0,0 +1,72 @@
|
||||
import * as Utils from "resource:///com/github/Aylur/ags/utils.js";
|
||||
import Service from "resource:///com/github/Aylur/ags/service.js";
|
||||
import options from "../options.js";
|
||||
import { dependencies } from "../utils.js";
|
||||
|
||||
const KBD = options.brightnessctlKBD;
|
||||
|
||||
class Brightness extends Service {
|
||||
static {
|
||||
Service.register(
|
||||
this,
|
||||
{},
|
||||
{
|
||||
screen: ["float", "rw"],
|
||||
kbd: ["int", "rw"],
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
#kbd = 0;
|
||||
#kbdMax = 3;
|
||||
#screen = 0;
|
||||
|
||||
get kbd() {
|
||||
return this.#kbd;
|
||||
}
|
||||
get screen() {
|
||||
return this.#screen;
|
||||
}
|
||||
|
||||
set kbd(value) {
|
||||
if (!dependencies(["brightnessctl"])) return;
|
||||
|
||||
if (value < 0 || value > this.#kbdMax) return;
|
||||
|
||||
Utils.execAsync(`brightnessctl -d ${KBD} s ${value} -q`)
|
||||
.then(() => {
|
||||
this.#kbd = value;
|
||||
this.changed("kbd");
|
||||
})
|
||||
.catch(console.error);
|
||||
}
|
||||
|
||||
set screen(percent) {
|
||||
if (!dependencies(["brightnessctl"])) return;
|
||||
|
||||
if (percent < 0) percent = 0;
|
||||
|
||||
if (percent > 1) percent = 1;
|
||||
|
||||
Utils.execAsync(`brightnessctl s ${percent * 100}% -q`)
|
||||
.then(() => {
|
||||
this.#screen = percent;
|
||||
this.changed("screen");
|
||||
})
|
||||
.catch(console.error);
|
||||
}
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
if (dependencies(["brightnessctl"])) {
|
||||
this.#kbd = Number(Utils.exec(`brightnessctl -d ${KBD} g`));
|
||||
this.#kbdMax = Number(Utils.exec(`brightnessctl -d ${KBD} m`));
|
||||
this.#screen =
|
||||
Number(Utils.exec("brightnessctl g")) /
|
||||
Number(Utils.exec("brightnessctl m"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default new Brightness();
|
||||
73
home/desktops/hyprland/ags/js/services/colorpicker.js
Normal file
73
home/desktops/hyprland/ags/js/services/colorpicker.js
Normal file
@@ -0,0 +1,73 @@
|
||||
import Notifications from "resource:///com/github/Aylur/ags/service/notifications.js";
|
||||
import { Variable } from "resource:///com/github/Aylur/ags/variable.js";
|
||||
import * as Utils from "resource:///com/github/Aylur/ags/utils.js";
|
||||
import Service from "resource:///com/github/Aylur/ags/service.js";
|
||||
import { dependencies } from "../utils.js";
|
||||
|
||||
const COLORS_CACHE = Utils.CACHE_DIR + "/colorpicker.json";
|
||||
|
||||
class Colors extends Service {
|
||||
static {
|
||||
Service.register(
|
||||
this,
|
||||
{},
|
||||
{
|
||||
colors: ["jsobject"],
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/** @type {Variable<string[]>} */
|
||||
#colors = new Variable([]);
|
||||
get colors() {
|
||||
return this.#colors.value;
|
||||
}
|
||||
|
||||
#notifID = 0;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.#colors.connect("changed", () => this.changed("colors"));
|
||||
|
||||
Utils.readFileAsync(COLORS_CACHE)
|
||||
.then((out) => this.#colors.setValue(JSON.parse(out || "[]")))
|
||||
.catch(() => print("no colorpicker cache found"));
|
||||
}
|
||||
|
||||
/** @param {string} color */
|
||||
wlCopy(color) {
|
||||
Utils.execAsync(["wl-copy", color]).catch((err) => console.error(err));
|
||||
}
|
||||
|
||||
async pick() {
|
||||
if (!dependencies(["hyprpicker"])) return;
|
||||
|
||||
const color = await Utils.execAsync("hyprpicker");
|
||||
if (!color) return;
|
||||
|
||||
this.wlCopy(color);
|
||||
const list = this.#colors.value;
|
||||
if (!list.includes(color)) {
|
||||
list.push(color);
|
||||
if (list.length > 10) list.shift();
|
||||
|
||||
this.#colors.value = list;
|
||||
Utils.writeFile(JSON.stringify(list, null, 2), COLORS_CACHE).catch(
|
||||
(err) => console.error(err),
|
||||
);
|
||||
}
|
||||
|
||||
this.#notifID = Notifications.Notify(
|
||||
"Color Picker",
|
||||
this.#notifID,
|
||||
"color-select-symbolic",
|
||||
color,
|
||||
"",
|
||||
[],
|
||||
{},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default new Colors();
|
||||
30
home/desktops/hyprland/ags/js/services/lockscreen.js
Normal file
30
home/desktops/hyprland/ags/js/services/lockscreen.js
Normal file
@@ -0,0 +1,30 @@
|
||||
import Service from "resource:///com/github/Aylur/ags/service.js";
|
||||
import * as Utils from "resource:///com/github/Aylur/ags/utils.js";
|
||||
import App from "resource:///com/github/Aylur/ags/app.js";
|
||||
const authpy = App.configDir + "/js/lockscreen/auth.py";
|
||||
|
||||
class Lockscreen extends Service {
|
||||
static {
|
||||
Service.register(this, {
|
||||
lock: ["boolean"],
|
||||
authenticating: ["boolean"],
|
||||
});
|
||||
}
|
||||
|
||||
lockscreen() {
|
||||
this.emit("lock", true);
|
||||
}
|
||||
|
||||
/** @param {string} password */
|
||||
auth(password) {
|
||||
this.emit("authenticating", true);
|
||||
Utils.execAsync([authpy, password])
|
||||
.then((out) => {
|
||||
this.emit("lock", out !== "True");
|
||||
this.emit("authenticating", false);
|
||||
})
|
||||
.catch((err) => console.error(err));
|
||||
}
|
||||
}
|
||||
|
||||
export default new Lockscreen();
|
||||
58
home/desktops/hyprland/ags/js/services/onScreenIndicator.js
Normal file
58
home/desktops/hyprland/ags/js/services/onScreenIndicator.js
Normal file
@@ -0,0 +1,58 @@
|
||||
import * as Utils from "resource:///com/github/Aylur/ags/utils.js";
|
||||
import Service from "resource:///com/github/Aylur/ags/service.js";
|
||||
import Audio from "resource:///com/github/Aylur/ags/service/audio.js";
|
||||
import icons from "../icons.js";
|
||||
import { getAudioTypeIcon } from "../utils.js";
|
||||
import Brightness from "./brightness.js";
|
||||
|
||||
class Indicator extends Service {
|
||||
static {
|
||||
Service.register(this, {
|
||||
popup: ["double", "string"],
|
||||
});
|
||||
}
|
||||
|
||||
#delay = 1500;
|
||||
#count = 0;
|
||||
|
||||
/**
|
||||
* @param {number} value - 0 < v < 1
|
||||
* @param {string} icon
|
||||
*/
|
||||
popup(value, icon) {
|
||||
this.emit("popup", value, icon);
|
||||
this.#count++;
|
||||
Utils.timeout(this.#delay, () => {
|
||||
this.#count--;
|
||||
|
||||
if (this.#count === 0) this.emit("popup", -1, icon);
|
||||
});
|
||||
}
|
||||
|
||||
speaker() {
|
||||
this.popup(
|
||||
Audio.speaker?.volume || 0,
|
||||
getAudioTypeIcon(Audio.speaker?.icon_name || ""),
|
||||
);
|
||||
}
|
||||
|
||||
display() {
|
||||
// brightness is async, so lets wait a bit
|
||||
Utils.timeout(10, () =>
|
||||
this.popup(Brightness.screen, icons.brightness.screen),
|
||||
);
|
||||
}
|
||||
|
||||
kbd() {
|
||||
// brightness is async, so lets wait a bit
|
||||
Utils.timeout(10, () =>
|
||||
this.popup((Brightness.kbd * 33 + 1) / 100, icons.brightness.keyboard),
|
||||
);
|
||||
}
|
||||
|
||||
connect(event = "popup", callback) {
|
||||
return super.connect(event, callback);
|
||||
}
|
||||
}
|
||||
|
||||
export default new Indicator();
|
||||
43
home/desktops/hyprland/ags/js/services/powermenu.js
Normal file
43
home/desktops/hyprland/ags/js/services/powermenu.js
Normal file
@@ -0,0 +1,43 @@
|
||||
import App from "resource:///com/github/Aylur/ags/app.js";
|
||||
import Service from "resource:///com/github/Aylur/ags/service.js";
|
||||
|
||||
class PowerMenu extends Service {
|
||||
static {
|
||||
Service.register(
|
||||
this,
|
||||
{},
|
||||
{
|
||||
title: ["string"],
|
||||
cmd: ["string"],
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
#title = "";
|
||||
#cmd = "";
|
||||
|
||||
get title() {
|
||||
return this.#title;
|
||||
}
|
||||
get cmd() {
|
||||
return this.#cmd;
|
||||
}
|
||||
|
||||
/** @param {'sleep' | 'reboot' | 'logout' | 'shutdown'} action */
|
||||
action(action) {
|
||||
[this.#cmd, this.#title] = {
|
||||
sleep: ["systemctl suspend", "Sleep"],
|
||||
reboot: ["systemctl reboot", "Reboot"],
|
||||
logout: ["pkill Hyprland", "Log Out"],
|
||||
shutdown: ["shutdown now", "Shutdown"],
|
||||
}[action];
|
||||
|
||||
this.notify("cmd");
|
||||
this.notify("title");
|
||||
this.emit("changed");
|
||||
App.closeWindow("powermenu");
|
||||
App.openWindow("verification");
|
||||
}
|
||||
}
|
||||
|
||||
export default new PowerMenu();
|
||||
112
home/desktops/hyprland/ags/js/services/screenrecord.js
Normal file
112
home/desktops/hyprland/ags/js/services/screenrecord.js
Normal file
@@ -0,0 +1,112 @@
|
||||
import Service from "resource:///com/github/Aylur/ags/service.js";
|
||||
import * as Utils from "resource:///com/github/Aylur/ags/utils.js";
|
||||
import App from "resource:///com/github/Aylur/ags/app.js";
|
||||
import GLib from "gi://GLib";
|
||||
import { dependencies } from "../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"],
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
#path = GLib.get_home_dir() + "/Videos/Screencasting";
|
||||
#file = "";
|
||||
#interval = 0;
|
||||
|
||||
recording = false;
|
||||
timer = 0;
|
||||
|
||||
async start() {
|
||||
if (!dependencies(["slurp", "wf-recorder"])) return;
|
||||
|
||||
if (this.recording) return;
|
||||
|
||||
const area = await Utils.execAsync("slurp");
|
||||
Utils.ensureDirectory(this.#path);
|
||||
this.#file = `${this.#path}/${now()}.mp4`;
|
||||
Utils.execAsync(["wf-recorder", "-g", area, "-f", this.#file]);
|
||||
this.recording = true;
|
||||
this.changed("recording");
|
||||
|
||||
this.timer = 0;
|
||||
this.#interval = Utils.interval(1000, () => {
|
||||
this.changed("timer");
|
||||
this.timer++;
|
||||
});
|
||||
}
|
||||
|
||||
async stop() {
|
||||
if (!dependencies(["notify-send"])) return;
|
||||
|
||||
if (!this.recording) return;
|
||||
|
||||
Utils.execAsync("killall -INT wf-recorder");
|
||||
this.recording = false;
|
||||
this.changed("recording");
|
||||
GLib.source_remove(this.#interval);
|
||||
|
||||
const res = await Utils.execAsync([
|
||||
"notify-send",
|
||||
"-A",
|
||||
"files=Show in Files",
|
||||
"-A",
|
||||
"view=View",
|
||||
"-i",
|
||||
"video-x-generic-symbolic",
|
||||
"Screenrecord",
|
||||
this.#file,
|
||||
]);
|
||||
|
||||
if (res === "files") Utils.execAsync("xdg-open " + this.#path);
|
||||
|
||||
if (res === "view") Utils.execAsync("xdg-open " + this.#file);
|
||||
}
|
||||
|
||||
async screenshot(full = false) {
|
||||
if (!dependencies(["slurp", "wayshot"])) return;
|
||||
|
||||
const path = GLib.get_home_dir() + "/Pictures/Screenshots";
|
||||
const file = `${path}/${now()}.png`;
|
||||
Utils.ensureDirectory(path);
|
||||
|
||||
await Utils.execAsync(
|
||||
["wayshot", "-f", file].concat(
|
||||
full ? [] : ["-s", await Utils.execAsync("slurp")],
|
||||
),
|
||||
);
|
||||
|
||||
Utils.execAsync(["bash", "-c", `wl-copy < ${file}`]);
|
||||
|
||||
const res = await Utils.execAsync([
|
||||
"notify-send",
|
||||
"-A",
|
||||
"files=Show in Files",
|
||||
"-A",
|
||||
"view=View",
|
||||
"-A",
|
||||
"edit=Edit",
|
||||
"-i",
|
||||
file,
|
||||
"Screenshot",
|
||||
file,
|
||||
]);
|
||||
if (res === "files") Utils.execAsync("xdg-open " + path);
|
||||
|
||||
if (res === "view") Utils.execAsync("xdg-open " + file);
|
||||
|
||||
if (res === "edit") Utils.execAsync(["swappy", "-f", file]);
|
||||
|
||||
App.closeWindow("dashboard");
|
||||
}
|
||||
}
|
||||
|
||||
export default new Recorder();
|
||||
Reference in New Issue
Block a user