Files
Trilium/apps/client/src/services/experimental_features.ts

54 lines
1.6 KiB
TypeScript
Raw Normal View History

2025-12-09 22:58:16 +02:00
import { t } from "./i18n";
import options from "./options";
interface ExperimentalFeature {
id: string;
name: string;
description: string;
}
export const experimentalFeatures = [
{
id: "new-layout",
2025-12-09 22:58:16 +02:00
name: t("experimental_features.new_layout_name"),
description: t("experimental_features.new_layout_description"),
}
] as const satisfies ExperimentalFeature[];
type ExperimentalFeatureId = typeof experimentalFeatures[number]["id"];
let enabledFeatures: Set<ExperimentalFeatureId> | null = null;
export function isExperimentalFeatureEnabled(featureId: ExperimentalFeatureId): boolean {
return getEnabledFeatures().has(featureId);
}
export function getEnabledExperimentalFeatureIds() {
return getEnabledFeatures().values();
}
export async function toggleExperimentalFeature(featureId: ExperimentalFeatureId, enable: boolean) {
let features = Array.from(getEnabledFeatures());
if (enable) {
if (!features.includes(featureId)) {
features.push(featureId);
}
} else {
features = features.filter(f => f !== featureId);
}
await options.save("experimentalFeatures", JSON.stringify(features));
}
function getEnabledFeatures() {
if (!enabledFeatures) {
let features: ExperimentalFeatureId[] = [];
try {
features = JSON.parse(options.get("experimentalFeatures")) as ExperimentalFeatureId[];
} catch (e) {
console.warn("Failed to parse experimental features from options:", e);
}
enabledFeatures = new Set(features);
}
return enabledFeatures;
}