update: saving file upon exit
This commit is contained in:
+9
-6
@@ -109,9 +109,6 @@
|
||||
<label for="nospam" class="pure-checkbox">
|
||||
<input id="nospam" type="checkbox"/> Avoid spamming
|
||||
</label>
|
||||
<label for="save" class="pure-checkbox">
|
||||
<input id="save" type="checkbox" checked/> Save to file
|
||||
</label>
|
||||
<label for="logs" class="pure-checkbox">
|
||||
<input id="logs" class="local-only" type="checkbox"/> Show logs
|
||||
</label>
|
||||
@@ -190,7 +187,6 @@
|
||||
|
||||
<script type="module">
|
||||
import { default as $, LogRecord, Rpc2 } from '/';
|
||||
if (performance.getEntriesByType('navigation')[0].type === 'reload') await Rpc2.invoke('exit');
|
||||
|
||||
let limit = 0;
|
||||
let length = 0;
|
||||
@@ -202,6 +198,13 @@ let writable = null;
|
||||
let filereader = null;
|
||||
let subcategories = [];
|
||||
|
||||
window.addEventListener('beforeunload', (e) => {
|
||||
writable?.abort().catch(() => void 0);
|
||||
Rpc2.notify('exit');
|
||||
e.preventDefault();
|
||||
e.returnValue = '';
|
||||
});
|
||||
|
||||
let { locales, mapping, parameters } = await Rpc2.invoke('context');
|
||||
let account = new String(parameters.account);
|
||||
let name = account.split('@', 1).pop();
|
||||
@@ -229,7 +232,7 @@ async function handlePrimaryButtonClick() {
|
||||
reader.readAsArrayBuffer(file);
|
||||
}));
|
||||
|
||||
let [file, buffer] = await filereader().catch(() => []);
|
||||
let [file, buffer] = await filereader().catch(e => alert('(ERROR) ' + new String(e ?? 'Unable to read data')));
|
||||
writable = await handle.createWritable().catch(() => null);
|
||||
limit = await Rpc2.invoke('ready', file.name, new Uint8Array(buffer).toBase64());
|
||||
$.get('#fileLabel').innerText = file.name;
|
||||
@@ -238,7 +241,7 @@ async function handlePrimaryButtonClick() {
|
||||
break;
|
||||
case 'READY':
|
||||
let locale = $('#locale').value;
|
||||
let options = { locale, mapping: new Object()};
|
||||
let options = { locale, mapping: new Object(), writable: new Boolean(writable) };
|
||||
|
||||
for (let element of $.all("input[type='number'].params")) {
|
||||
parameters[element.id] = element.disabled ? null : element.valueAsNumber;
|
||||
|
||||
Reference in New Issue
Block a user