mirror of
https://github.com/zadam/trilium.git
synced 2025-12-31 03:34:23 +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";
|
||||
}
|
||||
|
||||
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]) {
|
||||
const option = becca.getOption(name);
|
||||
|
||||
@ -137,6 +150,7 @@ export default {
|
||||
getOption,
|
||||
getOptionInt,
|
||||
getOptionBool,
|
||||
getOptionJson,
|
||||
setOption,
|
||||
createOption,
|
||||
getOptions,
|
||||
|
||||
@ -197,7 +197,7 @@ function updateTrayMenu() {
|
||||
}
|
||||
|
||||
function buildClosedWindowsMenu() {
|
||||
const savedOpenNoteContexts = JSON.parse(optionService.getOption("openNoteContexts") || "[]");
|
||||
const savedOpenNoteContexts = optionService.getOptionJson("openNoteContexts") || "[]";
|
||||
const openedWindowIds = windowService.getAllWindowIds();
|
||||
const closedWindows = savedOpenNoteContexts
|
||||
.filter(win => !openedWindowIds.includes(win.windowId))
|
||||
|
||||
@ -37,9 +37,7 @@ function trackWindowFocus(win: BrowserWindow, windowId: string) {
|
||||
|
||||
win.on("closed", () => {
|
||||
cls.wrap(() => {
|
||||
const savedWindows = JSON.parse(
|
||||
optionService.getOption("openNoteContexts") || "[]"
|
||||
);
|
||||
const savedWindows = optionService.getOptionJson("openNoteContexts") || "[]";
|
||||
|
||||
const win = savedWindows.find(w => w.windowId === windowId);
|
||||
if (win) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user