launcher: fixes
Fix light/dark actions Fix delay when pressing enter
This commit is contained in:
parent
0e2de54029
commit
ab80d8f786
3 changed files with 20 additions and 13 deletions
|
|
@ -29,12 +29,6 @@ const autocomplete = (entry: Widget.Entry, action: string) => {
|
|||
entry.set_position(-1);
|
||||
};
|
||||
|
||||
const hasMode = (mode: "light" | "dark") => {
|
||||
const scheme = Schemes.get_default().map[Palette.get_default().scheme];
|
||||
if (scheme.colours?.[mode]) return true;
|
||||
return scheme.flavours?.[Palette.get_default().flavour ?? ""]?.colours?.[mode] !== undefined;
|
||||
};
|
||||
|
||||
const actions = (mode: Variable<Mode>, entry: Widget.Entry): ActionMap => ({
|
||||
apps: {
|
||||
icon: "apps",
|
||||
|
|
@ -77,20 +71,20 @@ const actions = (mode: Variable<Mode>, entry: Widget.Entry): ActionMap => ({
|
|||
name: "Light",
|
||||
description: "Change scheme to light mode",
|
||||
action: () => {
|
||||
execAsync(`caelestia wallpaper -T light -f ${STATE}/wallpaper/current`).catch(console.error);
|
||||
Palette.get_default().switchMode("light");
|
||||
close();
|
||||
},
|
||||
available: () => hasMode("light"),
|
||||
available: () => Palette.get_default().hasMode("light"),
|
||||
},
|
||||
dark: {
|
||||
icon: "dark_mode",
|
||||
name: "Dark",
|
||||
description: "Change scheme to dark mode",
|
||||
action: () => {
|
||||
execAsync(`caelestia wallpaper -T dark -f ${STATE}/wallpaper/current`).catch(console.error);
|
||||
Palette.get_default().switchMode("dark");
|
||||
close();
|
||||
},
|
||||
available: () => hasMode("dark"),
|
||||
available: () => Palette.get_default().hasMode("dark"),
|
||||
},
|
||||
scheme: {
|
||||
icon: "palette",
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ export default class Launcher extends PopupWindow {
|
|||
);
|
||||
this.hook(entry, "activate", () => {
|
||||
(isAction(entry.get_text()) ? actions : content[mode.get()]).handleActivate(entry.get_text());
|
||||
entry.set_text(""); // Clear search on activate
|
||||
if (mode.get() === "math" && !isAction(entry.get_text())) entry.set_text(""); // Cause math mode doesn't auto clear
|
||||
});
|
||||
|
||||
// Clear search on hide if not in math mode or creating a todo
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
import { GLib, GObject, monitorFile, property, readFile, readFileAsync, register } from "astal";
|
||||
import { execAsync, GLib, GObject, monitorFile, property, readFile, readFileAsync, register } from "astal";
|
||||
import Schemes from "./schemes";
|
||||
|
||||
export type ColourMode = "light" | "dark";
|
||||
|
||||
export type Hex = `#${string}`;
|
||||
|
||||
|
|
@ -41,7 +44,7 @@ export default class Palette extends GObject.Object {
|
|||
return this.instance;
|
||||
}
|
||||
|
||||
#mode: "light" | "dark";
|
||||
#mode: ColourMode;
|
||||
#scheme: string;
|
||||
#flavour?: string;
|
||||
#colours!: IPalette;
|
||||
|
|
@ -249,6 +252,16 @@ export default class Palette extends GObject.Object {
|
|||
this.#notify();
|
||||
}
|
||||
|
||||
switchMode(mode: ColourMode) {
|
||||
execAsync(`caelestia scheme ${this.scheme} ${this.flavour ?? ""} ${mode}`).catch(console.error);
|
||||
}
|
||||
|
||||
hasMode(mode: ColourMode) {
|
||||
const scheme = Schemes.get_default().map[this.scheme];
|
||||
if (scheme?.colours?.[mode]) return true;
|
||||
return scheme?.flavours?.[this.flavour ?? ""]?.colours?.[mode] !== undefined;
|
||||
}
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue