Files
AtreidesAssetsFree/client/license.js
T
2026-10-29 15:24:06 +01:00

51 lines
1.5 KiB
JavaScript

// Generated, do not edit. sha256:1df2c5fd2e650856e801961b8f9b2f63fd3868b6f612cd0c41498384a12aea9b
import { licenseStatus } from './data/license-status.js';
import { getPref, setPref } from './data/preferences.js';
import { t } from './i18n/index.js';
let snapshot = null;
export async function loadLicense() {
snapshot = await licenseStatus();
return snapshot;
}
export function licenseSnapshot() { return snapshot; }
export function locked(feature) {
const f = snapshot?.features;
return f ? f[feature] === false : false;
}
export function limitFor(kind) {
const m = snapshot?.max;
return m && kind in m ? m[kind] : null;
}
export function counterText(kind, current) {
const max = limitFor(kind);
return max === null ? null : t('license.counter', { naam: t(`license.name_${kind}`), n: current, max });
}
const PREF_SCOPE = 'license';
const PREF_SEEN = 'seen';
export function licenseFingerprint(s) {
if (!s) return '';
const i = s.installed;
return [s.level, s.why, s.buyer ?? '', s.issued ?? '',
i ? `${i.majorFrom}-${i.majorTo}` : ''].join('|');
}
export async function markLicenseSeen() {
await setPref(PREF_SCOPE, PREF_SEEN, licenseFingerprint(snapshot));
}
export async function licenseChangedSinceSeen() {
if (!snapshot) return false;
const now = licenseFingerprint(snapshot);
const seen = await getPref(PREF_SCOPE, PREF_SEEN, null);
if (seen === null || seen === undefined) { await setPref(PREF_SCOPE, PREF_SEEN, now); return false; }
return seen !== now;
}