mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-20 15:19:16 +00:00
Enables customizing terminal font size both globally and for individual hosts, with persistent storage and UI controls in settings and terminal toolbars. Improves user experience and accessibility by allowing finer display adjustments.
36 lines
919 B
TypeScript
36 lines
919 B
TypeScript
const safeParse = <T>(value: string | null): T | null => {
|
|
if (!value) return null;
|
|
try {
|
|
return JSON.parse(value) as T;
|
|
} catch {
|
|
return null;
|
|
}
|
|
};
|
|
|
|
export const localStorageAdapter = {
|
|
read<T>(key: string): T | null {
|
|
return safeParse<T>(localStorage.getItem(key));
|
|
},
|
|
write<T>(key: string, value: T) {
|
|
localStorage.setItem(key, JSON.stringify(value));
|
|
},
|
|
readString(key: string): string | null {
|
|
return localStorage.getItem(key);
|
|
},
|
|
writeString(key: string, value: string) {
|
|
localStorage.setItem(key, value);
|
|
},
|
|
readNumber(key: string): number | null {
|
|
const value = localStorage.getItem(key);
|
|
if (!value) return null;
|
|
const num = parseInt(value, 10);
|
|
return isNaN(num) ? null : num;
|
|
},
|
|
writeNumber(key: string, value: number) {
|
|
localStorage.setItem(key, String(value));
|
|
},
|
|
remove(key: string) {
|
|
localStorage.removeItem(key);
|
|
},
|
|
};
|