update: saving file upon exit
This commit is contained in:
+9
-6
@@ -109,9 +109,6 @@
|
|||||||
<label for="nospam" class="pure-checkbox">
|
<label for="nospam" class="pure-checkbox">
|
||||||
<input id="nospam" type="checkbox"/> Avoid spamming
|
<input id="nospam" type="checkbox"/> Avoid spamming
|
||||||
</label>
|
</label>
|
||||||
<label for="save" class="pure-checkbox">
|
|
||||||
<input id="save" type="checkbox" checked/> Save to file
|
|
||||||
</label>
|
|
||||||
<label for="logs" class="pure-checkbox">
|
<label for="logs" class="pure-checkbox">
|
||||||
<input id="logs" class="local-only" type="checkbox"/> Show logs
|
<input id="logs" class="local-only" type="checkbox"/> Show logs
|
||||||
</label>
|
</label>
|
||||||
@@ -190,7 +187,6 @@
|
|||||||
|
|
||||||
<script type="module">
|
<script type="module">
|
||||||
import { default as $, LogRecord, Rpc2 } from '/';
|
import { default as $, LogRecord, Rpc2 } from '/';
|
||||||
if (performance.getEntriesByType('navigation')[0].type === 'reload') await Rpc2.invoke('exit');
|
|
||||||
|
|
||||||
let limit = 0;
|
let limit = 0;
|
||||||
let length = 0;
|
let length = 0;
|
||||||
@@ -202,6 +198,13 @@ let writable = null;
|
|||||||
let filereader = null;
|
let filereader = null;
|
||||||
let subcategories = [];
|
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 { locales, mapping, parameters } = await Rpc2.invoke('context');
|
||||||
let account = new String(parameters.account);
|
let account = new String(parameters.account);
|
||||||
let name = account.split('@', 1).pop();
|
let name = account.split('@', 1).pop();
|
||||||
@@ -229,7 +232,7 @@ async function handlePrimaryButtonClick() {
|
|||||||
reader.readAsArrayBuffer(file);
|
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);
|
writable = await handle.createWritable().catch(() => null);
|
||||||
limit = await Rpc2.invoke('ready', file.name, new Uint8Array(buffer).toBase64());
|
limit = await Rpc2.invoke('ready', file.name, new Uint8Array(buffer).toBase64());
|
||||||
$.get('#fileLabel').innerText = file.name;
|
$.get('#fileLabel').innerText = file.name;
|
||||||
@@ -238,7 +241,7 @@ async function handlePrimaryButtonClick() {
|
|||||||
break;
|
break;
|
||||||
case 'READY':
|
case 'READY':
|
||||||
let locale = $('#locale').value;
|
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")) {
|
for (let element of $.all("input[type='number'].params")) {
|
||||||
parameters[element.id] = element.disabled ? null : element.valueAsNumber;
|
parameters[element.id] = element.disabled ? null : element.valueAsNumber;
|
||||||
|
|||||||
@@ -46,9 +46,9 @@ def main(driver: Chrome, logger = logging.getLogger('main')):
|
|||||||
class Status(Enum):
|
class Status(Enum):
|
||||||
IDLE = 0
|
IDLE = 0
|
||||||
READY = 1
|
READY = 1
|
||||||
RUNNING = 3
|
RUNNING = 2
|
||||||
STANDBY = 4
|
STANDBY = 3
|
||||||
CLOSING = 5
|
CLOSING = 4
|
||||||
|
|
||||||
class ColumnMapping:
|
class ColumnMapping:
|
||||||
def __init__(self, email=None, recipient=None, code=None, region=None, sent=None, variables=None):
|
def __init__(self, email=None, recipient=None, code=None, region=None, sent=None, variables=None):
|
||||||
@@ -337,6 +337,17 @@ def main(driver: Chrome, logger = logging.getLogger('main')):
|
|||||||
sp.set('merge', merge)
|
sp.set('merge', merge)
|
||||||
sp.set('progress', lambda: progress)
|
sp.set('progress', lambda: progress)
|
||||||
|
|
||||||
|
def save():
|
||||||
|
try:
|
||||||
|
file = Path('.').joinpath(filename or f'Mailer-{datetime.now().strftime('%Y%m%d-%H%M%S-%f')}.xlsx').resolve()
|
||||||
|
logger.info('Saving file at %s', str(file))
|
||||||
|
wb.save(file)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error('Error while writing data to file', exc_info=e)
|
||||||
|
|
||||||
|
exit = sp.pop('exit')
|
||||||
|
sp.set('exit', lambda: (save() if options.get('writable') and status.value >= 2 else None, exit()))
|
||||||
|
|
||||||
class MismatchedEmailSubject(Exception): pass
|
class MismatchedEmailSubject(Exception): pass
|
||||||
class MismatchedEmailAddress(Exception): pass
|
class MismatchedEmailAddress(Exception): pass
|
||||||
|
|
||||||
@@ -553,7 +564,7 @@ def main(driver: Chrome, logger = logging.getLogger('main')):
|
|||||||
status = Status.STANDBY
|
status = Status.STANDBY
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if options.get('save'):
|
if options.get('writable'):
|
||||||
try:
|
try:
|
||||||
status = Status.CLOSING
|
status = Status.CLOSING
|
||||||
flow.allow(Wait, False)
|
flow.allow(Wait, False)
|
||||||
@@ -565,9 +576,8 @@ def main(driver: Chrome, logger = logging.getLogger('main')):
|
|||||||
except Close:
|
except Close:
|
||||||
pass
|
pass
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
file = Path('.').joinpath(filename or f'Mailer-{datetime.now().strftime('%Y%m%d-%H%M%S-%f')}.xlsx').resolve()
|
logger.warning('RPC communication failed', exc_info=e)
|
||||||
logger.warning('RPC communication failed; saving at %s', str(file), exc_info=e)
|
save()
|
||||||
wb.save(file)
|
|
||||||
|
|
||||||
flow.allow(Timeout, False)
|
flow.allow(Timeout, False)
|
||||||
flow.allow(Close, False)
|
flow.allow(Close, False)
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user