Skip to content

Commit 955b985

Browse files
committed
Handle cancel
1 parent d229fd5 commit 955b985

File tree

2 files changed

+39
-27
lines changed

2 files changed

+39
-27
lines changed

src/pg/inputPixelEditor/__examples__/basic/basic.ts

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -90,33 +90,41 @@ export default class XPgInputPixelEditorBasic extends HTMLElement {
9090
});
9191
this.$file.addEventListener('change', this.handleFile.bind(this));
9292
this.$saveSvg.addEventListener('click', async () => {
93-
// @ts-ignore
94-
const handle = await window.showSaveFilePicker({
95-
suggestedName: 'Canvas',
96-
types: [{
97-
description: 'SVG Document',
98-
accept: {'image/svg+xml': ['.svg']},
99-
}],
100-
});
101-
const writable = await handle.createWritable();
102-
await writable.write(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${this.$width.value} ${this.$height.value}">`);
103-
await writable.write(`<path d="${'test'}" />`);
104-
await writable.write('</svg>');
105-
await writable.close();
93+
try {
94+
// @ts-ignore
95+
const handle = await window.showSaveFilePicker({
96+
suggestedName: 'Canvas',
97+
types: [{
98+
description: 'SVG Document',
99+
accept: {'image/svg+xml': ['.svg']},
100+
}],
101+
});
102+
const writable = await handle.createWritable();
103+
await writable.write(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${this.$width.value} ${this.$height.value}">`);
104+
await writable.write(`<path d="${'test'}" />`);
105+
await writable.write('</svg>');
106+
await writable.close();
107+
} catch (e: any) {
108+
// no save
109+
}
106110
});
107111
this.$savePng.addEventListener('click', async () => {
108-
// @ts-ignore
109-
const handle = await window.showSaveFilePicker({
110-
suggestedName: 'CanvasName',
111-
types: [{
112-
description: 'SVG Document',
113-
accept: {'image/svg+xml': ['.svg']},
114-
}],
115-
});
116-
const writable = await handle.createWritable();
117-
await writable.write('something');
118-
await writable.write
119-
await writable.close();
112+
try {
113+
// @ts-ignore
114+
const handle = await window.showSaveFilePicker({
115+
suggestedName: 'CanvasName',
116+
types: [{
117+
description: 'SVG Document',
118+
accept: {'image/svg+xml': ['.svg']},
119+
}],
120+
});
121+
const writable = await handle.createWritable();
122+
await writable.write('something');
123+
await writable.write
124+
await writable.close();
125+
} catch (e: any) {
126+
// no save
127+
}
120128
});
121129
}
122130

src/pg/inputPixelEditor/__examples__/basic/saveUtil.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@ export async function saveFile(blob) {
1616
},
1717
],
1818
};
19-
// @ts-ignore
20-
return await window.showSaveFilePicker(opts);
19+
try {
20+
// @ts-ignore
21+
return await window.showSaveFilePicker(opts);
22+
} catch (e) {
23+
console.log('no save');
24+
}
2125
}
2226
const downloadelem = document.createElement("a");
2327
const url = URL.createObjectURL(blob);

0 commit comments

Comments
 (0)