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;
|
||||
|
||||
@@ -46,9 +46,9 @@ def main(driver: Chrome, logger = logging.getLogger('main')):
|
||||
class Status(Enum):
|
||||
IDLE = 0
|
||||
READY = 1
|
||||
RUNNING = 3
|
||||
STANDBY = 4
|
||||
CLOSING = 5
|
||||
RUNNING = 2
|
||||
STANDBY = 3
|
||||
CLOSING = 4
|
||||
|
||||
class ColumnMapping:
|
||||
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('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 MismatchedEmailAddress(Exception): pass
|
||||
|
||||
@@ -553,7 +564,7 @@ def main(driver: Chrome, logger = logging.getLogger('main')):
|
||||
status = Status.STANDBY
|
||||
continue
|
||||
|
||||
if options.get('save'):
|
||||
if options.get('writable'):
|
||||
try:
|
||||
status = Status.CLOSING
|
||||
flow.allow(Wait, False)
|
||||
@@ -565,9 +576,8 @@ def main(driver: Chrome, logger = logging.getLogger('main')):
|
||||
except Close:
|
||||
pass
|
||||
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; saving at %s', str(file), exc_info=e)
|
||||
wb.save(file)
|
||||
logger.warning('RPC communication failed', exc_info=e)
|
||||
save()
|
||||
|
||||
flow.allow(Timeout, False)
|
||||
flow.allow(Close, False)
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user