35 lines
972 B
TypeScript
35 lines
972 B
TypeScript
/**
|
||
* rApp Shortcut configuration utility.
|
||
*
|
||
* Reads/writes shortcut slot assignments (1–9) 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;
|
||
}
|