💥 fix(control-center/tiles/night-light): not turning back on after disabling
This commit is contained in:
+36
-32
@@ -1,9 +1,10 @@
|
|||||||
|
import { execAsync, exec } from "ags/process";
|
||||||
|
import { interval } from "ags/time";
|
||||||
|
import GObject, { getter, register, setter } from "ags/gobject";
|
||||||
|
|
||||||
import AstalIO from "gi://AstalIO";
|
import AstalIO from "gi://AstalIO";
|
||||||
import GLib from "gi://GLib?version=2.0";
|
import GLib from "gi://GLib?version=2.0";
|
||||||
|
|
||||||
import GObject, { getter, register } from "ags/gobject";
|
|
||||||
import { execAsync, exec } from "ags/process";
|
|
||||||
import { interval } from "ags/time";
|
|
||||||
|
|
||||||
export { NightLight };
|
export { NightLight };
|
||||||
|
|
||||||
@@ -16,9 +17,6 @@ class NightLight extends GObject.Object {
|
|||||||
#gamma: number = 100;
|
#gamma: number = 100;
|
||||||
#identity: boolean = false;
|
#identity: boolean = false;
|
||||||
|
|
||||||
#prevTemperature: (number|null) = null;
|
|
||||||
#prevGamma: (number|null) = null;
|
|
||||||
|
|
||||||
@getter(Number)
|
@getter(Number)
|
||||||
public get temperature() { return this.#temperature; }
|
public get temperature() { return this.#temperature; }
|
||||||
public set temperature(newValue: number) { this.setTemperature(newValue); }
|
public set temperature(newValue: number) { this.setTemperature(newValue); }
|
||||||
@@ -34,19 +32,24 @@ class NightLight extends GObject.Object {
|
|||||||
|
|
||||||
@getter(Boolean)
|
@getter(Boolean)
|
||||||
public get identity() { return this.#identity; }
|
public get identity() { return this.#identity; }
|
||||||
public set identity(newValue: boolean) {
|
|
||||||
newValue ? this.applyIdentity() : this.filter();
|
@setter(Boolean)
|
||||||
|
public set identity(val: boolean) {
|
||||||
|
val ? this.applyIdentity() : this.filter();
|
||||||
|
this.#identity = val;
|
||||||
|
this.notify("identity");
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.#watchInterval = interval(1000, () => {
|
this.#watchInterval = interval(10000, () => {
|
||||||
execAsync("hyprctl hyprsunset temperature").then(t => {
|
execAsync("hyprctl hyprsunset temperature").then(t => {
|
||||||
if(t.trim() !== "" && t.trim().length <= 5) {
|
if(t.trim() !== "" && t.trim().length <= 5) {
|
||||||
const val = Number.parseInt(t.trim());
|
const val = Number.parseInt(t.trim());
|
||||||
|
|
||||||
if(this.#temperature !== val) {
|
if(this.#temperature !== val) {
|
||||||
|
this.identity = this.#temperature === this.identityTemperature;
|
||||||
this.#temperature = val;
|
this.#temperature = val;
|
||||||
this.notify("temperature");
|
this.notify("temperature");
|
||||||
}
|
}
|
||||||
@@ -58,6 +61,7 @@ class NightLight extends GObject.Object {
|
|||||||
const val = Number.parseInt(g.trim());
|
const val = Number.parseInt(g.trim());
|
||||||
|
|
||||||
if(this.#gamma !== val) {
|
if(this.#gamma !== val) {
|
||||||
|
this.identity = this.#gamma === this.maxGamma;
|
||||||
this.#gamma = val;
|
this.#gamma = val;
|
||||||
this.notify("gamma");
|
this.notify("gamma");
|
||||||
}
|
}
|
||||||
@@ -77,7 +81,7 @@ class NightLight extends GObject.Object {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private setTemperature(value: number): void {
|
private setTemperature(value: number): void {
|
||||||
if(value === this.temperature) return;
|
if(value === this.temperature && !this.identity) return;
|
||||||
|
|
||||||
if(value > this.maxTemperature || value < 1000) {
|
if(value > this.maxTemperature || value < 1000) {
|
||||||
console.error(`Night Light(hyprsunset): provided temperatue ${value
|
console.error(`Night Light(hyprsunset): provided temperatue ${value
|
||||||
@@ -85,20 +89,18 @@ class NightLight extends GObject.Object {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
execAsync(`hyprctl hyprsunset temperature ${value}`).then(() => {
|
this.dispatchAsync("temperature", value).then(() => {
|
||||||
this.#temperature = value;
|
this.#temperature = value;
|
||||||
this.notify("temperature");
|
this.notify("temperature");
|
||||||
|
|
||||||
this.#identity = false;
|
this.identity = false;
|
||||||
this.#prevTemperature = null;
|
|
||||||
this.#prevGamma = null;
|
|
||||||
}).catch((r) => console.error(
|
}).catch((r) => console.error(
|
||||||
`Night Light(hyprsunset): Couldn't set temperature. Stderr: ${r}`
|
`Night Light(hyprsunset): Couldn't set temperature. Stderr: ${r}`
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
private setGamma(value: number): void {
|
private setGamma(value: number): void {
|
||||||
if(value === this.gamma) return;
|
if(value === this.gamma && !this.identity) return;
|
||||||
|
|
||||||
if(value > this.maxGamma || value < 0) {
|
if(value > this.maxGamma || value < 0) {
|
||||||
console.error(`Night Light(hyprsunset): provided gamma ${value
|
console.error(`Night Light(hyprsunset): provided gamma ${value
|
||||||
@@ -106,38 +108,40 @@ class NightLight extends GObject.Object {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
execAsync(`hyprctl hyprsunset gamma ${value}`).then(() => {
|
this.dispatchAsync("gamma", value).then(() => {
|
||||||
this.#gamma = value;
|
this.#gamma = value;
|
||||||
this.notify("gamma");
|
this.notify("gamma");
|
||||||
|
|
||||||
this.#identity = false;
|
this.identity = false;
|
||||||
this.#prevTemperature = null;
|
|
||||||
this.#prevGamma = null;
|
|
||||||
}).catch((r) => console.error(
|
}).catch((r) => console.error(
|
||||||
`Night Light(hyprsunset): Couldn't set gamma. Stderr: ${r}`
|
`Night Light(hyprsunset): Couldn't set gamma. Stderr: ${r}`
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
public applyIdentity(): void {
|
public applyIdentity(): void {
|
||||||
if(this.#identity) return;
|
this.dispatch("identity");
|
||||||
|
if(!this.#identity) {
|
||||||
|
this.#identity = true;
|
||||||
|
this.notify("identity");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.#prevGamma = this.#gamma;
|
private dispatch(call: "temperature"|"gamma"|"identity", val?: number): string {
|
||||||
this.#prevTemperature = this.#temperature;
|
return exec(`hyprctl hyprsunset ${call}${val != null ? ` ${val}` : ""}`);
|
||||||
|
}
|
||||||
|
|
||||||
this.#identity = true;
|
private async dispatchAsync(...[call, val]: Parameters<typeof this.dispatch>): Promise<string> {
|
||||||
this.temperature = this.identityTemperature;
|
return await execAsync(`hyprctl hyprsunset ${call}${val != null ? ` ${val}` : ""}`);
|
||||||
this.gamma = this.maxGamma;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public filter(): void {
|
public filter(): void {
|
||||||
if(!this.#identity) return;
|
this.setTemperature(this.temperature);
|
||||||
|
this.setGamma(this.gamma);
|
||||||
|
|
||||||
this.#identity = false;
|
if(this.#identity) {
|
||||||
this.setTemperature(this.#prevTemperature ?? this.identityTemperature);
|
this.#identity = false;
|
||||||
this.setGamma(this.#prevGamma ?? this.maxGamma);
|
this.notify("identity");
|
||||||
|
}
|
||||||
this.#prevTemperature = null;
|
|
||||||
this.#prevGamma = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public saveData(): void {
|
public saveData(): void {
|
||||||
|
|||||||
@@ -10,11 +10,14 @@ export const TileNightLight = () =>
|
|||||||
<Tile title={tr("control_center.tiles.night_light.title")}
|
<Tile title={tr("control_center.tiles.night_light.title")}
|
||||||
icon={"weather-clear-night-symbolic"}
|
icon={"weather-clear-night-symbolic"}
|
||||||
description={createComputed([
|
description={createComputed([
|
||||||
|
createBinding(NightLight.getDefault(), "identity"),
|
||||||
createBinding(NightLight.getDefault(), "temperature"),
|
createBinding(NightLight.getDefault(), "temperature"),
|
||||||
createBinding(NightLight.getDefault(), "gamma")
|
createBinding(NightLight.getDefault(), "gamma")
|
||||||
], (temp, gamma) => `${temp === NightLight.getDefault().identityTemperature ?
|
], (identity, temp, gamma) => !identity ?
|
||||||
tr("control_center.tiles.night_light.default_desc") : `${temp}K`} ${
|
`${temp === NightLight.getDefault().identityTemperature ?
|
||||||
gamma < NightLight.getDefault().maxGamma ? `(${gamma}%)` : ""}`
|
tr("control_center.tiles.night_light.default_desc") : `${temp}K`
|
||||||
|
} ${gamma < NightLight.getDefault().maxGamma ? `(${gamma}%)` : ""}`
|
||||||
|
: tr("control_center.tiles.disabled")
|
||||||
)}
|
)}
|
||||||
hasArrow visible={isInstalled("hyprsunset")}
|
hasArrow visible={isInstalled("hyprsunset")}
|
||||||
onDisabled={() => NightLight.getDefault().identity = true}
|
onDisabled={() => NightLight.getDefault().identity = true}
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ class Tile extends Gtk.Box {
|
|||||||
<Gtk.Label class={"description"} label={createBinding(this, "description")}
|
<Gtk.Label class={"description"} label={createBinding(this, "description")}
|
||||||
xalign={0} ellipsize={Pango.EllipsizeMode.END} visible={
|
xalign={0} ellipsize={Pango.EllipsizeMode.END} visible={
|
||||||
variableToBoolean(createBinding(this, "description"))
|
variableToBoolean(createBinding(this, "description"))
|
||||||
} maxWidthChars={15} hexpand={false}
|
} maxWidthChars={12} hexpand={false}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Gtk.GestureClick onReleased={() => {
|
<Gtk.GestureClick onReleased={() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user