diff --git a/ivette/src/dome/src/renderer/data/json.ts b/ivette/src/dome/src/renderer/data/json.ts index 56ef9117e0fb57fc7d9724f842985e5412a63ba6..76f304999bf0d97da38455431aae41114f388c05 100644 --- a/ivette/src/dome/src/renderer/data/json.ts +++ b/ivette/src/dome/src/renderer/data/json.ts @@ -14,6 +14,8 @@ export type json = undefined | null | boolean | number | string | json[] | { [key: string]: json }; +export type jobject = { [key: string]: json }; + /** Parse without _revivals_. Returned data is guaranteed to have only [[json]] type. @@ -84,6 +86,11 @@ export const jNull: Safe<undefined> = () => undefined; /** Identity. */ export const jAny: Safe<json> = (js: json) => js; +/** JSON Object. */ +export const jObj: Loose<jobject> = (js: json) => ( + typeof js === 'object' && !Array.isArray(js) && js !== null ? js : undefined +); + /** Primitive JSON number or `undefined`. */ export const jNumber: Loose<number> = (js: json) => ( typeof js === 'number' && !Number.isNaN(js) ? js : undefined diff --git a/ivette/src/frama-c/LabViews.tsx b/ivette/src/frama-c/LabViews.tsx index 70f63b7f6947113a0600784f641b39cc01d55477..54b4bc4f0e835b149b6282756ee93020b8affdd8 100644 --- a/ivette/src/frama-c/LabViews.tsx +++ b/ivette/src/frama-c/LabViews.tsx @@ -352,10 +352,11 @@ const makeGridItem = (customize: any, onClose: any) => (comp: any) => { function CustomViews({ settings, shape, setShape, views: libViews }: any) { const [local, setLocal] = Settings.useWindowSettings( - settings, Json.jAny, {}, + settings, Json.jObj, {}, ) as any; - const [customs, setCustoms] = - Dome.useGlobalSettings<any>('frama-c.labview', Json.jAny, {}); + const [customs, setCustoms] = Settings.useLocalStorage( + 'frama-c.labview', Json.jObj, {}, + ); const [edited, setEdited]: any = React.useState(); const triggerDefault = React.useRef(); const { current, shapes = {} } = local; @@ -374,7 +375,7 @@ function CustomViews({ settings, shape, setShape, views: libViews }: any) { { id, order, label, title, builtin: true, defaultView, origin }; }); - _.forEach(customs, (view) => { + _.forEach(customs as any, (view) => { const { id, order, label = '(Custom View)', title, origin } = view; if (id && !theViews[id]) { theViews[id] = { id, order, label, title, builtin: false, origin }; @@ -463,7 +464,7 @@ function CustomViews({ settings, shape, setShape, views: libViews }: any) { if (edited === id) { const RENAMED = (newLabel: string) => { if (newLabel) { - const custom = customs[id]; + const custom = Json.jObj(customs[id]) || {}; if (custom) custom.label = newLabel; setCustoms(customs); } diff --git a/ivette/src/renderer/Controller.tsx b/ivette/src/renderer/Controller.tsx index 853f8b06ccd78a2ffc1298cd05564707868228cb..0f51b37cc00f10f9eca5248a292eed44714fc250 100644 --- a/ivette/src/renderer/Controller.tsx +++ b/ivette/src/renderer/Controller.tsx @@ -99,7 +99,7 @@ function insertConfig(hs: string[], cfg: Server.Configuration) { let reloadCommand: string | undefined; Dome.reload.on(() => { - const [lastCmd] = Settings.getWindowSettings( + const [lastCmd] = Settings.getLocalStorage( 'Controller.history', Json.jList(Json.jString), [], ); reloadCommand = lastCmd; @@ -175,7 +175,7 @@ const RenderConsole = () => { const [cursor, setCursor] = React.useState(-1); const [isEmpty, setEmpty] = React.useState(true); const [noTrash, setNoTrash] = React.useState(true); - const [history, setHistory] = Settings.useWindowSettings( + const [history, setHistory] = Settings.useLocalStorage( 'Controller.history', Json.jList(Json.jString), [], );