Skip to content

Commit 68c2578

Browse files
Fix import/export filter (close #2016)
1 parent 5fb2b28 commit 68c2578

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

application/holder/src/service/electron/dialogs.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ export class Dialogs extends Implementation {
6767
} {
6868
const opener = async (target: number, ext?: string): Promise<string[]> => {
6969
let results;
70+
this.fixFocusAndMouse();
7071
switch (target) {
7172
case 0:
72-
this.fixFocusAndMouse();
7373
results = await dialog.showOpenDialog(this._window, {
7474
title: 'Opening a file',
7575
properties: ['openFile', 'multiSelections'],
@@ -85,23 +85,20 @@ export class Dialogs extends Implementation {
8585
});
8686
break;
8787
case 1:
88-
this.fixFocusAndMouse();
8988
results = await dialog.showOpenDialog(this._window, {
9089
title: 'Opening a DLT file',
9190
properties: ['openFile', 'multiSelections'],
9291
filters: [{ name: 'DLT files', extensions: ['dlt'] }],
9392
});
9493
break;
9594
case 2:
96-
this.fixFocusAndMouse();
9795
results = await dialog.showOpenDialog(this._window, {
9896
title: 'Opening a PCAPNG file',
9997
properties: ['openFile', 'multiSelections'],
10098
filters: [{ name: 'PCAPNG Files', extensions: ['pcapng'] }],
10199
});
102100
break;
103101
case 3:
104-
this.fixFocusAndMouse();
105102
results = await dialog.showOpenDialog(this._window, {
106103
title: 'Opening a PCAP file',
107104
properties: ['openFile', 'multiSelections'],

application/holder/src/service/storage.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ export class Service extends Implementation {
181181
}
182182
} else if (request.file !== undefined) {
183183
const file = new FileController(request.file).init();
184-
const error = file.write(JSON.stringify(request.entries));
184+
const error = file.write(JSON.stringify(entries));
185185
if (error instanceof Error) {
186186
return Promise.reject(error);
187187
}

application/holder/src/service/storage/entries.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@ export type Reader = (key: string) => Promise<string>;
1010
export class Entries {
1111
static from(str: string, storageKey: string, logger: Logger): Map<string, Entry> {
1212
const entries = new Map<string, Entry>();
13-
const parsed = JSON.parse(str) as Entry[];
13+
const parsed = ((): Entry[] => {
14+
try {
15+
const inner = JSON.parse(str);
16+
return typeof inner === 'string' ? JSON.parse(inner) : inner;
17+
} catch (e) {
18+
throw new Error(`Fail to parse Entry[] from string: ${error(e)}`);
19+
}
20+
})();
1421
if (!(parsed instanceof Array)) {
1522
throw new Error(
1623
`Invalid format: expecting an Entry[], but has been gotten: ${typeof parsed}`,

0 commit comments

Comments
 (0)