launcher: light/dark actions
For switching dynamic mode
This commit is contained in:
parent
9c1cc00965
commit
df3f93475a
2 changed files with 49 additions and 2 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
import { Apps } from "@/services/apps";
|
import { Apps } from "@/services/apps";
|
||||||
import type { IPalette } from "@/services/palette";
|
import type { IPalette } from "@/services/palette";
|
||||||
|
import Palette from "@/services/palette";
|
||||||
import Schemes from "@/services/schemes";
|
import Schemes from "@/services/schemes";
|
||||||
import Wallpapers from "@/services/wallpapers";
|
import Wallpapers from "@/services/wallpapers";
|
||||||
import { basename } from "@/utils/strings";
|
import { basename } from "@/utils/strings";
|
||||||
|
|
@ -17,6 +18,7 @@ interface IAction {
|
||||||
name: string;
|
name: string;
|
||||||
description: string;
|
description: string;
|
||||||
action: (...args: string[]) => void;
|
action: (...args: string[]) => void;
|
||||||
|
available?: () => boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ActionMap {
|
interface ActionMap {
|
||||||
|
|
@ -65,6 +67,26 @@ const actions = (mode: Variable<Mode>, entry: Widget.Entry): ActionMap => ({
|
||||||
entry.set_text("");
|
entry.set_text("");
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
light: {
|
||||||
|
icon: "light_mode",
|
||||||
|
name: "Light",
|
||||||
|
description: "Change dynamic scheme to light mode",
|
||||||
|
action: () => {
|
||||||
|
execAsync(`caelestia wallpaper -T light -f ${STATE}/wallpaper/current`).catch(console.error);
|
||||||
|
close();
|
||||||
|
},
|
||||||
|
available: () => Palette.get_default().name === "dynamic",
|
||||||
|
},
|
||||||
|
dark: {
|
||||||
|
icon: "dark_mode",
|
||||||
|
name: "Dark",
|
||||||
|
description: "Change dynamic scheme to dark mode",
|
||||||
|
action: () => {
|
||||||
|
execAsync(`caelestia wallpaper -T dark -f ${STATE}/wallpaper/current`).catch(console.error);
|
||||||
|
close();
|
||||||
|
},
|
||||||
|
available: () => Palette.get_default().name === "dynamic",
|
||||||
|
},
|
||||||
scheme: {
|
scheme: {
|
||||||
icon: "palette",
|
icon: "palette",
|
||||||
name: "Scheme",
|
name: "Scheme",
|
||||||
|
|
@ -278,7 +300,8 @@ export default class Actions extends Widget.Box implements LauncherContent {
|
||||||
for (const { obj } of fuzzysort.go(wallpaper, Wallpapers.get_default().list, { all: true, key: "path" }))
|
for (const { obj } of fuzzysort.go(wallpaper, Wallpapers.get_default().list, { all: true, key: "path" }))
|
||||||
this.#content.add(<Wallpaper {...obj} />);
|
this.#content.add(<Wallpaper {...obj} />);
|
||||||
} else {
|
} else {
|
||||||
for (const { target } of fuzzysort.go(action, this.#list, { all: true }))
|
const list = this.#list.filter(a => this.#map[a].available?.() ?? true);
|
||||||
|
for (const { target } of fuzzysort.go(action, list, { all: true }))
|
||||||
this.#content.add(<Action {...this.#map[target]} args={args.slice(1)} />);
|
this.#content.add(<Action {...this.#map[target]} args={args.slice(1)} />);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { GLib, GObject, monitorFile, property, readFile, register } from "astal";
|
import { GLib, GObject, monitorFile, property, readFile, readFileAsync, register } from "astal";
|
||||||
|
|
||||||
export type Hex = `#${string}`;
|
export type Hex = `#${string}`;
|
||||||
|
|
||||||
|
|
@ -41,8 +41,20 @@ export default class Palette extends GObject.Object {
|
||||||
return this.instance;
|
return this.instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#isLight: boolean;
|
||||||
|
#name: string;
|
||||||
#colours!: IPalette;
|
#colours!: IPalette;
|
||||||
|
|
||||||
|
@property(Boolean)
|
||||||
|
get isLight() {
|
||||||
|
return this.#isLight;
|
||||||
|
}
|
||||||
|
|
||||||
|
@property(String)
|
||||||
|
get name() {
|
||||||
|
return this.#name;
|
||||||
|
}
|
||||||
|
|
||||||
@property(Object)
|
@property(Object)
|
||||||
get colours() {
|
get colours() {
|
||||||
return this.#colours;
|
return this.#colours;
|
||||||
|
|
@ -234,6 +246,18 @@ export default class Palette extends GObject.Object {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
|
this.#isLight = readFile(`${STATE}/scheme/current-mode.txt`) === "light";
|
||||||
|
monitorFile(`${STATE}/scheme/current-mode.txt`, async file => {
|
||||||
|
this.#isLight = (await readFileAsync(file)) === "light";
|
||||||
|
this.notify("is-light");
|
||||||
|
});
|
||||||
|
|
||||||
|
this.#name = readFile(`${STATE}/scheme/current-name.txt`);
|
||||||
|
monitorFile(`${STATE}/scheme/current-name.txt`, async file => {
|
||||||
|
this.#name = await readFileAsync(file);
|
||||||
|
this.notify("name");
|
||||||
|
});
|
||||||
|
|
||||||
this.update();
|
this.update();
|
||||||
monitorFile(`${STATE}/scheme/current.txt`, () => this.update());
|
monitorFile(`${STATE}/scheme/current.txt`, () => this.update());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue