Skip to content
Snippets Groups Projects
Unverified Commit c2ebfc72 authored by Jarek Samic's avatar Jarek Samic Committed by GitHub
Browse files

Fix importing transactions in Safari (#1349)

parent 92ddaa56
No related branches found
No related tags found
No related merge requests found
......@@ -52,8 +52,19 @@ global.Actual = {
openFileDialog: async ({ filters = [], properties }) => {
return new Promise(resolve => {
let input = document.createElement('input');
let createdElement = false;
// Attempt to reuse an already-created file input.
let input = document.body.querySelector(
'input[id="open-file-dialog-input"]',
);
if (!input) {
createdElement = true;
input = document.createElement('input');
}
input.type = 'file';
input.id = 'open-file-dialog-input';
input.value = null;
let filter = filters.find(filter => filter.extensions);
if (filter) {
......@@ -63,15 +74,9 @@ global.Actual = {
input.style.position = 'absolute';
input.style.top = '0px';
input.style.left = '0px';
input.dispatchEvent(
new MouseEvent('click', {
view: window,
bubbles: true,
cancelable: true,
}),
);
input.style.display = 'none';
input.addEventListener('change', e => {
input.onchange = e => {
let file = e.target.files[0];
let filename = file.name.replace(/.*(\.[^.]*)/, 'file$1');
......@@ -89,7 +94,15 @@ global.Actual = {
alert('Error reading file');
};
}
});
};
// In Safari the file input has to be in the DOM for change events to
// reliably fire.
if (createdElement) {
document.body.appendChild(input);
}
input.click();
});
},
......
......@@ -671,8 +671,8 @@ function ImportTransactions({
setFieldMappings({ ...fieldMappings, ...newFieldMappings });
}
function onNewFile() {
const res = window.Actual.openFileDialog({
async function onNewFile() {
const res = await window.Actual.openFileDialog({
filters: [
{ name: 'Financial Files', extensions: ['qif', 'ofx', 'qfx', 'csv'] },
],
......
---
category: Bugfix
authors: [Cldfire]
---
Fix bug causing transaction import in Safari to be unreliable
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment