rspace-online/shared/shortcut-config.ts

35 lines
972 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* rApp Shortcut configuration utility.
*
* Reads/writes shortcut slot assignments (19) from localStorage.
* Used by the settings UI in rstack-identity.ts.
* The shell inline script reads localStorage directly (can't import ES modules).
*/
const STORAGE_KEY = "rspace-shortcuts";
export function getShortcuts(): Record<string, string> {
try {
return JSON.parse(localStorage.getItem(STORAGE_KEY) || "{}");
} catch {
return {};
}
}
export function setShortcut(slot: string, moduleId: string): void {
if (slot < "1" || slot > "9") return;
const shortcuts = getShortcuts();
shortcuts[slot] = moduleId;
localStorage.setItem(STORAGE_KEY, JSON.stringify(shortcuts));
}
export function removeShortcut(slot: string): void {
const shortcuts = getShortcuts();
delete shortcuts[slot];
localStorage.setItem(STORAGE_KEY, JSON.stringify(shortcuts));
}
export function getModuleForSlot(slot: string): string | null {
return getShortcuts()[slot] ?? null;
}