mirror of
https://github.com/zadam/trilium.git
synced 2026-01-07 23:24:25 +01:00
chore(window): handle potential JSON parsing failures
This commit is contained in:
parent
c28f11336e
commit
254145f0e5
@ -72,6 +72,19 @@ function getOptionBool(name: FilterOptionsByType<boolean>): boolean {
|
|||||||
return val === "true";
|
return val === "true";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getOptionJson(name: OptionNames) {
|
||||||
|
const val = getOptionOrNull(name);
|
||||||
|
|
||||||
|
if (typeof val !== "string") {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return JSON.parse(val);
|
||||||
|
} catch (e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function setOption<T extends OptionNames>(name: T, value: string | OptionDefinitions[T]) {
|
function setOption<T extends OptionNames>(name: T, value: string | OptionDefinitions[T]) {
|
||||||
const option = becca.getOption(name);
|
const option = becca.getOption(name);
|
||||||
|
|
||||||
@ -137,6 +150,7 @@ export default {
|
|||||||
getOption,
|
getOption,
|
||||||
getOptionInt,
|
getOptionInt,
|
||||||
getOptionBool,
|
getOptionBool,
|
||||||
|
getOptionJson,
|
||||||
setOption,
|
setOption,
|
||||||
createOption,
|
createOption,
|
||||||
getOptions,
|
getOptions,
|
||||||
|
|||||||
@ -197,7 +197,7 @@ function updateTrayMenu() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function buildClosedWindowsMenu() {
|
function buildClosedWindowsMenu() {
|
||||||
const savedOpenNoteContexts = JSON.parse(optionService.getOption("openNoteContexts") || "[]");
|
const savedOpenNoteContexts = optionService.getOptionJson("openNoteContexts") || "[]";
|
||||||
const openedWindowIds = windowService.getAllWindowIds();
|
const openedWindowIds = windowService.getAllWindowIds();
|
||||||
const closedWindows = savedOpenNoteContexts
|
const closedWindows = savedOpenNoteContexts
|
||||||
.filter(win => !openedWindowIds.includes(win.windowId))
|
.filter(win => !openedWindowIds.includes(win.windowId))
|
||||||
|
|||||||
@ -37,9 +37,7 @@ function trackWindowFocus(win: BrowserWindow, windowId: string) {
|
|||||||
|
|
||||||
win.on("closed", () => {
|
win.on("closed", () => {
|
||||||
cls.wrap(() => {
|
cls.wrap(() => {
|
||||||
const savedWindows = JSON.parse(
|
const savedWindows = optionService.getOptionJson("openNoteContexts") || "[]";
|
||||||
optionService.getOption("openNoteContexts") || "[]"
|
|
||||||
);
|
|
||||||
|
|
||||||
const win = savedWindows.find(w => w.windowId === windowId);
|
const win = savedWindows.find(w => w.windowId === windowId);
|
||||||
if (win) {
|
if (win) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user