Schedules list as a table with enable, run now, edit, duplicate, delete and view runs; built-ins only enable, retime and run. The runs page links each run's tasks through its capture's dispatches. The Start node gains a Schedule trigger that picks or creates a schedule and binds the schedule source to the workflow. Times show in a per-browser display zone set under Appearance; the cron time zone and run retention are edited on the Schedules page.
180 lines
4.7 KiB
TypeScript
180 lines
4.7 KiB
TypeScript
import { defineStore } from "pinia";
|
|
import { ref } from "vue";
|
|
|
|
export const THEME_KEY = "archie.theme";
|
|
export const DENSITY_KEY = "archie.density";
|
|
export const MOTION_KEY = "archie.motion";
|
|
export const TOOLTIPS_KEY = "archie.tooltips";
|
|
export const OVERSCROLL_KEY = "archie.overscroll";
|
|
export const PRINT_WIDTH_KEY = "archie.printWidth";
|
|
export const TIME_ZONE_KEY = "archie.timeZone";
|
|
|
|
export type Theme = "system" | "dark" | "light";
|
|
export type Density = "comfortable" | "compact";
|
|
export type Motion = "system" | "reduced";
|
|
|
|
/** Columns a code view wraps at; "window" wraps at the edge of the pane. */
|
|
export type PrintWidth = "window" | "80" | "100" | "120";
|
|
export const PRINT_WIDTHS: readonly PrintWidth[] = ["window", "80", "100", "120"];
|
|
|
|
type ResolvedTheme = Exclude<Theme, "system">;
|
|
|
|
function storedChoice<T extends string>(
|
|
key: string,
|
|
choices: readonly T[],
|
|
fallback: T,
|
|
): T {
|
|
try {
|
|
const value = localStorage.getItem(key);
|
|
return choices.includes(value as T) ? (value as T) : fallback;
|
|
} catch {
|
|
return fallback;
|
|
}
|
|
}
|
|
|
|
function persist(key: string, value: string): void {
|
|
try {
|
|
localStorage.setItem(key, value);
|
|
} catch {
|
|
// The preference still applies for this page view; only persistence is lost.
|
|
}
|
|
}
|
|
|
|
function storedZone(): string {
|
|
try {
|
|
const value = localStorage.getItem(TIME_ZONE_KEY) ?? "";
|
|
if (value) new Intl.DateTimeFormat(undefined, { timeZone: value });
|
|
return value;
|
|
} catch {
|
|
return "";
|
|
}
|
|
}
|
|
|
|
function resolveTheme(preference: Theme): ResolvedTheme {
|
|
if (preference !== "system") return preference;
|
|
try {
|
|
return matchMedia("(prefers-color-scheme: dark)").matches
|
|
? "dark"
|
|
: "light";
|
|
} catch {
|
|
return "dark";
|
|
}
|
|
}
|
|
|
|
export const useAppearanceStore = defineStore("appearance", () => {
|
|
const theme = ref<Theme>(
|
|
storedChoice(THEME_KEY, ["system", "dark", "light"], "dark"),
|
|
);
|
|
const density = ref<Density>(
|
|
storedChoice(DENSITY_KEY, ["comfortable", "compact"], "comfortable"),
|
|
);
|
|
const motion = ref<Motion>(
|
|
storedChoice(MOTION_KEY, ["system", "reduced"], "system"),
|
|
);
|
|
const tooltipsEnabled = ref(
|
|
storedChoice(TOOLTIPS_KEY, ["on", "off"], "on") === "on",
|
|
);
|
|
const overscroll = ref(
|
|
storedChoice(OVERSCROLL_KEY, ["on", "off"], "on") === "on",
|
|
);
|
|
const printWidth = ref<PrintWidth>(
|
|
storedChoice(PRINT_WIDTH_KEY, PRINT_WIDTHS, "window"),
|
|
);
|
|
// An IANA zone times are shown in; empty follows the browser.
|
|
const timeZone = ref(storedZone());
|
|
let initialized = false;
|
|
|
|
function applyTheme(): void {
|
|
document.documentElement.dataset.theme = resolveTheme(theme.value);
|
|
}
|
|
|
|
function setTheme(value: Theme): void {
|
|
theme.value = value;
|
|
applyTheme();
|
|
persist(THEME_KEY, value);
|
|
}
|
|
|
|
function setDensity(value: Density): void {
|
|
density.value = value;
|
|
document.documentElement.dataset.density = value;
|
|
persist(DENSITY_KEY, value);
|
|
}
|
|
|
|
function setMotion(value: Motion): void {
|
|
motion.value = value;
|
|
document.documentElement.dataset.motion = value;
|
|
persist(MOTION_KEY, value);
|
|
}
|
|
|
|
function setTooltips(enabled: boolean): void {
|
|
tooltipsEnabled.value = enabled;
|
|
persist(TOOLTIPS_KEY, enabled ? "on" : "off");
|
|
}
|
|
|
|
function applyOverscroll(): void {
|
|
document.documentElement.dataset.overscroll = overscroll.value ? "on" : "off";
|
|
}
|
|
|
|
function setOverscroll(enabled: boolean): void {
|
|
overscroll.value = enabled;
|
|
applyOverscroll();
|
|
persist(OVERSCROLL_KEY, enabled ? "on" : "off");
|
|
}
|
|
|
|
function applyPrintWidth(): void {
|
|
document.documentElement.style.setProperty(
|
|
"--code-print-width",
|
|
printWidth.value === "window" ? "9999ch" : `${printWidth.value}ch`,
|
|
);
|
|
}
|
|
|
|
function setPrintWidth(value: PrintWidth): void {
|
|
printWidth.value = value;
|
|
applyPrintWidth();
|
|
persist(PRINT_WIDTH_KEY, value);
|
|
}
|
|
|
|
function setTimeZone(value: string): void {
|
|
timeZone.value = value;
|
|
persist(TIME_ZONE_KEY, value);
|
|
}
|
|
|
|
function initialize(): void {
|
|
if (initialized) return;
|
|
initialized = true;
|
|
applyTheme();
|
|
applyOverscroll();
|
|
applyPrintWidth();
|
|
document.documentElement.dataset.density = density.value;
|
|
document.documentElement.dataset.motion = motion.value;
|
|
try {
|
|
matchMedia("(prefers-color-scheme: dark)").addEventListener(
|
|
"change",
|
|
() => {
|
|
if (theme.value === "system") applyTheme();
|
|
},
|
|
);
|
|
} catch {
|
|
// matchMedia is absent in older embedded views. The dark fallback stands.
|
|
}
|
|
}
|
|
|
|
return {
|
|
theme,
|
|
density,
|
|
motion,
|
|
tooltipsEnabled,
|
|
overscroll,
|
|
printWidth,
|
|
timeZone,
|
|
initialize,
|
|
setTheme,
|
|
setDensity,
|
|
setMotion,
|
|
setTooltips,
|
|
setOverscroll,
|
|
setPrintWidth,
|
|
setTimeZone,
|
|
};
|
|
});
|