()
| 8940 | for (let i = 0; i < bytes.length; i += chunkSize) { |
| 8941 | binary += String.fromCharCode.apply(null, bytes.subarray(i, i + chunkSize)); |
| 8942 | } |
| 8943 | resolve(btoa(binary)); |
| 8944 | }; |
| 8945 | reader.readAsArrayBuffer(file); |
| 8946 | }); |
| 8947 | } |
| 8948 | |
| 8949 | async function readFileAsText(file) { |
| 8950 | return new Promise((resolve, reject) => { |
| 8951 | const reader = new FileReader(); |
| 8952 | reader.onerror = () => reject(reader.error); |
| 8953 | reader.onload = () => resolve(reader.result || ''); |
| 8954 | reader.readAsText(file); |
| 8955 | }); |
| 8956 | } |
| 8957 | |
| 8958 | function promptForBackupFile() { |
| 8959 | return new Promise((resolve) => { |
| 8960 | const input = document.createElement('input'); |
| 8961 | input.type = 'file'; |
| 8962 | input.accept = '.db'; |
| 8963 | input.style.display = 'none'; |
| 8964 | input.addEventListener('change', () => { |
| 8965 | const file = input.files && input.files[0] ? input.files[0] : null; |
| 8966 | input.remove(); |
| 8967 | resolve(file); |
| 8968 | }); |
| 8969 | document.body.appendChild(input); |
| 8970 | input.click(); |
| 8971 | }); |
| 8972 | } |
| 8973 | |
| 8974 | function promptForLibraryImportFile() { |
| 8975 | return new Promise((resolve) => { |
| 8976 | const input = document.createElement('input'); |
| 8977 | input.type = 'file'; |
| 8978 | input.accept = '.json,application/json'; |
| 8979 | input.style.display = 'none'; |
| 8980 | input.addEventListener('change', () => { |
| 8981 | const file = input.files && input.files[0] ? input.files[0] : null; |
| 8982 | input.remove(); |
| 8983 | resolve(file); |
| 8984 | }); |
| 8985 | document.body.appendChild(input); |
| 8986 | input.click(); |
| 8987 | }); |
| 8988 | } |
| 8989 | |
| 8990 | window._restoreBackupFromDialogImpl = async function() { |
| 8991 | try { |
| 8992 | const confirmResult = await window.electron.showMessage( |
| 8993 | 'Confirm Restore', |
| 8994 | 'Warning: Restoring from backup will replace all current data. This cannot be undone. Continue?', |
| 8995 | ['Yes', 'No'] |
| 8996 | ); |
no test coverage detected