(directoryPath, background = false, isStlHomeScan = false)
| 11812 | fileSelected = true; |
| 11813 | |
| 11814 | const file = e.target.files[0]; |
| 11815 | |
| 11816 | // Clean up immediately, even if no file was selected |
| 11817 | if (activeImageInput === fileInput) { |
| 11818 | activeImageInput = null; |
| 11819 | } |
| 11820 | if (fileInput.parentNode) { |
| 11821 | fileInput.parentNode.removeChild(fileInput); |
| 11822 | } |
| 11823 | |
| 11824 | if (!file) { |
| 11825 | return; // User cancelled |
| 11826 | } |
| 11827 | |
| 11828 | try { |
| 11829 | // Read file as data URL |
| 11830 | const reader = new FileReader(); |
| 11831 | reader.onload = async (event) => { |
| 11832 | try { |
| 11833 | const dataUrl = event.target.result; |
| 11834 | // Add thumbnail to each selected model (multi-edit: same image to all) |
| 11835 | for (const filePath of paths) { |
| 11836 | await window.electron.addThumbnail(filePath, dataUrl); |
| 11837 | } |
| 11838 | // Server-side handler sends thumbnail-added per model to refresh the UI |
| 11839 | } catch (error) { |
| 11840 | console.error('Error adding image:', error); |
| 11841 | alert('Error adding image: ' + error.message); |
| 11842 | } |
| 11843 | }; |
| 11844 | reader.onerror = (error) => { |
| 11845 | console.error('Error reading file:', error); |
| 11846 | alert('Error reading image file'); |
| 11847 | }; |
| 11848 | reader.readAsDataURL(file); |
| 11849 | } catch (error) { |
| 11850 | console.error('Error processing image file:', error); |
| 11851 | alert('Error processing image: ' + error.message); |
| 11852 | } |
| 11853 | }); |
| 11854 | |
| 11855 | // Clean up if user cancels (no file selected after a delay) |
| 11856 | setTimeout(() => { |
| 11857 | if (!fileSelected && activeImageInput === fileInput) { |
| 11858 | activeImageInput = null; |
| 11859 | if (fileInput.parentNode) { |
| 11860 | fileInput.parentNode.removeChild(fileInput); |
| 11861 | } |
| 11862 | } |
| 11863 | }, 1000); |
| 11864 | |
| 11865 | // Trigger file input dialog |
| 11866 | document.body.appendChild(fileInput); |
| 11867 | fileInput.click(); |
| 11868 | } catch (error) { |
| 11869 | console.error('Error setting up image file input:', error); |
| 11870 | alert('Error: Could not open file dialog'); |
| 11871 | activeImageInput = null; |
no test coverage detected